public StandardWrapper addServlet(String path, String name, String clazz) throws ServletException { StandardWrapper servlet = (StandardWrapper) rootContext.createWrapper(); servlet.setName(name); servlet.setServletClass(clazz); servlet.setLoadOnStartup(1); rootContext.addChild(servlet); rootContext.addServletMapping(path, name); servlet.setParent(rootContext); // servlet.load(); return servlet; }
private void initializeServlet(Context context, String name) { Container child = context.findChild(name); if (child instanceof StandardWrapper) { try { StandardWrapper wrapper = (StandardWrapper) child; wrapper.deallocate(wrapper.allocate()); } catch (ServletException ex) { // Continue } } }
private void load(Wrapper wrapper) { try { wrapper.load(); } catch (ServletException ex) { String message = sm.getString("standardContext.loadOnStartup.loadException", getName(), wrapper.getName()); if (getComputedFailCtxIfServletStartFails()) { throw new WebServerException(message, ex); } getLogger().error(message, StandardWrapper.getRootCause(ex)); } }
unavailable(f); throw f; } catch (ServletException f) { } catch (Throwable f) { ExceptionUtils.handleThrowable(f); getServletContext().log("StandardWrapper.Throwable", f ); throw new ServletException (sm.getString("standardWrapper.initException", getName()), f);
loadServletClass(); servlet = ((StandardContext)getParent()).createServletInstance( servletClass); } catch (ClassCastException e) { unavailable(null); throw new ServletException(msg, e); } catch (Throwable e) { unavailable(null); throw new ServletException(msg, e); if (!isServletAllowed(servlet)) { String msg = MessageFormat.format(rb.getString(LogFacade.PRIVILEGED_SERVLET_CANNOT_BE_LOADED_EXCEPTION), servletClass.getName()); throw new SecurityException(msg); (isContainerProvidedServlet(servletClass.getName()) || ((Context)getParent()).getPrivileged() )) { ((ContainerServlet) servlet).setWrapper(this); fireContainerEvent("load", this);
Context context = (Context) wrapper.getParent(); boolean unavailable = !context.getAvailable() || wrapper.isUnavailable(); servlet = wrapper.allocate(); container.getLogger().error(sm.getString("standardWrapper.allocateException", wrapper.getName()), StandardWrapper.getRootCause(e)); throwable = e; exception(request, response, e); } catch (Throwable e) { ExceptionUtils.handleThrowable(e); container.getLogger().error(sm.getString("standardWrapper.allocateException", wrapper.getName()), e); throwable = e; exception(request, response, e); exception(request, response, e); } catch (IOException e) { container.getLogger().error(sm.getString( "standardWrapper.serviceException", wrapper.getName(), "standardWrapper.serviceException", wrapper.getName(), Throwable rootCause = StandardWrapper.getRootCause(e); wrapper.getName(), context.getName(), e.getMessage()), rootCause);
for (int i = 0; i < children.length; i++) { Wrapper wrapper = (Wrapper) children[i]; int loadOnStartup = wrapper.getLoadOnStartup(); if (loadOnStartup < 0) continue; for (Wrapper wrapper : list) { try { wrapper.load(); } catch (ServletException e) { getLogger().error(sm.getString("standardWrapper.loadException", getName()), StandardWrapper.getRootCause(e));
/** * Process an UnavailableException, marking this servlet as unavailable * for the specified amount of time. * * @param unavailable The exception that occurred, or <code>null</code> * to mark this servlet as permanently unavailable */ @Override public void unavailable(UnavailableException unavailable) { getServletContext().log(sm.getString("standardWrapper.unavailable", getName())); if (unavailable == null) setAvailable(Long.MAX_VALUE); else if (unavailable.isPermanent()) setAvailable(Long.MAX_VALUE); else { int unavailableSeconds = unavailable.getUnavailableSeconds(); if (unavailableSeconds <= 0) unavailableSeconds = 60; // Arbitrary default setAvailable(System.currentTimeMillis() + (unavailableSeconds * 1000L)); } }
public Set<String> addMapping(String... urlPatterns) { Set<String> conflicts = new HashSet<String>(); if (!((Context) wrapper.getParent()).isStarting()) { throw MESSAGES.cannotAddServletRegistrationAfterInit(((Context) wrapper.getParent()).getPath()); } if (urlPatterns == null || urlPatterns.length == 0) { throw MESSAGES.invalidServletRegistrationArguments(); } for (String urlPattern : urlPatterns) { Context context = ((Context) wrapper.getParent()); String wrapperName = context.findServletMapping(urlPattern); if (wrapperName != null) { Wrapper servletWrapper = (Wrapper) context.findChild(wrapperName); if (servletWrapper.isOverridable()) { // Some Wrappers (from global and host web.xml) may be // overridden rather than generating a conflict context.removeServletMapping(urlPattern); } else { conflicts.add(urlPattern); } } } if (conflicts.isEmpty()) { for (String urlPattern : urlPatterns) { ((Context) wrapper.getParent()).addServletMapping(urlPattern, wrapper.getName()); } } return conflicts; }
public boolean setInitParameter(String name, String value) { if (!((Context) wrapper.getParent()).isStarting()) { throw MESSAGES.cannotAddServletRegistrationAfterInit(((Context) wrapper.getParent()).getPath()); } if (name == null || value == null) { throw MESSAGES.invalidServletRegistrationArguments(); } if (wrapper.findInitParameter(name) == null) { wrapper.addInitParameter(name, value); return true; } else { return false; } }
for (int i = 0; i < children.length; i++) { Wrapper wrapper = (Wrapper) children[i]; int loadOnStartup = wrapper.getLoadOnStartup(); if (loadOnStartup < 0) continue; for (Wrapper wrapper : list) { try { wrapper.load(); } catch (ServletException e) { getLogger().error(sm.getString("standardContext.loadOnStartup.loadException", getName(), wrapper.getName()), StandardWrapper.getRootCause(e)); if(getComputedFailCtxIfServletStartFails()) { return false;
public Set<String> addMapping(String... urlPatterns) { Set<String> conflicts = new HashSet<String>(); if (!((Context) wrapper.getParent()).isStarting()) { throw new IllegalStateException(sm.getString ("servletRegistration.ise", ((Context) wrapper.getParent()).getPath())); } if (urlPatterns == null || urlPatterns.length == 0) { throw new IllegalArgumentException(sm.getString("servletRegistration.iae")); } for (String urlPattern : urlPatterns) { if (((Context) wrapper.getParent()).findServletMapping(urlPattern) != null) { conflicts.add(urlPattern); } } if (conflicts.isEmpty()) { for (String urlPattern : urlPatterns) { ((Context) wrapper.getParent()).addServletMapping(urlPattern, wrapper.getName()); } } return conflicts; }
public void setLoadOnStartup(int loadOnStartup) { if (!((Context) wrapper.getParent()).isStarting()) { throw MESSAGES.cannotAddServletRegistrationAfterInit(((Context) wrapper.getParent()).getPath()); } wrapper.setLoadOnStartup(loadOnStartup); }
for (int i = 0; i < children.length; i++) { Wrapper wrapper = (Wrapper) children[i]; int loadOnStartup = wrapper.getLoadOnStartup(); if (loadOnStartup < 0) continue; for (Wrapper wrapper : list) { try { String servletClass = wrapper.getServletClass(); lifecycle.fireLifecycleEvent(Lifecycle.BEFORE_LOAD_ON_STARTUP_EVENT, servletClass); wrapper.load(); lifecycle.fireLifecycleEvent(Lifecycle.AFTER_LOAD_ON_STARTUP_EVENT, servletClass); } catch (ServletException e) { getLogger().error(MESSAGES.errorLoadingServlet(wrapper.getName()), StandardWrapper.getRootCause(e));
/** * Return <code>true</code> if the servlet class represented by this * component implements the <code>SingleThreadModel</code> interface. */ public boolean isSingleThreadModel() { // Short-cuts // If singleThreadModel is true, must have already checked this // If instance != null, must have already loaded if (singleThreadModel || instance != null) { return singleThreadModel; } // The logic to determine this safely is more complex than one might // expect. allocate() already has the necessary logic so re-use it. // Make sure the Servlet is loaded with the right class loader ClassLoader old = Thread.currentThread().getContextClassLoader(); ClassLoader webappClassLoader = ((Context) getParent()).getLoader().getClassLoader(); try { Thread.currentThread().setContextClassLoader(webappClassLoader); Servlet s = allocate(); deallocate(s); } catch (Throwable t) { ExceptionUtils.handleThrowable(t); } finally { Thread.currentThread().setContextClassLoader(old); } return singleThreadModel; }
} catch (Throwable t) { ExceptionUtils.handleThrowable(t); log.error(sm.getString("standardContext.createWrapper.error"), t); return null; wrapper = new StandardWrapper(); LifecycleListener listener = (LifecycleListener) clazz.getConstructor().newInstance(); wrapper.addLifecycleListener(listener); } catch (Throwable t) { ExceptionUtils.handleThrowable(t); log.error(sm.getString("standardContext.createWrapper.listenerError"), t); return null; ContainerListener listener = (ContainerListener) clazz.getConstructor().newInstance(); wrapper.addContainerListener(listener); } catch (Throwable t) { ExceptionUtils.handleThrowable(t); log.error(sm.getString("standardContext.createWrapper.containerListenerError"), t); return null;
/** * Creates an ad-hoc servlet wrapper from the given ad-hoc servlet info. * * @param servletInfo Ad-hoc servlet info from which to generate * ad-hoc servlet wrapper * * @return The generated ad-hoc servlet wrapper */ private Wrapper createAdHocWrapper(AdHocServletInfo servletInfo) { Wrapper adHocWrapper = new StandardWrapper(); adHocWrapper.setServletClassName( servletInfo.getServletClass().getName()); adHocWrapper.setName(servletInfo.getServletName()); Map<String,String> initParams = servletInfo.getServletInitParams(); if (initParams != null && !initParams.isEmpty()) { for(String paramName : initParams.keySet()) { adHocWrapper.addInitParameter(paramName, initParams.get(paramName)); } } return adHocWrapper; }
wrapper = new StandardWrapper(); InstanceListener listener = (InstanceListener) clazz.newInstance(); wrapper.addInstanceListener(listener); } catch (Throwable t) { log.error("createWrapper", t); ContainerListener listener = (ContainerListener) clazz.newInstance(); wrapper.addContainerListener(listener); } catch (Throwable t) { log.error("createWrapper", t);
public Set<String> addMapping(String... urlPatterns) { if (ctx.isContextInitializedCalled()) { String msg = MessageFormat.format(rb.getString(LogFacade.SERVLET_REGISTRATION_ALREADY_INIT), new Object[] {"mapping", wrapper.getName(), ctx.getName()}); throw new IllegalStateException(msg); } if (urlPatterns == null || urlPatterns.length == 0) { String msg = MessageFormat.format(rb.getString(LogFacade.SERVLET_REGISTRATION_MAPPING_URL_PATTERNS_EXCEPTION), new Object[] {wrapper.getName(), ctx.getName()}); throw new IllegalArgumentException(msg); } return ctx.addServletMapping(wrapper.getName(), urlPatterns); }
public void setLoadOnStartup(int loadOnStartup) { if (ctx.isContextInitializedCalled()) { String msg = MessageFormat.format(rb.getString(LogFacade.DYNAMIC_SERVLET_REGISTRATION_ALREADY_INIT), new Object[] {"load-on-startup", wrapper.getName(), ctx.getName()}); throw new IllegalStateException(msg); } wrapper.setLoadOnStartup(loadOnStartup); }