javax.servlet.ServletContext#getNamedDispatcher ( )源码实例Demo

下面列出了javax.servlet.ServletContext#getNamedDispatcher ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

public PortletRequestDispatcher getNamedDispatcher(ServletContext servletContext, PortletApplicationDefinition app,
                                                   String name)
{
    if (LOG.isDebugEnabled())
    {
        LOG.debug("Named PortletRequestDispatcher requested for name: "+name+" at context: "+app.getContextPath());
    }
    
    RequestDispatcher dispatcher = servletContext.getNamedDispatcher(name);
    if (dispatcher != null)
    {
        return new PortletRequestDispatcherImpl(dispatcher, name, true);
    }
    if (LOG.isInfoEnabled())
    {
        LOG.info("No matching request dispatcher found for name: "+ name);
    }
    return null;
}
 
源代码2 项目: BIMserver   文件: GenericWebServiceServlet.java
protected void redirect(HttpServletRequest request, HttpServletResponse response, String pathInfo) throws ServletException {

		String theServletPath = dispatcherServletPath == null ? "/" : dispatcherServletPath;

		ServletContext sc = super.getServletContext();
		RequestDispatcher rd = dispatcherServletName != null ? sc.getNamedDispatcher(dispatcherServletName) : sc.getRequestDispatcher(theServletPath + pathInfo);
		if (rd == null) {
			throw new ServletException("No RequestDispatcher can be created for path " + pathInfo);
		}
		try {
			HttpServletRequestFilter servletRequest = new HttpServletRequestFilter(request, pathInfo, theServletPath);
			rd.forward(servletRequest, response);
		} catch (Throwable ex) {
			throw new ServletException("RequestDispatcher for path " + pathInfo + " has failed");
		}
	}
 
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
		throws Exception {

	ServletContext servletContext = getServletContext();
	Assert.state(servletContext != null, "No ServletContext");
	RequestDispatcher rd = servletContext.getNamedDispatcher(this.servletName);
	if (rd == null) {
		throw new ServletException("No servlet with name '" + this.servletName + "' defined in web.xml");
	}

	// If already included, include again, else forward.
	if (useInclude(request, response)) {
		rd.include(request, response);
		if (logger.isTraceEnabled()) {
			logger.trace("Included servlet [" + this.servletName +
					"] in ServletForwardingController '" + this.beanName + "'");
		}
	}
	else {
		rd.forward(request, response);
		if (logger.isTraceEnabled()) {
			logger.trace("Forwarded to servlet [" + this.servletName +
					"] in ServletForwardingController '" + this.beanName + "'");
		}
	}

	return null;
}
 
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
		throws Exception {

	ServletContext servletContext = getServletContext();
	Assert.state(servletContext != null, "No ServletContext");
	RequestDispatcher rd = servletContext.getNamedDispatcher(this.servletName);
	if (rd == null) {
		throw new ServletException("No servlet with name '" + this.servletName + "' defined in web.xml");
	}

	// If already included, include again, else forward.
	if (useInclude(request, response)) {
		rd.include(request, response);
		if (logger.isTraceEnabled()) {
			logger.trace("Included servlet [" + this.servletName +
					"] in ServletForwardingController '" + this.beanName + "'");
		}
	}
	else {
		rd.forward(request, response);
		if (logger.isTraceEnabled()) {
			logger.trace("Forwarded to servlet [" + this.servletName +
					"] in ServletForwardingController '" + this.beanName + "'");
		}
	}

	return null;
}
 
源代码5 项目: doodle   文件: SimpleUrlHandler.java
public SimpleUrlHandler(ServletContext servletContext) {
    defaultServlet = servletContext.getNamedDispatcher(TOMCAT_DEFAULT_SERVLET);

    if (null == defaultServlet) {
        throw new RuntimeException("没有默认的Servlet");
    }

    log.info("The default servlet for serving static resource is [{}]", TOMCAT_DEFAULT_SERVLET);
}
 
源代码6 项目: mycore   文件: MCRServletTarget.java
@Override
public void handleSubmission(ServletContext context, MCRServletJob job, MCREditorSession session,
    String servletNameOrPath)
    throws Exception {
    session.getSubmission().setSubmittedValues(job.getRequest().getParameterMap());
    Document result = session.getEditedXML();

    if (session.getValidator().isValid()) {
        result = MCRChangeTracker.removeChangeTracking(result);
        result = session.getXMLCleaner().clean(result);
        result = session.getPostProcessor().process(result);

        RequestDispatcher dispatcher = context.getNamedDispatcher(servletNameOrPath);
        if (dispatcher == null) {
            dispatcher = context.getRequestDispatcher(servletNameOrPath);
        }

        job.getRequest().setAttribute("MCRXEditorSubmission", result);

        session.setBreakpoint("After handling target servlet " + servletNameOrPath);

        dispatcher.forward(job.getRequest(), job.getResponse());
    } else {
        session.setBreakpoint("After validation failed, target servlet " + servletNameOrPath);
        job.getResponse().sendRedirect(job.getResponse().encodeRedirectURL(session.getRedirectURL(null)));
    }
}
 
