/** * Accepts {@code config.xml} submission, as well as serve it. */ @WebMethod(name = "config.xml") public void doConfigDotXml(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException { if (req.getMethod().equals("GET")) { // read checkPermission(EXTENDED_READ); rsp.setContentType("application/xml"); Node node = getNode(); if (node == null) { throw HttpResponses.notFound(); } Jenkins.XSTREAM2.toXMLUTF8(node, rsp.getOutputStream()); return; } if (req.getMethod().equals("POST")) { // submission updateByXml(req.getInputStream()); return; } // huh? rsp.sendError(SC_BAD_REQUEST); }
private String extractListenerId(StaplerRequest req) { String path = req.getRestOfPath(); String id = getListenerId(path.substring(1)); if (id == null) { throw HttpResponses.notFound(); } return id; }
/** * This method serves static resources in the plugin under <tt>hudson/plugin/SHORTNAME</tt>. */ public void doDynamic(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException { String path = req.getRestOfPath(); if (path.startsWith("/META-INF/") || path.startsWith("/WEB-INF/")) { throw HttpResponses.notFound(); } if(path.length()==0) path = "/"; // Stapler routes requests like the "/static/.../foo/bar/zot" to be treated like "/foo/bar/zot" // and this is used to serve long expiration header, by using Jenkins.VERSION_HASH as "..." // to create unique URLs. Recognize that and set a long expiration header. String requestPath = req.getRequestURI().substring(req.getContextPath().length()); boolean staticLink = requestPath.startsWith("/static/"); long expires = staticLink ? TimeUnit.DAYS.toMillis(365) : -1; // use serveLocalizedFile to support automatic locale selection try { rsp.serveLocalizedFile(req, wrapper.baseResourceURL.toURI().resolve(new URI(null, '.' + path, null)).toURL(), expires); } catch (URISyntaxException x) { throw new IOException(x); } }
public void doShow(StaplerRequest req, StaplerResponse rsp, @QueryParameter("id") String fileId, @AncestorInPath ItemGroup group) throws IOException, ServletException { Config config = ConfigFiles.getByIdOrNull(group, fileId); if (config != null) { req.setAttribute("contentType", config.getProvider().getContentType()); req.setAttribute("config", config); req.getView(this, JELLY_RESOURCES_PATH + "show.jelly").forward(req, rsp); } throw HttpResponses.notFound(); }
public Job<?, ?> getProject( String job, StaplerRequest req, StaplerResponse rsp ) throws HttpResponses.HttpResponseException { Job<?, ?> p; SecurityContext orig = ACL.impersonate( ACL.SYSTEM ); try { p = Jenkins.getInstance().getItemByFullName( job, Job.class ); } finally { SecurityContextHolder.setContext( orig ); } if ( p == null ) { throw org.kohsuke.stapler.HttpResponses.notFound(); } return p; }
/** * Accepts <tt>config.xml</tt> submission, as well as serve it. */ @WebMethod(name = "config.xml") public void doConfigDotXml(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException { if (req.getMethod().equals("GET")) { // read checkPermission(EXTENDED_READ); rsp.setContentType("application/xml"); Node node = getNode(); if (node == null) { throw HttpResponses.notFound(); } Jenkins.XSTREAM2.toXMLUTF8(node, rsp.getOutputStream()); return; } if (req.getMethod().equals("POST")) { // submission updateByXml(req.getInputStream()); return; } // huh? rsp.sendError(SC_BAD_REQUEST); }