private void addDefaultServlet(Context context) { Wrapper defaultServlet = context.createWrapper(); defaultServlet.setName("default"); defaultServlet.setServletClass("org.apache.catalina.servlets.DefaultServlet"); defaultServlet.addInitParameter("debug", "0"); defaultServlet.addInitParameter("listings", "false"); defaultServlet.setLoadOnStartup(1); // Otherwise the default location of a Spring DispatcherServlet cannot be set defaultServlet.setOverridable(true); context.addChild(defaultServlet); context.addServletMappingDecoded("/", "default"); }
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)); } }
/** * Gets the application servlet maps. * * @param context the context * @return the application servlet maps */ public static List<ServletMapping> getApplicationServletMaps(Context context) { String[] sms = context.findServletMappings(); List<ServletMapping> servletMaps = new ArrayList<>(sms.length); for (String servletMapping : sms) { if (servletMapping != null) { String sn = context.findServletMapping(servletMapping); if (sn != null) { ServletMapping sm = new ServletMapping(); sm.setApplicationName(context.getName().length() > 0 ? context.getName() : "/"); sm.setUrl(servletMapping); sm.setServletName(sn); Container container = context.findChild(sn); if (container instanceof Wrapper) { Wrapper wrapper = (Wrapper) container; sm.setServletClass(wrapper.getServletClass()); sm.setAvailable(!wrapper.isUnavailable()); } servletMaps.add(sm); } } } return servletMaps; }
context.setWebappVersion("3.1"); context.setName("Oryx"); context.addWelcomeFile("index.html"); addErrorPages(context); wrapper.addInitParameter("javax.ws.rs.Application", OryxApplication.class.getName()); wrapper.addMapping("/*"); wrapper.setLoadOnStartup(1); wrapper.setMultipartConfigElement(new MultipartConfigElement(""));
/** * Unregister wrapper. */ private void unregisterWrapper(Wrapper wrapper) { String contextPath = ((Context) wrapper.getParent()).getPath(); String wrapperName = wrapper.getName(); if ("/".equals(contextPath)) { contextPath = ""; } String version = ((Context) wrapper.getParent()).getWebappVersion(); String hostName = wrapper.getParent().getParent().getName(); String[] mappings = wrapper.findMappings(); for (String mapping : mappings) { mapper.removeWrapper(hostName, contextPath, version, mapping); } if(log.isDebugEnabled()) { log.debug(sm.getString("mapperListener.unregisterWrapper", wrapperName, contextPath, connector)); } }
int statusCode = response.getStatus(); Context context = request.getContext(); if (context == null) return; if (!response.isError()) return; ErrorPage errorPage = context.findErrorPage(statusCode); if (errorPage != null) { response.setAppCommitted(false); request.setAttribute(RequestDispatcher.ERROR_STATUS_CODE, Integer.valueOf(statusCode)); if (message == null) message = ""; request.setAttribute(RequestDispatcher.ERROR_MESSAGE, message); request.setAttribute (ApplicationFilterFactory.DISPATCHER_REQUEST_PATH_ATTR, if (wrapper != null) request.setAttribute(RequestDispatcher.ERROR_SERVLET_NAME, wrapper.getName()); request.setAttribute(RequestDispatcher.ERROR_REQUEST_URI, request.getRequestURI()); container.getLogger().warn("Exception Processing " + errorPage, e);
if (wrapper.isUnavailable()) { wrapper.getLogger().warn( sm.getString("applicationDispatcher.isUnavailable", wrapper.getName())); long available = wrapper.getAvailable(); if ((available > 0L) && (available < Long.MAX_VALUE)) hresponse.setDateHeader("Retry-After", available); hresponse.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, sm .getString("applicationDispatcher.isUnavailable", wrapper .getName())); unavailable = true; servlet = wrapper.allocate(); wrapper.getLogger().error(sm.getString("applicationDispatcher.allocateException", wrapper.getName()), StandardWrapper.getRootCause(e)); servletException = e; } catch (Throwable e) { ExceptionUtils.handleThrowable(e); wrapper.getLogger().error(sm.getString("applicationDispatcher.allocateException", wrapper.getName()), e); wrapper.getName()), e); servlet = null; support.fireInstanceEvent(InstanceEvent.AFTER_DISPATCH_EVENT, servlet, request, response); wrapper.getLogger().error(sm.getString("applicationDispatcher.serviceException", wrapper.getName()), e);
Context context = request.getContext(); if (context == null) { return; if (log.isDebugEnabled()) { log.debug (sm.getString("standardHost.clientAbort", realError.getCause().getMessage())); ErrorPage errorPage = context.findErrorPage(throwable); if ((errorPage == null) && (realError != throwable)) { errorPage = context.findErrorPage(realError); if (wrapper != null) { request.setAttribute(RequestDispatcher.ERROR_SERVLET_NAME, wrapper.getName()); request.setAttribute(RequestDispatcher.ERROR_REQUEST_URI, if (custom(request, response, errorPage)) { try { response.finishResponse(); } catch (IOException e) { container.getLogger().warn("Exception Processing " + errorPage, e);
if (wrapper.isUnavailable()) { wrapper.getLogger().warn( sm.getString("applicationDispatcher.isUnavailable", wrapper.getName())); long available = wrapper.getAvailable(); if ((available > 0L) && (available < Long.MAX_VALUE)) hresponse.setDateHeader("Retry-After", available); hresponse.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, sm .getString("applicationDispatcher.isUnavailable", wrapper .getName())); unavailable = true; servlet = wrapper.allocate(); wrapper.getLogger().error(sm.getString("applicationDispatcher.allocateException", wrapper.getName()), StandardWrapper.getRootCause(e)); servletException = e; } catch (Throwable e) { ExceptionUtils.handleThrowable(e); wrapper.getLogger().error(sm.getString("applicationDispatcher.allocateException", wrapper.getName()), e); wrapper.getName()), e); servlet = null; ioException = e; } catch (IOException e) { wrapper.getLogger().error(sm.getString("applicationDispatcher.serviceException", wrapper.getName()), e);
int statusCode = response.getStatus(); Context context = request.getContext(); if (context == null) { return; if (!response.isError()) { return; ErrorPage errorPage = context.findErrorPage(statusCode); if (errorPage == null) { errorPage = context.findErrorPage(0); message = ""; request.setAttribute(RequestDispatcher.ERROR_MESSAGE, message); request.setAttribute(Globals.DISPATCHER_REQUEST_PATH_ATTR, errorPage.getLocation()); if (wrapper != null) { request.setAttribute(RequestDispatcher.ERROR_SERVLET_NAME, wrapper.getName()); request.setAttribute(RequestDispatcher.ERROR_REQUEST_URI, container.getLogger().warn("Exception Processing " + errorPage, e);
protected void addContext(Context context) { mapper.addContext(context.getParent().getName(), context.getName(), context, context.findWelcomeFiles(), context.getResources()); // Add all wrappers for (Container child : context.findChildren()) { Wrapper wrapper = (Wrapper) child; if (wrapper.getEnabled()) { for (String mapping : wrapper.findMappings()) { boolean jspWildCard = ("jsp".equals(wrapper.getName()) && mapping.endsWith("/*")); mapper.addWrapper(context.getParent().getName(), context.getName(), mapping, wrapper, jspWildCard); } } } }
boolean jspWildCard) { if (findChild(name) == null) throw new IllegalArgumentException (sm.getString("standardContext.servletMap.name", name)); String adjustedPattern = adjustURLPattern(pattern); if (!validateURLPattern(adjustedPattern)) throw new IllegalArgumentException (sm.getString("standardContext.servletMap.pattern", adjustedPattern)); Wrapper wrapper = (Wrapper) findChild(name2); wrapper.removeMapping(adjustedPattern); Wrapper wrapper = (Wrapper) findChild(name); wrapper.addMapping(adjustedPattern); fireContainerEvent("addServletMapping", adjustedPattern);
/** * Static version of {@link #addServlet(String, String, String)} * @param ctx Context to add Servlet to * @param servletName Servlet name (used in mappings) * @param servletClass The class to be used for the Servlet * @return The wrapper for the servlet */ public static Wrapper addServlet(Context ctx, String servletName, String servletClass) { // will do class for name and set init params Wrapper sw = ctx.createWrapper(); sw.setServletClass(servletClass); sw.setName(servletName); ctx.addChild(sw); return sw; }
context.setAllowCasualMultipartParsing(true); PippoServlet pippoServlet = new PippoServlet(); pippoServlet.setApplication(getApplication()); Wrapper wrapper = context.createWrapper(); String name = "pippoServlet"; wrapper.setName(name); wrapper.setLoadOnStartup(1); wrapper.setServlet(pippoServlet); context.addChild(wrapper); context.addServletMapping(pippoFilterPath, name);
private Set<String> getNonAsyncClassNames() { Set<String> result = new HashSet<>(); Wrapper wrapper = getWrapper(); if (!wrapper.isAsyncSupported()) { result.add(wrapper.getServletClass()); } FilterChain filterChain = getFilterChain(); if (filterChain instanceof ApplicationFilterChain) { ((ApplicationFilterChain) filterChain).findNonAsyncFilters(result); } else { result.add(sm.getString("coyoteRequest.filterAsyncSupportUnknown")); } Container c = wrapper; while (c != null) { c.getPipeline().findNonAsyncValves(result); c = c.getParent(); } return result; }
@Override public boolean setInitParameter(String name, String value) { if (name == null || value == null) { throw new IllegalArgumentException( sm.getString("applicationFilterRegistration.nullInitParam", name, value)); } if (getInitParameter(name) != null) { return false; } wrapper.addInitParameter(name, value); return true; }
private void setWsContainer(Context context, Wrapper wrapper, HttpListener wsContainer) { // Make up an ID for the WebServiceContainer // put a reference the ID in the init-params // put the WebServiceContainer in the webapp context keyed by its ID String webServicecontainerID = wrapper.getName() + WsServlet.WEBSERVICE_CONTAINER + wsContainer.hashCode(); context.getServletContext().setAttribute(webServicecontainerID, wsContainer); wrapper.addInitParameter(WsServlet.WEBSERVICE_CONTAINER, webServicecontainerID); } }
private void addDefaultServlet() { Wrapper defaultServlet = this.tomcatContext.createWrapper(); defaultServlet.setName("default"); defaultServlet.setServletClass("org.apache.catalina.servlets.DefaultServlet"); defaultServlet.addInitParameter("debug", "0"); defaultServlet.addInitParameter("listings", "false"); defaultServlet.setLoadOnStartup(1); defaultServlet.setOverridable(true); this.tomcatContext.addChild(defaultServlet); addServletMapping("/", "default"); }
public ProgrammaticContext addServlet(final String name, final Class<?> type, final String mapping, final String... initParams) { final Wrapper wrapper = createWrapper(); wrapper.setServletClass(type.getName()); wrapper.setName(name); if (initParams != null && initParams.length > 0) { for (int i = 0; i < initParams.length; i+=2) { wrapper.addInitParameter(initParams[i], initParams[i+1]); } } wrapper.setLoadOnStartup(1); // otherwise we would miss reposgitry integration at least addChild(wrapper); addServletMapping(mapping, wrapper.getName(), false); return this; }
public void enter() { if (securityService != null && request.getWrapper() != null) { oldState = securityService.enterWebApp(request.getWrapper().getRealm(), request.getPrincipal(), request.getWrapper().getRunAs()); } }