/** * Evaluates the Jelly script submitted by the client. * * This is useful for system administration as well as unit testing. */ @RequirePOST public void doEval(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException { checkPermission(RUN_SCRIPTS); try { MetaClass mc = WebApp.getCurrent().getMetaClass(getClass()); Script script = mc.classLoader.loadTearOff(JellyClassLoaderTearOff.class).createContext().compileScript(new InputSource(req.getReader())); new JellyRequestDispatcher(this,script).forward(req,rsp); } catch (JellyException e) { throw new ServletException(e); } }
/** * Accepts {@code config.xml} submission, as well as serve it. */ @WebMethod(name = "config.xml") public void doConfigDotXml(StaplerRequest req, StaplerResponse rsp) throws IOException { if (req.getMethod().equals("GET")) { // read rsp.setContentType("application/xml"); writeConfigDotXml(rsp.getOutputStream()); return; } if (req.getMethod().equals("POST")) { // submission updateByXml((Source)new StreamSource(req.getReader())); return; } // huh? rsp.sendError(SC_BAD_REQUEST); }
/** * Accepts {@code config.xml} submission, as well as serve it. */ @WebMethod(name = "config.xml") public HttpResponse doConfigDotXml(StaplerRequest req) throws IOException { if (req.getMethod().equals("GET")) { // read checkPermission(READ); return new HttpResponse() { public void generateResponse(StaplerRequest req, StaplerResponse rsp, Object node) throws IOException, ServletException { rsp.setContentType("application/xml"); View.this.writeXml(rsp.getOutputStream()); } }; } if (req.getMethod().equals("POST")) { // submission updateByXml(new StreamSource(req.getReader())); return HttpResponses.ok(); } // huh? return HttpResponses.error(SC_BAD_REQUEST, "Unexpected request method " + req.getMethod()); }
protected String getRequestPayload(final StaplerRequest req) throws IOException { return CharStreams.toString(req.getReader()); }
private String extractRequestBody(StaplerRequest req) { String body = null; BufferedReader br = null; try { br = req.getReader(); body = IOUtils.toString(br); } catch (IOException e) { body = null; } finally { IOUtils.closeQuietly(br); } return body; }
@Override public Object parse(StaplerRequest request, Annotation a, Class type, String parameterName) throws ServletException { String ct = request.getContentType(); if ((ct == null) || !ct.startsWith("application/json")) throw new ServletException("Expected application/json but got "+ct); try { // TODO: exception thrown here results in error page rendered in HTML. JSONObject o = JSONObject.fromObject(IOUtils.toString(request.getReader())); return JSONObject.toBean(o,type); } catch (IOException e) { throw new ServletException("Failed to read JSON",e); } } }
@Override public Object parse(StaplerRequest request, Annotation a, Class type, String parameterName) throws ServletException { String ct = request.getContentType(); if ((ct == null) || !ct.startsWith("application/json")) throw new ServletException("Expected application/json but got "+ct); try { // TODO: exception thrown here results in error page rendered in HTML. JSONObject o = JSONObject.fromObject(IOUtils.toString(request.getReader())); return JSONObject.toBean(o,type); } catch (IOException e) { throw new ServletException("Failed to read JSON",e); } } }
/** * Used to post the build result from a remote machine. */ public void doPostBuildResult( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException { checkPermission(AbstractProject.BUILD); ExternalRun run = newBuild(); run.acceptRemoteSubmission(req.getReader()); rsp.setStatus(HttpServletResponse.SC_OK); }
/** * Used to post the build result from a remote machine. */ public void doPostBuildResult(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException { checkPermission(AbstractProject.BUILD); ExternalRun run = newBuild(); run.acceptRemoteSubmission(req.getReader()); rsp.setStatus(HttpServletResponse.SC_OK); }
/** * Used to post the build result from a remote machine. */ public void doPostBuildResult( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException { checkPermission(AbstractProject.BUILD); ExternalRun run = newBuild(); run.acceptRemoteSubmission(req.getReader()); rsp.setStatus(HttpServletResponse.SC_OK); }
/** * Used to post the build result from a remote machine. */ public void doPostBuildResult( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException { checkPermission(AbstractProject.BUILD); ExternalRun run = newBuild(); run.acceptRemoteSubmission(req.getReader()); rsp.setStatus(HttpServletResponse.SC_OK); }
/** * Evaluates the Jelly script submitted by the client. * * This is useful for system administration as well as unit testing. */ @RequirePOST public void doEval(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException { checkPermission(RUN_SCRIPTS); try { MetaClass mc = WebApp.getCurrent().getMetaClass(getClass()); Script script = mc.classLoader.loadTearOff(JellyClassLoaderTearOff.class).createContext().compileScript(new InputSource(req.getReader())); new JellyRequestDispatcher(this,script).forward(req,rsp); } catch (JellyException e) { throw new ServletException(e); } }
/** * Accepts <tt>config.xml</tt> submission, as well as serve it. */ @WebMethod(name = "config.xml") public void doConfigDotXml(StaplerRequest req, StaplerResponse rsp) throws IOException { if (req.getMethod().equals("GET")) { // read rsp.setContentType("application/xml"); writeConfigDotXml(rsp.getOutputStream()); return; } if (req.getMethod().equals("POST")) { // submission updateByXml((Source)new StreamSource(req.getReader())); return; } // huh? rsp.sendError(SC_BAD_REQUEST); }
/** * Evaluates the Jelly script submitted by the client. * * This is useful for system administration as well as unit testing. */ public void doEval(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException { checkPermission(ADMINISTER); requirePOST(); try { MetaClass mc = WebApp.getCurrent().getMetaClass(getClass()); Script script = mc.classLoader.loadTearOff(JellyClassLoaderTearOff.class).createContext().compileScript(new InputSource(req.getReader())); new JellyRequestDispatcher(this, script).forward(req, rsp); } catch (JellyException e) { throw new ServletException(e); } }
/** * Evaluates the Jelly script submitted by the client. * * This is useful for system administration as well as unit testing. */ public void doEval(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException { checkPermission(ADMINISTER); requirePOST(); try { MetaClass mc = WebApp.getCurrent().getMetaClass(getClass()); Script script = mc.classLoader.loadTearOff(JellyClassLoaderTearOff.class).createContext().compileScript(new InputSource(req.getReader())); new JellyRequestDispatcher(this, script).forward(req, rsp); } catch (JellyException e) { throw new ServletException(e); } }
/** * Evaluates the Jelly script submitted by the client. * * This is useful for system administration as well as unit testing. */ public void doEval(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException { checkPermission(ADMINISTER); requirePOST(); try { MetaClass mc = WebApp.getCurrent().getMetaClass(getClass()); Script script = mc.classLoader.loadTearOff(JellyClassLoaderTearOff.class).createContext().compileScript(new InputSource(req.getReader())); new JellyRequestDispatcher(this, script).forward(req, rsp); } catch (JellyException e) { throw new ServletException(e); } }
/** * Evaluates the Jelly script submitted by the client. * * This is useful for system administration as well as unit testing. */ public void doEval(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException { checkPermission(ADMINISTER); requirePOST(); try { MetaClass mc = WebApp.getCurrent().getMetaClass(getClass()); Script script = mc.classLoader.loadTearOff(JellyClassLoaderTearOff.class).createContext().compileScript(new InputSource(req.getReader())); new JellyRequestDispatcher(this, script).forward(req, rsp); } catch (JellyException e) { throw new ServletException(e); } }
/** * Accepts <tt>config.xml</tt> submission, as well as serve it. */ @WebMethod(name = "config.xml") public HttpResponse doConfigDotXml(StaplerRequest req) throws IOException { if (req.getMethod().equals("GET")) { // read checkPermission(READ); return new HttpResponse() { public void generateResponse(StaplerRequest req, StaplerResponse rsp, Object node) throws IOException, ServletException { rsp.setContentType("application/xml"); View.this.writeXml(rsp.getOutputStream()); } }; } if (req.getMethod().equals("POST")) { // submission updateByXml(new StreamSource(req.getReader())); return HttpResponses.ok(); } // huh? return HttpResponses.error(SC_BAD_REQUEST, "Unexpected request method " + req.getMethod()); }
/** * Retrieves the Gerrit command. * * @param request the request * @param response the response * @throws IOException if so. */ public void doDynamic(StaplerRequest request, StaplerResponse response) throws IOException { try { this.lastContent = IOUtils.toString(request.getReader()); } finally { response.setContentType("application/json"); PrintWriter writer = response.getWriter(); writer.write(new JSONObject(true).toString()); writer.flush(); } } }
/** * Retrieves the Gerrit command. * * @param request the request * @param response the response * @throws IOException if so. */ public void doDynamic(StaplerRequest request, StaplerResponse response) throws IOException { lastPath = request.getRestOfPath(); lastContent = IOUtils.toString(request.getReader()); response.setContentType("application/json"); PrintWriter writer = response.getWriter(); writer.write(new JSONObject(true).toString()); writer.flush(); } }