⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jahiaapplicationsdispatchingservletservice.java

📁 java 写的一个新闻发布系统
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
/* *                                   ____. *                       __/\ ______|    |__/\.     _______ *            __   .____|    |       \   |    +----+       \ *    _______|  /--|    |    |    -   \  _    |    :    -   \_________ *   \\______: :---|    :    :           |    :    |         \________> *           |__\---\_____________:______:    :____|____:_____\ *                                      /_____| * *              . . . i n   j a h i a   w e   t r u s t . . . * * * * ----- BEGIN LICENSE BLOCK ----- * Version: JCSL 1.0 * * The contents of this file are subject to the Jahia Community Source License * 1.0 or later (the "License"); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * http://www.jahia.org/license * * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the rights, obligations and limitations governing use of the contents * of the file. The Original and Upgraded Code is the Jahia CMS and Portal * Server. The developer of the Original and Upgraded Code is JAHIA Ltd. JAHIA * Ltd. owns the copyrights in the portions it created. All Rights Reserved. * * The Shared Modifications are Jahia View Helper. * * The Developer of the Shared Modifications is Jahia Solution S�rl. * Portions created by the Initial Developer are Copyright (C) 2002 by the * Initial Developer. All Rights Reserved. * * Contributor(s): * 20-AUG-2003, Jahia Solutions Sarl, Fulco Houkes * * ----- END LICENSE BLOCK ----- */package org.jahia.services.applications;import java.io.IOException;import java.util.Enumeration;import java.util.Vector;import javax.servlet.RequestDispatcher;import javax.servlet.ServletContext;import javax.servlet.ServletException;import javax.servlet.http.HttpSession;import org.jahia.data.applications.ApplicationBean;import org.jahia.data.applications.ApplicationContext;import org.jahia.data.applications.ServletBean;import org.jahia.data.cache.JahiaSimpleCache;import org.jahia.exceptions.JahiaException;import org.jahia.exceptions.JahiaInitializationException;import org.jahia.exceptions.JahiaSessionExpirationException;import org.jahia.params.ParamBean;import org.jahia.registries.ServicesRegistry;import org.jahia.settings.JahiaPrivateSettings;import org.jahia.utils.JahiaConsole;/** * This service handles dispatching requests to sub-applications, that is to say servlets or JSP * under the same context or another one. The context, destination application and arguments are * retrieved from Jahia's application database. * * Note: * One of the reasons that we are requesting the output of servlets and JSPs as String is to enable * further output processing before sending out to the browser. There might be a more efficient way * to do this by implemented variable PrintWriters, but this is simple enough and works well. If * we hit performance walls on this we might want to look at this second approach. It is notably * used by the Engine's to generate forms whose content in generated at a handling time and then * re-forwarded for final output rendering. (see the Fetcher Service for an example of this use). * * @todo : Currently dispatching to a JSP is no longer possible because on Tomcat's implementation * there seems to be a problems using a getNamedDispatcher on a <jsp-file> declaration. * Will have to double check this for the next version of Jahia. * @todo : test session awareness caches * * @author Serge Huber. * */public class JahiaApplicationsDispatchingServletService        extends JahiaApplicationsDispatchingService {    /** the service unique instance */    private static JahiaApplicationsDispatchingServletService instance;    private static final String APP_ID_SEPARATOR = "_";    private static final String CACHE_ID_SEPARATOR = ":";    /** the output cache */    private JahiaSimpleCache outputCache = null;    /** the request cache */    private JahiaSimpleCache requestCache = null;    private boolean cacheOutputBoolean;    private boolean inheritJahiaSessionAttributes = false;    /**     * The constructor is protected because of singleton pattern     */    protected JahiaApplicationsDispatchingServletService () {        JahiaConsole.println ("DispatchingServletService", "***** Starting Service *****");        cacheOutputBoolean = true;    }    /**     * @return Retrieves the instance of the servlet service singleton     */    public static synchronized JahiaApplicationsDispatchingServletService        getInstance () {        if (instance == null) {            instance = new JahiaApplicationsDispatchingServletService();        }        return instance;    }    /**     * Initializes the servlet dispatching service with parameters loaded     * from the Jahia configuration file.         * @param jSettings private settings object that contains Jahia configuration     * parameters     * @throws JahiaInitializationException shouldn't be thrown, only to be     * compliant with the interface.     */    public void init (JahiaPrivateSettings jSettings)        throws JahiaInitializationException    {        inheritJahiaSessionAttributes = jSettings.                                        isAppInheritingJahiaSessionAttributes();        outputCache = new JahiaSimpleCache (                "OutputCache", "Portlet application output cache",                jSettings.getOutputCacheSize());        requestCache = new JahiaSimpleCache (                "RequestCache", "Portlet application request cache",                jSettings.getRequestCacheSize());    }    /**     * Actually does the dispatching to the web application, along with all the     * request and response wrapping process.         * @param jParams Jahia's parameters object passed mostly because it contains     * the request and response objects     * @param appBean This object contains Jahia's persistant definition         * of the application and is used for emulation generation as well as request     * cache generation.     * @param appUniqueIDStr This string contains a concatenation of the appID     * that comes from the application definition in Jahia's persistant storage     * with the fieldID to make sure the resulting ID is unique for the page     * (to properly handle the case of having twice the same application on the         * same page). It is used mostly for the response.encodeURL behaviour to handle     * the routing of requests.         * @param appURL String containg the request URL to use for the emulation of     * the request object         * @param appMethod String containing the method type to emulate (POST, GET,     * PUT, ...)     * @param cacheOutput Specifies whether the application output cache table     * should be updated with the result of this dispatch.     * @return A string containing the output of the servlet that we are     * dispatching to.     */    protected String dispatchRequest (ParamBean jParams,                                      ApplicationBean appBean,                                      ServletBean servletBean,                                      String appUniqueIDStr,                                      String appURL,                                      String appMethod,                                      String contextID,                                      boolean cacheOutput,                                      boolean fullScreenActivated                                      )        throws JahiaException,        JahiaSessionExpirationException {        PersistantServletRequest appRequest;        ServletIncludeRequestWrapper requestWrapper = null;        ServletIncludeResponseWrapper responseWrapper = null;        boolean mustCache = cacheOutput;        long cacheExpirationDelay = -1; // by default we never expire        JahiaConsole.println ("DispatchingServletService", "Dispatching by using request : " +                     "appMethod=" + appMethod +                     ", appURL=" + appURL);        try {            // Setting attributes in request should the application want to access some of Jahia's data            jParams.getRequest().setAttribute("org.jahia.params", jParams);            // First let's get the context in which to dispatch our request            JahiaConsole.println ("DispatchingServletService", "Trying get dispatcher to context=[" +                         servletBean.getContext() + "] appName=[" +                         servletBean.getServletName() + "]");            ServletContext dispatchedContext = jParams.getContext().getContext(                servletBean.getContext());            if (dispatchedContext == null) {                JahiaConsole.println ("DispatchingServletService", "Error getting dispatch context [" +                             servletBean.getContext() + "]");                JahiaConsole.printe ("Web application error",                             new JahiaException("Can't access context " +                                                servletBean.getContext(),                    "Error getting request context " +                    servletBean.getContext() + " for app " +                    servletBean.getName(),                    JahiaException.ERROR,                    JahiaException.APPLICATION_ERROR));                return "Error accessing application " + appBean.getName() +                    " , dispatchedContext is null ";            }            // Now let's retrieve that context's dispatcher object.            RequestDispatcher requestDispatcher = null;            if (servletBean.getWebAppType() == ServletBean.JSP_TYPE) {                // we are doing this because most serlvet containers do not support                // servlet names for JSP pages...                requestDispatcher = dispatchedContext.getRequestDispatcher(                    servletBean.getservletsrc());            } else if (servletBean.getWebAppType() == ServletBean.SERVLET_TYPE) {                // Retrieving a named dispatcher is done to avoid generation of                // include attribute which confuse JSP inclusion later on...                requestDispatcher = dispatchedContext.getNamedDispatcher(                    servletBean.getServletName());                JahiaConsole.println ("DispatchingServletService", "Retrieved NamedDispatcher for servlet name " +                             servletBean.getServletName());            }            RequestDispatcherWrapper sessionDispatcher = new                RequestDispatcherWrapper(requestDispatcher);            if (sessionDispatcher == null) {                JahiaConsole.println ("DispatchingServletService",                    "Error getting request dispatcher because sessionDispatcher is null");                JahiaConsole.printe ("Error in web application",                             new JahiaException("Can't access application " +                                                appBean.getName(),                    "Error getting request dispatcher for app " +                    appBean.getName(),                    JahiaException.ERROR,                    JahiaException.APPLICATION_ERROR));                return "Error accessing application " + appBean.getName() +                    " , sessionDispatcher is null ";            }            jParams.getResponse().setContentType("text/html");            if (appBean == null) {                JahiaConsole.println ("DispatchingServletService", "Application bean object is null !!");            }            appRequest = new PersistantServletRequest(appBean,                servletBean,                appUniqueIDStr,                appURL,                appMethod,                contextID                );            JahiaConsole.println ("DispatchingServletService", "appRequest URL :" + appRequest.getURL());            requestWrapper = new ServletIncludeRequestWrapper(jParams.                getRequest(),                appRequest.getURL(),                appRequest.getContext(),

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -