protected List<String> getPossibleViewNames(String baseName) { List<String> names = new ArrayList<String>(); for (Facet f : WebApp.get(Jenkins.getInstance().servletContext).facets) { if (f instanceof JellyCompatibleFacet) { JellyCompatibleFacet jcf = (JellyCompatibleFacet) f; for (String ext : jcf.getScriptExtensions()) names.add(baseName +ext); } } return names; }
@Override protected int run() throws Exception { Jenkins j = Jenkins.get(); // Or perhaps simpler to inline the thread body of doReload? j.doReload(); Object app; while ((app = WebApp.get(j.servletContext).getApp()) instanceof HudsonIsLoading) { Thread.sleep(100); } if (app instanceof Jenkins) { return 0; } else if (app instanceof JenkinsReloadFailed) { Throwable t = ((JenkinsReloadFailed) app).cause; if (t instanceof Exception) { throw (Exception) t; } else { throw new RuntimeException(t); } } else { stderr.println("Unexpected status " + app); return 1; // could throw JenkinsReloadFailed.cause if it were not deprecated } }
public void handle(ServletRequest request, ServletResponse response, AccessDeniedException cause) throws IOException, ServletException { HttpServletRequest req = (HttpServletRequest) request; HttpServletResponse rsp = (HttpServletResponse) response; rsp.setStatus(HttpServletResponse.SC_FORBIDDEN); req.setAttribute("exception",cause); if (cause instanceof AccessDeniedException2) { ((AccessDeniedException2)cause).reportAsHeaders(rsp); } WebApp.get(Jenkins.getInstance().servletContext).getSomeStapler() .invoke(req,rsp, Jenkins.getInstance(), "/accessDenied"); } }
/** * @deprecated * Use {@link WebApp#getClassLoader()} */ public static ClassLoader getClassLoader( ServletContext context ) { return WebApp.get(context).getClassLoader(); }
private void resetMetaClassCache() { // to allow the change to be effective, i.e. rebuild the MetaClass using the new whitelist WebApp.get(Jenkins.get().servletContext).clearMetaClassCache(); }
/** * @deprecated * Use {@link WebApp#getClassLoader()} */ public static ClassLoader getClassLoader( ServletContext context ) { return WebApp.get(context).getClassLoader(); }
@Initializer public static void init(final Jenkins j) throws IOException { CompressionFilter.setUncaughtExceptionHandler(j.servletContext, (e, context, req, rsp) -> { if (rsp.isCommitted()) { LOGGER.log(isEOFException(e) ? Level.FINE : Level.WARNING, null, e); return; } req.setAttribute("javax.servlet.error.exception",e); try { WebApp.get(j.servletContext).getSomeStapler().invoke(req, rsp, j, "/oops"); } catch (ServletException | IOException x) { if (!Stapler.isSocketException(x)) { throw x; } } }); try { Thread.setDefaultUncaughtExceptionHandler(new DefaultUncaughtExceptionHandler()); LOGGER.log(Level.FINE, "Successfully installed a global UncaughtExceptionHandler."); } catch (SecurityException ex) { LOGGER.log(Level.SEVERE, "Failed to set the default UncaughtExceptionHandler. " + "If any threads die due to unhandled coding errors then there will be no logging of this information. " + "The lack of this diagnostic information will make it harder to track down issues which will reduce the supportability of Jenkins. " + "It is highly recommended that you consult the documentation that comes with you servlet container on how to allow the " + "`setDefaultUncaughtExceptionHandler` permission and enable it.", ex); } }
/** * Sets up Stapler to use our crumb issuer. */ @Initializer public static void initStaplerCrumbIssuer() { WebApp.get(Jenkins.getInstance().servletContext).setCrumbIssuer(new org.kohsuke.stapler.CrumbIssuer() { @Override public String issueCrumb(StaplerRequest request) { CrumbIssuer ci = Jenkins.getInstance().getCrumbIssuer(); return ci!=null ? ci.getCrumb(request) : DEFAULT.issueCrumb(request); } @Override public void validateCrumb(StaplerRequest request, String submittedCrumb) { CrumbIssuer ci = Jenkins.getInstance().getCrumbIssuer(); if (ci==null) { DEFAULT.validateCrumb(request,submittedCrumb); } else { if (!ci.validateCrumb(request, ci.getDescriptor().getCrumbSalt(), submittedCrumb)) throw new SecurityException("Crumb didn't match"); } } }); }
/** * @deprecated * Use {@link WebApp#getClassLoader()} */ public static ClassLoader getClassLoader( ServletContext context ) { return WebApp.get(context).getClassLoader(); }
public void handle(ServletRequest request, ServletResponse response, AccessDeniedException cause) throws IOException, ServletException { HttpServletRequest req = (HttpServletRequest) request; HttpServletResponse rsp = (HttpServletResponse) response; rsp.setStatus(HttpServletResponse.SC_FORBIDDEN); req.setAttribute("exception",cause); if (cause instanceof AccessDeniedException2) { ((AccessDeniedException2)cause).reportAsHeaders(rsp); } WebApp.get(Jenkins.getInstance().servletContext).getSomeStapler() .invoke(req,rsp, Jenkins.getInstance(), "/accessDenied"); } }
/** * Exposes this failure to UI and invoke the hook. * * @param home * JENKINS_HOME if it's already known. */ public void publish(ServletContext context, @CheckForNull File home) { LOGGER.log(Level.SEVERE, "Failed to initialize Jenkins",this); WebApp.get(context).setApp(this); if (home == null) { return; } new GroovyHookScript("boot-failure", context, home, BootFailure.class.getClassLoader()) .bind("exception",this) .bind("home",home) .bind("servletContext", context) .bind("attempts",loadAttempts(home)) .run(); }
/** * Reloads the configuration synchronously. * Beware that this calls neither {@link ItemListener#onLoaded} nor {@link Initializer}s. */ public void reload() throws IOException, InterruptedException, ReactorException { queue.save(); executeReactor(null, loadTasks()); // Ensure we reached the final initialization state. Log the error otherwise if (initLevel != InitMilestone.COMPLETED) { LOGGER.log(SEVERE, "Jenkins initialization has not reached the COMPLETED initialization milestone after the configuration reload. " + "Current state: {0}. " + "It may cause undefined incorrect behavior in Jenkins plugin relying on this state. " + "It is likely an issue with the Initialization task graph. " + "Example: usage of @Initializer(after = InitMilestone.COMPLETED) in a plugin (JENKINS-37759). " + "Please create a bug in Jenkins bugtracker.", initLevel); } User.reload(); queue.load(); WebApp.get(servletContext).setApp(this); }
/** * Reloads the configuration. */ @RequirePOST public synchronized HttpResponse doReload() throws IOException { checkPermission(ADMINISTER); LOGGER.log(Level.WARNING, "Reloading Jenkins as requested by {0}", getAuthentication().getName()); // engage "loading ..." UI and then run the actual task in a separate thread WebApp.get(servletContext).setApp(new HudsonIsLoading()); new Thread("Jenkins config reload thread") { @Override public void run() { try { ACL.impersonate(ACL.SYSTEM); reload(); } catch (Exception e) { LOGGER.log(SEVERE,"Failed to reload Jenkins config",e); new JenkinsReloadFailed(e).publish(servletContext,root); } } }.start(); return HttpResponses.redirectViaContextPath("/"); }
pluginManager = PluginManager.createDefault(this); this.pluginManager = pluginManager; WebApp webApp = WebApp.get(servletContext);
/** * Sets the classloader used by {@link StaplerRequest#bindJSON(Class, JSONObject)} and its sibling methods. * * @deprecated * Use {@link WebApp#setClassLoader(ClassLoader)} */ public static void setClassLoader( ServletContext context, ClassLoader classLoader ) { WebApp.get(context).setClassLoader(classLoader); }
/** * Sets the classloader used by {@link StaplerRequest#bindJSON(Class, JSONObject)} and its sibling methods. * * @deprecated * Use {@link WebApp#setClassLoader(ClassLoader)} */ public static void setClassLoader( ServletContext context, ClassLoader classLoader ) { WebApp.get(context).setClassLoader(classLoader); }
public @Override void init(ServletConfig servletConfig) throws ServletException { super.init(servletConfig); this.context = servletConfig.getServletContext(); this.webApp = WebApp.get(context); String defaultEncodings = servletConfig.getInitParameter("default-encodings"); if(defaultEncodings!=null) { for(String t : defaultEncodings.split(";")) { t=t.trim(); int idx=t.indexOf('='); if(idx<0) throw new ServletException("Invalid format: "+t); webApp.defaultEncodingForStaticResources.put(t.substring(0,idx),t.substring(idx+1)); } } }
/** * Sets the classloader used by {@link StaplerRequest#bindJSON(Class, JSONObject)} and its sibling methods. * * @deprecated * Use {@link WebApp#setClassLoader(ClassLoader)} */ public static void setClassLoader( ServletContext context, ClassLoader classLoader ) { WebApp.get(context).setClassLoader(classLoader); }
protected List<String> getPossibleViewNames(String baseName) { List<String> names = new ArrayList<String>(); for (Facet f : WebApp.get(Jenkins.getInstance().servletContext).facets) { if (f instanceof JellyCompatibleFacet) { JellyCompatibleFacet jcf = (JellyCompatibleFacet) f; for (String ext : jcf.getScriptExtensions()) names.add(baseName +ext); } } return names; }
/** * @param app * The app object that handles the root of the URL. */ public JettyRunner(Object app) { server = new Server(); ServletContextHandler root = new ServletContextHandler(server, "/", ServletContextHandler.SESSIONS); root.addServlet(new ServletHolder(new Stapler()), "/*"); WebApp.get(root.getServletContext()).setApp(app); }