📄 jahiaapplicationsdispatchingservletservice.java
字号:
appRequest.getMethod(), appRequest, contextID, fullScreenActivated, inheritJahiaSessionAttributes, jParams); String forceEncoding = null; if (jParams.settings().isUtf8Encoding()) { forceEncoding = "UTF-8"; } if (jParams.getLocale().toString().substring(0, 2).equals("zh")) { forceEncoding = "GBK"; } responseWrapper = new ServletIncludeResponseWrapper(jParams. getResponse(), appRequest.getUniqueIDStr(), appRequest.getURL(), jParams, false, forceEncoding); // requestWrapper.setContextPath(jParams.getRequest().getContextPath() + "/" + CONTEXT_PATH_HEADER + appIDStr + "/"); JahiaConsole.println ("DispatchingServletService", "INCLUDE BEGIN -----"); // Let's now call the servlet and retrieve the result of it's processing if (servletBean.getWebAppType() == ServletBean.JSP_TYPE) { // for JSP's we do a forward to avoid generation of the extra // include parameters to be set internally by the servlet // container. sessionDispatcher.forward(requestWrapper, responseWrapper); } else if (servletBean.getWebAppType() == ServletBean.SERVLET_TYPE) { JahiaConsole.println ("DispatchingServletService", "servletBean is of SERVLET TYPE"); sessionDispatcher.include(requestWrapper, responseWrapper); //sessionDispatcher.forward(requestWrapper, responseWrapper); } JahiaConsole.println ("DispatchingServletService", "INCLUDE END -----"); if (!requestWrapper.isApplicationCacheOn()) { JahiaConsole.println ("DispatchingServletService", "The application deactivated caching itself"); mustCache = false; } cacheExpirationDelay = requestWrapper. getApplicationCacheExpirationDelay(); } catch (ServletException se) { JahiaConsole.printe ("Error in web application", new JahiaException("Can't access application " + appBean.getName(), "Servlet Exception occured in getAppOutput dispatching process ! Message = [" + se + "]", JahiaException.ERROR, JahiaException.APPLICATION_ERROR, se)); JahiaConsole.printe ("Can't access application, ServletException " + se.toString(), se); JahiaConsole.println ("DispatchingServletService", "-----------------------------------------------------------------------"); se.printStackTrace(); JahiaConsole.println ("DispatchingServletService", "-----------------------------------------------------------------------"); return "Error while retrieving application " + appBean.getName(); } catch (IOException ioe) { JahiaConsole.printe ("Error in web application", new JahiaException("Can't access application " + appBean.getName(), "IOException occured in getAppOutput dispatching process !", JahiaException.ERROR, JahiaException.APPLICATION_ERROR, ioe)); JahiaConsole.printe ("Can't access application, IOException " + ioe.toString(), ioe); return "Error while retrieving application " + appBean.getName(); } catch (Throwable t) { JahiaConsole.printe ("Application generated error", t); JahiaConsole.printe ("Error in web application", new JahiaException("JahiaApplicationsDispatchingServletService for app " + appBean.getName(), "Unknown exception occured during dispatching process " + t.getMessage(), JahiaException.WARNING, JahiaException.APPLICATION_ERROR, t)); JahiaConsole.printe ("Can't access application, Exception " + t.toString(), t); return "Error while retrieving application " + appBean.getName(); } //logger.debug("Response=[" + responseWrapper.getStringBuffer() + "]"); //String applicationOutput = "Error while retrieving application " + appBean.getName(); String applicationOutput = null; try { applicationOutput = responseWrapper.getStringBuffer(false); } catch (IOException ioe) { JahiaConsole.printe ("Exception on calling response.getStringBuffer()", ioe); applicationOutput = "IOException while retrieving application " + appBean.getName() + ": " + ioe.getMessage(); return applicationOutput; } // Return the String containing the output of the application. if (mustCache) { if (cacheExpirationDelay != -1) { // for the moment as we don't have an expiration system for the // application output caches, we simply never use it if a // delay has been set. We do however use the expiration mechanism // of the HTML page output cache. flushOutputCacheByAppUniqueID(jParams.getSession(),appUniqueIDStr); // flush the was processed attribute too jParams.getSession().removeAttribute( "org.jahia.services.applications.wasProcessed." + appUniqueIDStr); jParams.setCacheExpirationDelay (cacheExpirationDelay); } else { flushOutputCacheByAppUniqueID(jParams.getSession(),appUniqueIDStr); HttpSession curSession = jParams.getSession(); if (curSession != null && applicationOutput != null) { outputCache.setValue (applicationOutput, buildCacheKey(curSession, appUniqueIDStr) ); } if (applicationOutput == null) { // flush the was processed attribute too jParams.getSession().removeAttribute( "org.jahia.services.applications.wasProcessed." + appUniqueIDStr); } } } else { // let's set the page's cache expiration date jParams.setCacheExpirationDelay(0); flushOutputCacheByAppUniqueID(jParams.getSession(), appUniqueIDStr); // flush the was processed attribute too jParams.getSession().removeAttribute( "org.jahia.services.applications.wasProcessed." + appUniqueIDStr); } if (appRequest.getMethod().equalsIgnoreCase("GET")) { HttpSession curSession = jParams.getSession(); if (curSession != null) { requestCache.setValue (appRequest, buildCacheKey(curSession, appUniqueIDStr)); } } else { JahiaConsole.println ("DispatchingServletService", "POST method, skipping request cache update..."); } return applicationOutput; } /** * This method retrieves the output of an application in the case where we * have no action defined for it. In this case we either previously stored * a request in the cache, or we have to generate a new request since this * is the first time we are calling the request, or no request has been stored * because this feature was deactivated. * @param appID Web application database ID * @param appUniqueIDStr Unique web application ID generated from fieldID and * database ID * @param jParams a Jahia ParamBean object containing the request and response * objects * @return A string containing the output of the web application */ public String getAppOutputNoAction (int appID, String appUniqueIDStr, String contextID, ParamBean jParams, boolean cacheRead, boolean fullScreenActivated) throws JahiaException { String outputResult = ""; // we are in the case were there is no application ID // default behavior : // 1. lookup in cache for output for the current app // 2. if none, generate URL and do request HttpSession curSession = jParams.getSession(); if (cacheRead) { outputResult = (String)outputCache.getValue ( buildCacheKey(curSession, appUniqueIDStr)); } else { outputResult = null; } if (outputResult == null) { // we must now check the request table to know if we can use a // previous request. PersistantServletRequest storedRequest = (PersistantServletRequest)requestCache.getValue ( buildCacheKey(curSession, appUniqueIDStr)); if (storedRequest != null) { // we have found a previous request, let's use it. if (storedRequest.getVisibleStatus() != 0) { JahiaConsole.println ("DispatchingServletService", "Using request stored in cache"); outputResult = dispatchRequest(jParams, storedRequest.getApplicationBean(), storedRequest, storedRequest.getUniqueIDStr(), storedRequest.getURL(), storedRequest.getMethod(), contextID, cacheOutputBoolean, fullScreenActivated); } else { JahiaConsole.println ("DispatchingServletService", "Application has been deactivated"); JahiaConsole.printe ("Error in web application", new JahiaException("JahiaApplicationsDispatchingServletService", "Application " + appID + " has been deactivated", JahiaException.APPLICATION_ERROR, JahiaException.WARNING)); return "Application has been deactivated"; } } else { // let's generate an URL since we never had any. we use the application's default servlet JahiaConsole.println ("DispatchingServletService", "Generating new URL for request"); ApplicationBean appBean = ServicesRegistry.getInstance() .getJahiaApplicationsManagerService() .getApplication(appID); if (appBean == null) { String errorMsg = "AppID : " + appID; JahiaConsole.printe ("Error in web application", new JahiaException("Cannot retrieve application definition !", errorMsg, JahiaException.DATABASE_ERROR, JahiaException.ERROR)); return "The requested application is not available"; } // visibleStatusCache.put(new Integer(appID), new Integer(appBean.getVisibleStatus())); // let's update visible status cache if (curSession != null) { curSession.setAttribute(Integer.toString(appID), new Integer(appBean.getVisibleStatus())); } if (appBean.getVisibleStatus() == 0) { JahiaConsole.println ("DispatchingServletService", "Application has been deactivated"); JahiaConsole.printe ("Error in web application", new JahiaException("JahiaApplicationsDispatchingServletService", "Application " + appID + " has been deactivated", JahiaException.APPLICATION_ERROR, JahiaException.WARNING)); return "Application has been deactivated"; } ApplicationContext appContext = ServicesRegistry.getInstance() . getJahiaApplicationContextService() .getApplicationContext(appBean. getContext()); // get the default servlet if any String servletName = appContext.findServletMapping("/"); ServletBean servletBean = null; if (servletName != null) { servletBean = appContext.getServlet(servletName); if (servletBean != null) { servletBean.setUrlMappingPattern("/"); } } else { // no default servlet defined, we look for available welcome files // actually we get the first if any if (appContext.getWelcomeFiles().size() > 0) { String welcomefile = (String) appContext. getWelcomeFiles().get(0); String resourceFile = welcomefile; if (!resourceFile.startsWith("/")) { resourceFile = "/" + resourceFile;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -