List of usage examples for javax.servlet DispatcherType INCLUDE
DispatcherType INCLUDE
To view the source code for javax.servlet DispatcherType INCLUDE.
Click Source Link
From source file:org.eclipse.gyrex.http.jetty.internal.app.ApplicationHandler.java
@Override public void doScope(String target, final Request baseRequest, final HttpServletRequest request, final HttpServletResponse response) throws IOException, ServletException { /*//from w w w . j a v a2s . co m * IMPLEMENTATION NOTE * * This method is overridden to customize the path handling. * * Normally, a ContextHandler has a context path. However, the ApplicationHandler * must inherit the context path from the calling ApplicationHandlerCollection because * it changes depending on the incoming url. * * Additionally, class loader handling has been disabled in order to rely on the Equinox default. */ // note, we do not support requests going through different contexts final ContextHandler.Context origContext = baseRequest.getContext(); if ((origContext != null) && (origContext != _scontext)) throw new IllegalStateException( "origContext != this context, nesting/cross-application routing not supported!"); // backup paths final String origContextPath = baseRequest.getContextPath(); final String origServletPath = baseRequest.getServletPath(); final String origPathInfo = baseRequest.getPathInfo(); // if the current context is not set, we need to set and restore final boolean newContext = (origContext == null) || (currentContextPath.get() == null); // set 'current' context path if not already set if (newContext) { // note, we rely on ApplicationHandlerCollection to pre-set the // correct context path on the request currentContextPath.set(baseRequest.getContextPath()); } try { final String contextPath = currentContextPath.get(); String pathInfo = null; final DispatcherType dispatch = baseRequest.getDispatcherType(); // Are we already in this context? if (newContext) { // check the target if (DispatcherType.REQUEST.equals(dispatch) || DispatcherType.ASYNC.equals(dispatch)) { // perform checkContext to support unavailable status if (!checkContext(target, baseRequest, response)) return; // only accept requests coming through ApplicationHandlerCollection if (contextPath == null) return; // calculate paths if (target.length() > contextPath.length()) { if (contextPath.length() > 1) { target = target.substring(contextPath.length()); } pathInfo = target; } else if (contextPath.length() == 1) { target = URIUtil.SLASH; pathInfo = URIUtil.SLASH; } else { // redirect null path infos in order to have context request end with / baseRequest.setHandled(true); if (baseRequest.getQueryString() != null) { response.sendRedirect(URIUtil.addPaths(baseRequest.getRequestURI(), URIUtil.SLASH) + "?" + baseRequest.getQueryString()); } else { response.sendRedirect(URIUtil.addPaths(baseRequest.getRequestURI(), URIUtil.SLASH)); } return; } } } else { // calculate paths for forwarded requests // (note, handle error dispatches like forwards for custom error handler support) if ((DispatcherType.FORWARD.equals(dispatch) || DispatcherType.ERROR.equals(dispatch)) && target.startsWith(URIUtil.SLASH)) { pathInfo = target; } } // update the paths baseRequest.setContext(_scontext); if (!DispatcherType.INCLUDE.equals(dispatch) && target.startsWith(URIUtil.SLASH)) { if (contextPath.length() == 1) { baseRequest.setContextPath(EMPTY_STRING); } else { baseRequest.setContextPath(contextPath); } baseRequest.setServletPath(null); baseRequest.setPathInfo(pathInfo); } // set application handler debug info reference if (showDebugInfo) { final StringBuilder dump = new StringBuilder(); dump(dump); baseRequest.setAttribute(ATTRIBUTE_DEBUG_INFO, dump.toString()); } // next scope // start manual inline of nextScope(target,baseRequest,request,response); if (never()) { nextScope(target, baseRequest, request, response); } else if (_nextScope != null) { _nextScope.doScope(target, baseRequest, request, response); } else if (_outerScope != null) { _outerScope.doHandle(target, baseRequest, request, response); } else { doHandle(target, baseRequest, request, response); } // end manual inline (pathetic attempt to reduce stack depth) } finally { if (newContext) { // reset the context and servlet path baseRequest.setContext(origContext); baseRequest.setContextPath(origContextPath); baseRequest.setServletPath(origServletPath); baseRequest.setPathInfo(origPathInfo); currentContextPath.set(null); } } }
From source file:org.openspaces.core.space.RestBean.java
@Override public void afterPropertiesSet() throws Exception { int runningNumber = clusterInfo.getRunningNumber(); try {/*from w w w.ja v a 2s .c om*/ jettyPort = Integer.valueOf(this.port); } catch (NumberFormatException e) { throw new CannotCreateContainerException("Port should be number"); } jettyPort += runningNumber; server = new Server(); server.setStopAtShutdown(true); server.setGracefulShutdown(1000); SelectChannelConnector connector = new SelectChannelConnector(); connector.setPort(jettyPort); server.setConnectors(new Connector[] { connector }); String ispaceName, igroups, ilocators; if (gigaspace == null && spaceName == null) { throw new CannotCreateContainerException( "Either giga-space or space-name attribute should be specified."); } if (gigaspace != null && spaceName != null) { throw new CannotCreateContainerException( "Either giga-space or space-name attribute can be specified but not both."); } if (spaceName != null) { ispaceName = spaceName; //TODO validate groups and locators ? igroups = (groups == null ? null : groups); ilocators = (locators == null ? null : locators); } else { IJSpace space = gigaspace.getSpace(); ispaceName = space.getName(); String[] lookupgroups = space.getFinderURL().getLookupGroups(); if (lookupgroups == null || lookupgroups.length == 0) { igroups = null; } else { igroups = StringUtils.join(lookupgroups, ",", 0, lookupgroups.length); } LookupLocator[] lookuplocators = space.getFinderURL().getLookupLocators(); if (lookuplocators == null || lookuplocators.length == 0) { ilocators = null; } else { ilocators = ""; for (int i = 0; i < lookuplocators.length; i++) { ilocators += lookuplocators[i].getHost() + ":" + lookuplocators[i].getPort(); if (i != (lookuplocators.length - 1)) { ilocators += ","; } } } } logger.info("Starting REST service on port [" + jettyPort + "]"); webAppContext = new WebAppContext(); filterHolder = new FilterHolder(RequestStatisticsFilter.class); webAppContext.addFilter(filterHolder, "/*", EnumSet.of(DispatcherType.INCLUDE, DispatcherType.REQUEST)); webAppContext.setContextPath("/"); webAppContext.setWar(SystemInfo.singleton().locations().lib() + "/optional/rest/xap-rest.war"); webAppContext.setInitParameter("port", port); webAppContext.setInitParameter("spaceName", ispaceName); if (igroups != null && !igroups.equalsIgnoreCase("null")) { logger.debug("Applying groups " + igroups); webAppContext.setInitParameter("lookupGroups", igroups); } if (ilocators != null && !ilocators.equalsIgnoreCase("null")) { logger.debug("Applying locators " + ilocators); webAppContext.setInitParameter("lookupLocators", ilocators); } if (properties != null && properties.getProperty("datetime_format") != null) { webAppContext.setInitParameter("datetime_format", properties.getProperty("datetime_format")); } server.setHandler(webAppContext); try { server.start(); jettyStarted = true; logger.info("REST service is started"); } catch (Exception e) { logger.error("Unable to start rest service on port [" + jettyPort + "]", e); throw new CannotCreateContainerException("Unable to start rest server on port [" + jettyPort + "]", e); } }
From source file:org.siphon.d2js.D2jsRunner.java
public String getServletPath(HttpServletRequest request) { // FORWARD, INCLUDE, REQUEST, ASYNC, ERROR if (request.getDispatcherType() == DispatcherType.REQUEST) { return request.getServletPath(); } else if (request.getDispatcherType() == DispatcherType.INCLUDE) { return (String) request.getAttribute(Globals.DISPATCHER_REQUEST_PATH_ATTR); } else {//from w w w . j av a 2 s.co m return request.getServletPath(); // not sure } }