源代码7 项目: cxf   文件: RequestDispatcherProvider.java
protected RequestDispatcher getRequestDispatcher(ServletContext sc, Class<?> clazz, String path) {

        RequestDispatcher rd = dispatcherName != null ? sc.getNamedDispatcher(dispatcherName)
                                                      : sc.getRequestDispatcher(path);
        if (rd == null) {
            String message =
                new org.apache.cxf.common.i18n.Message("RESOURCE_PATH_NOT_FOUND",
                                                       BUNDLE, path).toString();
            LOG.severe(message);
            throw ExceptionUtils.toInternalServerErrorException(null, null);
        }
        return rd;
    }
 
源代码8 项目: cxf   文件: AbstractHTTPServlet.java
protected void redirect(HttpServletRequest request, HttpServletResponse response, String pathInfo)
    throws ServletException {
    boolean customServletPath = dispatcherServletPath != null;
    String theServletPath = customServletPath ? dispatcherServletPath : "/";

    ServletContext sc = super.getServletContext();
    RequestDispatcher rd = dispatcherServletName != null
        ? sc.getNamedDispatcher(dispatcherServletName)
        : sc.getRequestDispatcher((theServletPath + pathInfo).replace("//", "/"));
    if (rd == null) {
        String errorMessage = "No RequestDispatcher can be created for path " + pathInfo;
        if (dispatcherServletName != null) {
            errorMessage += ", dispatcher name: " + dispatcherServletName;
        }
        throw new ServletException(errorMessage);
    }
    try {
        for (Map.Entry<String, String> entry : redirectAttributes.entrySet()) {
            request.setAttribute(entry.getKey(), entry.getValue());
        }
        HttpServletRequest servletRequest =
            new HttpServletRequestRedirectFilter(request, pathInfo, theServletPath, customServletPath);
        if (PropertyUtils.isTrue(getServletConfig().getInitParameter(REDIRECT_WITH_INCLUDE_PARAMETER))) {
            rd.include(servletRequest, response);
        } else {
            rd.forward(servletRequest, response);
        }
    } catch (Throwable ex) {
        throw new ServletException("RequestDispatcher for path " + pathInfo + " has failed", ex);
    }
}
 
源代码9 项目: doodle   文件: JspHandler.java
public JspHandler(ServletContext servletContext) {
    jspServlet = servletContext.getNamedDispatcher(JSP_SERVLET);
    if (null == jspServlet) {
        throw new RuntimeException("没有jsp Servlet");
    }
}
 
源代码10 项目: sakai   文件: ActiveToolComponent.java
/**
 * @inheritDoc
 */
public void register(Tool tool, ServletContext context)
{
	ActiveTool at = null;

	// make it an active tool
	if (tool instanceof MyActiveTool)
	{
		at = (MyActiveTool) tool;
	}
	else if (tool instanceof ActiveTool)
	{
		at = (ActiveTool) tool;
	}
	else
	{
		at = new MyActiveTool(tool);
	}

	// TODO: elevate setServletContext to ActiveTool interface to avoid instance testing
	if (at instanceof MyActiveTool) {
		((MyActiveTool) at).setServletContext(context);
	}

	// KNL-409 - JSR-168 Portlets do not dispatch the same as normal
	// Sakai tools - so the warning below is not necessary for JSR-168
	// tools

               String portletContext = null;
               Properties toolProps = at.getFinalConfig();
               if (toolProps != null) {
               	portletContext = toolProps
                               .getProperty(TOOL_PORTLET_CONTEXT_PATH);
	}

	if (portletContext == null )
	{
		// try getting the RequestDispatcher, just to test - but DON'T SAVE IT!
		// Tomcat's RequestDispatcher is NOT thread safe and must be gotten from the context
		// every time its needed!
		RequestDispatcher dispatcher = context.getNamedDispatcher(at.getId());
		if (dispatcher == null)
		{
			log.warn("missing dispatcher for tool: " + at.getId());
		}
	}

	m_tools.put(at.getId(), at);
}
 
源代码11 项目: sakai   文件: ActiveToolComponent.java
/**
 * @inheritDoc
 */
public void register(Tool tool, ServletContext context)
{
	ActiveTool at = null;

	// make it an active tool
	if (tool instanceof MyActiveTool)
	{
		at = (MyActiveTool) tool;
	}
	else if (tool instanceof ActiveTool)
	{
		at = (ActiveTool) tool;
	}
	else
	{
		at = new MyActiveTool(tool);
	}

	// TODO: elevate setServletContext to ActiveTool interface to avoid instance testing
	if (at instanceof MyActiveTool) {
		((MyActiveTool) at).setServletContext(context);
	}

	// KNL-409 - JSR-168 Portlets do not dispatch the same as normal
	// Sakai tools - so the warning below is not necessary for JSR-168
	// tools

               String portletContext = null;
               Properties toolProps = at.getFinalConfig();
               if (toolProps != null) {
               	portletContext = toolProps
                               .getProperty(TOOL_PORTLET_CONTEXT_PATH);
	}

	if (portletContext == null )
	{
		// try getting the RequestDispatcher, just to test - but DON'T SAVE IT!
		// Tomcat's RequestDispatcher is NOT thread safe and must be gotten from the context
		// every time its needed!
		RequestDispatcher dispatcher = context.getNamedDispatcher(at.getId());
		if (dispatcher == null)
		{
			log.warn("missing dispatcher for tool: " + at.getId());
		}
	}

	m_tools.put(at.getId(), at);
}