Java Code Examples for javax.servlet.ServletContext#getContext()

The following examples show how to use javax.servlet.ServletContext#getContext() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PortletToolRenderService.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
private boolean isPortletApplication(ServletContext context,
		ToolConfiguration configuration) throws ToolRenderException,
		MalformedURLException
{
	SakaiPortletWindow window = registry.getOrCreatePortletWindow(configuration);
	if (window == null)
	{
		return false;
	}
	log.debug("Checking context for potential portlet ");
	ServletContext crossContext = context.getContext(window.getContextPath());
	if (log.isDebugEnabled())
	{
		log.debug("Got servlet context as  " + crossContext);
		log.debug("Getting Context for path " + window.getContextPath());
		log.debug("Base Path " + crossContext.getRealPath("/"));
		log.debug("Context Name " + crossContext.getServletContextName());
		log.debug("Server Info " + crossContext.getServerInfo());
		log.debug("      and it is a portlet ? :"
				+ (crossContext.getResource("/WEB-INF/portlet.xml") != null));
	}
	return crossContext.getResource("/WEB-INF/portlet.xml") != null;
}
 
Example 2
Source File: PortletContextManager.java    From portals-pluto with Apache License 2.0 6 votes vote down vote up
/**
 * Retrieve the servlet context of the portlet web app.
 * @param portalContext The servlet context of the portal web app.
 * @param portletContextPath The context path of the portlet web app.
 * The given path must be begin with "/" (see {@link ServletContext#getContext(String)}).
 * @return The servlet context of the portlet web app.
 * @throws PortletContainerException if the servlet context cannot be
 * retrieved for the given context path
 */
public static ServletContext getPortletContext(ServletContext portalContext,
    String portletContextPath) throws PortletContainerException {
    if (Configuration.preventUnecessaryCrossContext()) {
        String portalPath = getContextPath(portalContext);
        if (portalPath.equals(portletContextPath)) {
            return portalContext;
        }
    }

    //Hack to deal with inconsistence in root context handling between
    //ServletContext.getContextPath and ServletContext.getContext
    if ("".equals(portletContextPath)) {
        portletContextPath = "/";
    }
    ServletContext portletAppCtx = portalContext.getContext(portletContextPath);
    if (portletAppCtx == null) {
        final String msg = "Unable to obtain the servlet context for the " +
          "portlet app context path [" + portletContextPath + "]. Make " +
          "sure that the portlet app has been deployed and that cross " +
          "context support is enabled for the portal app.";
        throw new PortletContainerException(msg);
    }
    return portletAppCtx;
}
 
Example 3
Source File: PortletToolRenderService.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
private boolean isPortletApplication(ServletContext context,
		ToolConfiguration configuration) throws ToolRenderException,
		MalformedURLException
{
	SakaiPortletWindow window = registry.getOrCreatePortletWindow(configuration);
	if (window == null)
	{
		return false;
	}
	log.debug("Checking context for potential portlet ");
	ServletContext crossContext = context.getContext(window.getContextPath());
	if (log.isDebugEnabled())
	{
		log.debug("Got servlet context as  " + crossContext);
		log.debug("Getting Context for path " + window.getContextPath());
		log.debug("Base Path " + crossContext.getRealPath("/"));
		log.debug("Context Name " + crossContext.getServletContextName());
		log.debug("Server Info " + crossContext.getServerInfo());
		log.debug("      and it is a portlet ? :"
				+ (crossContext.getResource("/WEB-INF/portlet.xml") != null));
	}
	return crossContext.getResource("/WEB-INF/portlet.xml") != null;
}
 
Example 4
Source File: TestRequestDispatcher.java    From joynr with Apache License 2.0 6 votes vote down vote up
private void forwardToUrl(final String targetContextPath,
                          Request baseRequest,
                          HttpServletResponse response) throws ServletException, IOException {

    logger.info("Forward request {} to context {}", baseRequest.toString(), targetContextPath);

    synchronized (contextForwardCounts) {
        int currentContextForwardCount = 0;
        if (contextForwardCounts.containsKey(targetContextPath)) {
            currentContextForwardCount = contextForwardCounts.get(targetContextPath);
        }
        contextForwardCounts.put(targetContextPath, currentContextForwardCount + 1);
    }

    ServletContext currentContext = baseRequest.getServletContext();
    String currentContextPath = currentContext.getContextPath();

    String forwardContextPath = currentContextPath.replace(ClusteredBounceProxyWithDispatcher.CONTEXT_DISPATCHER,
                                                           targetContextPath);

    ServletContext forwardContext = currentContext.getContext(forwardContextPath);
    String forwardPath = baseRequest.getPathInfo();
    RequestDispatcher requestDispatcher = forwardContext.getRequestDispatcher(forwardPath);

    requestDispatcher.forward(baseRequest, response);
}
 
Example 5
Source File: RequestDispatcherProvider.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected ServletContext getServletContext() {
    ServletContext sc = getMessageContext().getServletContext();
    if (servletContextPath != null) {
        sc = sc.getContext(servletContextPath);
        if (sc == null) {
            String message =
                new org.apache.cxf.common.i18n.Message("RESOURCE_DISPATCH_NOT_FOUND",
                                                       BUNDLE, servletContextPath).toString();
            LOG.severe(message);
            throw ExceptionUtils.toInternalServerErrorException(null, null);
        }
    }
    return sc;
}
 
Example 6
Source File: SSIServletExternalResolver.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
protected boolean isRootContext(ServletContext servletContext) {
    return servletContext == servletContext.getContext("/");
}
 
Example 7
Source File: SSIServletExternalResolver.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
protected boolean isRootContext(ServletContext servletContext) {
    return servletContext == servletContext.getContext("/");
}
 
Example 8
Source File: SSIServletExternalResolver.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
protected boolean isRootContext(ServletContext servletContext) {
    return servletContext == servletContext.getContext("/");
}