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

📄 jahiaapplicationsdispatchingservletservice.java

📁 java 写的一个新闻发布系统
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
                if (appBean == null || servletBean == null) {                    String errorMsg = "AppID : " + appID;                    throw new JahiaException(                        "Cannot retrieve application definition !",                        errorMsg,                        JahiaException.DATABASE_ERROR,                        JahiaException.ERROR);                }                outputResult = dispatchRequest(jParams,                                               appBean,                                               servletBean,                                               appUniqueIDStr,                                               appURL,                                               jParams.getRequest().getMethod(),                                               contextID,                                               cacheOutputBoolean,                                               fullScreenActivated);            } else {                outputResult = getAppOutputNoAction(appID, appUniqueIDStr,                    contextID, jParams, cacheRead, fullScreenActivated);            }        } else {            outputResult = getAppOutputNoAction(appID, appUniqueIDStr,                                                contextID, jParams, cacheRead,                                                fullScreenActivated);        }        return outputResult;    }    // @author NK    /**     * Resolve servlet mapping, return a servlet bean for the given application     * request.     */    private ServletBean getServletBean (ApplicationBean appBean, String appURL)        throws JahiaException {        ServletBean servletBean = null;        String url = ServletIncludeRequestWrapper.URLDecode(appURL);        int pos = url.indexOf(appBean.getContext());        if (pos == -1) {            String errMsg = "Cannot locate the application context path part [" +                            appBean.getContext() + "] in the appParams [" +                            appURL + "]";            throw new JahiaException(errMsg, errMsg,                                     JahiaException.ERROR,                                     JahiaException.APPLICATION_ERROR);        }        String appRequestURI = url.substring(pos);        ApplicationContext appContext = ServicesRegistry.getInstance()                                        .getJahiaApplicationContextService()                                        .getApplicationContext(appBean.            getContext());        if (appContext == null) {            String errMsg = "ApplicationContext not found for app context [" +                            appBean.getContext() + "] in the appParams [" +                            appURL + "]";            throw new JahiaException(errMsg, errMsg,                                     JahiaException.ERROR,                                     JahiaException.APPLICATION_ERROR);        }        String servletMappingPattern = appContext.                                       findServletMappingFromRequestURI(            appRequestURI);        if (servletMappingPattern != null) {            String servletName = appContext.findServletMapping(                servletMappingPattern);            servletBean = appContext.getServlet(servletName);            // store the mapping pattern information            if (servletBean != null) {                servletBean.setUrlMappingPattern(servletMappingPattern);            }        } else {            JahiaConsole.println ("DispatchingServletService",                    "None of the servlet mapping matched the app URL ["+ appURL +"]");            // no servlet mapping can resolve requested servlet            // perhaps, the requested resource is a file instead of a servlet            pos = appRequestURI.indexOf("?");            String subStr = appRequestURI;            if (pos != -1) {                subStr = appRequestURI.substring(0, pos);            }            JahiaConsole.println ("DispatchingServletService",                    " appURL without queryString = ["+ subStr +"]");            if (subStr.indexOf(".") != -1) {                JahiaConsole.println ("DispatchingServletService",                    " Servlet Bean is created for a resource (jsp,html,...) request ");                servletBean = new ServletBean(ServletBean.JSP_TYPE,                                              appBean.getName(),                                              appBean.getName(),                                              subStr.substring(appBean.                    getContext().length()),                                              appBean.getContext(),                                              "");            } else if (appContext.getWelcomeFiles().size() > 0) {                JahiaConsole.println ("DispatchingServletService",                    " Servlet Bean is created with the first welcome files ");                String welcomefile = (String) appContext.getWelcomeFiles().get(                    0);                String resourceFile = subStr.substring(appBean.getContext().                    length());                if (!resourceFile.startsWith("/")) {                    resourceFile = "/" + resourceFile;                }                if (!resourceFile.endsWith("/") && welcomefile.startsWith("/")) {                    resourceFile += "/";                }                resourceFile += welcomefile;                servletBean = new ServletBean(ServletBean.JSP_TYPE,                                              appBean.getName(),                                              welcomefile,                                              resourceFile,                                              appBean.getContext(),                                              "");            } else {                // NK 	: I added this for application without any servlet mapping information and without any welcome file                try {                    servletBean = (ServletBean) appContext.getServlets().values().                                  iterator().next();                } catch (Throwable t) {                }            }        }        return servletBean;    }    public void flushAllSessionsCaches (HttpSession session) {        JahiaConsole.println ("DispatchingServletService",                "Starting to flush all the session caches");        flushSessionOutputCache(session);        flushSessionRequestCache(session);        Enumeration enum = session.getAttributeNames();        Vector toRemove = new Vector();        while (enum.hasMoreElements()) {            String name = (String) enum.nextElement();            if (name.startsWith("org.jahia.services.applications.wasProcessed.")) {                toRemove.add(name);            }        }        int size = toRemove.size();        for (int i = 0; i < size; i++) {            session.removeAttribute( (String) toRemove.get(i));        }    }    final public void flushSessionOutputCache (HttpSession session) {        flushCacheBySession (outputCache, session);    }    final public void flushSessionRequestCache (HttpSession session) {        flushCacheBySession (requestCache, session);    }    private void flushCacheBySession (JahiaSimpleCache cache, HttpSession session) {        // null sessions are not allowed        if (session == null) {            JahiaConsole.println ("DispatchingServletService",                    "null session! Stopping flushing process.");            return;        }        JahiaConsole.println ("JahiaApplicationDispatchingServletService",                "Flushing cache ["+ cache.getCacheName() +"] for session " +                session.getId());        // find all the cache elements related to the specified session        Enumeration cacheKeys = cache.keys();        Vector keysToRemove = new Vector();        while (cacheKeys.hasMoreElements()) {            String curCacheKey = (String)cacheKeys.nextElement();            if (curCacheKey.startsWith(session.getId())) {                keysToRemove.add (curCacheKey);            }        }        for (int i=0; i<keysToRemove.size(); i++) {            String curKeyToRemove = (String) keysToRemove.get(i);            cache.removeValue (curKeyToRemove);        }    }    public void flushApplicationSessionRequestCache (HttpSession session,        String appUniqueIDStr) {        // null sessions are not allowed, neither null application IDs        if (session == null) {            JahiaConsole.println ("DispatchingServletService",                    "null session! Stopping flushing process.");            return;        }        if (appUniqueIDStr == null) {            JahiaConsole.println ("DispatchingServletService",                    "null application ID! Stopping flushing process.");            return;        }        JahiaConsole.println ("DispatchingServletService",                "Flushing request cache for session " + session.getId()                     + " and AppId=" + appUniqueIDStr);        requestCache.removeValue (buildCacheKey(session, appUniqueIDStr));    }    public void setApplicationSessionRequestCache (HttpSession session,        PersistantServletRequest request) {        if (session != null && request != null) {            requestCache.setValue ( request, buildCacheKey (session, request.getUniqueIDStr()));        } else {            JahiaConsole.println ("DispatchingServletService",                "null session or null request! Stopping caching process.");        }    }    private String buildCacheKey (HttpSession session, String appUniqueIDStr) {        return session.getId() + CACHE_ID_SEPARATOR + appUniqueIDStr;    }    /**     * if session is null flush all output entries for the given appID     *     * @param session     * @param appUniqueIDStr     */    public void flushOutputCacheByAppUniqueID (HttpSession session, String appUniqueIDStr) {        // null application IDs are not allowed        if (appUniqueIDStr == null) {            JahiaConsole.print ("JahiaApplicationDispatchingServletService",                    "null application ID! Stopping flushing process.");            return;        }        if (session != null) {            outputCache.removeValue (this.buildCacheKey (session, appUniqueIDStr));        } else {            Enumeration outputCacheKeys = outputCache.keys ();            Vector keysToFlush = new Vector();            while (outputCacheKeys.hasMoreElements()) {                String curOutputCacheKey = (String)outputCacheKeys.nextElement();                if (curOutputCacheKey.indexOf (                        JahiaApplicationsDispatchingServletService.CACHE_ID_SEPARATOR +                        appUniqueIDStr) != -1) {                    keysToFlush.add (curOutputCacheKey);                }            }            for (int i=0; i<keysToFlush.size(); i++) {                String curKeyToFlush = (String)keysToFlush.get(i);                outputCache.removeValue (curKeyToFlush);            }        }    }}

⌨️ 快捷键说明

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