📄 jahiaapplicationsdispatchingservletservice.java
字号:
} servletBean = new ServletBean(ServletBean.JSP_TYPE, appBean.getName(), welcomefile, resourceFile, appBean.getContext(), ""); } } // NK : I added this for application without any servlet mapping information // if (servletBean == null) { try { servletBean = (ServletBean) appContext.getServlets(). values().iterator().next(); } catch (Throwable t) { } } if (servletBean == null) { JahiaConsole.printe ("Error in web application", new JahiaException("Neither default servlet or welcome files found !", "Neither default servlet or welcome files found !", JahiaException.APPLICATION_ERROR, JahiaException.ERROR)); return "Neither default servlet or welcome files found !"; } if ( (appBean.getJahiaID() != jParams.getSiteID()) && !appBean.isShared() && ServicesRegistry.getInstance().getAppsShareService(). getShare(jParams.getSite(), appBean) == null) { JahiaConsole.println ("DispatchingServletService", "You cannot access the application"); JahiaConsole.printe ("Warning in web application", new JahiaException("JahiaApplicationsDispatchingServletService", "Site has not share access with the app " + appID, JahiaException.APPLICATION_ERROR, JahiaException.WARNING)); return "Application has been deactivated"; } String URLPort; if (jParams.getRequest().getServerPort() == 80) { URLPort = ""; } else { URLPort = ":" + Integer.toString(jParams.getRequest().getServerPort()); } String context; if (appBean.getContext().equals("/")) { context = ""; } else { context = appBean.getContext(); } String URLPath = context; JahiaConsole.println ("DispatchingServletService", "Using URLPath = " + URLPath); outputResult = dispatchRequest(jParams, appBean, servletBean, appUniqueIDStr, URLPath, "GET", contextID, cacheOutputBoolean, fullScreenActivated); } } else { JahiaConsole.println ("DispatchingServletService", "Retrieving application output from cache."); // Integer visibleStatus = (Integer) visibleStatusCache.get(new Integer(appID)); Integer visibleStatus = null; if (curSession != null) { visibleStatus = (Integer) curSession.getAttribute(Integer. toString(appID)); } if (visibleStatus != null) { if (visibleStatus.intValue() == 0) { JahiaConsole.printe ("Warning", new JahiaException("JahiaApplicationsDispatchingServletService", "Application " + appID + " has been deactivated", JahiaException.APPLICATION_ERROR, JahiaException.WARNING)); return "Application has been deactivated"; } } } return outputResult; } /** * Retrieves the output of a servlet in a String object * * In order to avoid namespaces conflict, applications should be in seperate contexts of a servlet container. * This way session information and object will be automatically local to that context. * * FIXME : still to be done : request wrapper, context wrapper (in case we need to change session info), * We still have to decide what can of request we send objects that aren't concerned by the current * request. One way to do it would be to clone the initial request and store it in a hashtable, then * update it when a real request come to the concerned app. * * @param fieldID used to generate the context id for the app and build the unique id string * @param appIDStr String containing the application ID, to be used to look it up in the application definition database * @param jParams Bean containg the request and response objects * @return String containing the output generated by the application. */ public String getAppOutput (int fieldID, String appIDStr, ParamBean jParams) throws JahiaException { String outputResult = ""; String fieldIDStr = Integer.toString(fieldID); String appUniqueIDStr = fieldIDStr + APP_ID_SEPARATOR + appIDStr; String contextID = fieldIDStr; boolean cacheRead = true; if ( (ParamBean.CACHE_OFF.equals(jParams.getOriginalCacheStatus())) || (ParamBean.CACHE_OFFONCE.equals(jParams.getOriginalCacheStatus())) || (ParamBean.CACHE_ONLYUPDATE.equals(jParams.getOriginalCacheStatus()))) { JahiaConsole.println ("DispatchingServletService", "Application cache deactivated because of request page cache status : " + jParams.getOriginalCacheStatus()); cacheRead = false; } boolean fullScreenActivated = false; JahiaConsole.println ("DispatchingServletService", "Requested Application is [" + appUniqueIDStr + "]"); if (jParams == null) { return null; } HttpSession session = jParams.getSession(); Boolean wasProcessed = (Boolean) session.getAttribute( "org.jahia.services.applications.wasProcessed." + appUniqueIDStr); if (wasProcessed != null) { // this means the application has ALREADY been processed during this request, we should just return the output cache // if we have one, otherwise this means we had an error previously. if (wasProcessed.booleanValue()) { JahiaConsole.println ("DispatchingServletService", "Application was already accessed during this request, will only output cache again or error if we cannot find it !"); outputResult = (String) outputCache.getValue ( buildCacheKey(session, appUniqueIDStr)); if (outputResult == null) { JahiaConsole.printe ("Warning", new JahiaException("JahiaApplicationsDispatchingServletService.getAppOutput", "Application " + appUniqueIDStr + " cannot be accessed again in the request !", JahiaException.APPLICATION_ERROR, JahiaException.WARNING)); outputResult = "Error accessing application " + appUniqueIDStr + ", has the session expired ?"; } return outputResult; } else { JahiaConsole.println ("DispatchingServletService", "Invalid attribute in request : org.jahia.services.applications.wasProcessed." + appUniqueIDStr + " should NEVER become false !"); } } else { session.setAttribute( "org.jahia.services.applications.wasProcessed." + appUniqueIDStr, new Boolean(true)); } int appID = 0; try { appID = Integer.parseInt(appIDStr); } catch (NumberFormatException nfe) { JahiaConsole.printe ( "Error while parsing application id to convert to integer", nfe); return ""; } String fullScreenStr = jParams.getRequest().getParameter("maximize"); if (fullScreenStr == null) { fullScreenStr = jParams.getRequest().getParameter("fullscreen"); } int fullScreenContainerID = -1; int fullScreenFieldID = -1; if (fullScreenStr != null) { try { int seperatorPos = fullScreenStr.indexOf("_"); String fullScreenContainerIDStr = fullScreenStr.substring(0, seperatorPos); String fullScreenFieldIDStr = fullScreenStr.substring( seperatorPos + 1, fullScreenStr.length()); fullScreenContainerID = Integer.parseInt( fullScreenContainerIDStr); fullScreenFieldID = Integer.parseInt(fullScreenFieldIDStr); } catch (NumberFormatException nfe) { } } else { Integer sessionFullScreenFieldID = (Integer) session.getAttribute( "org.jahia.fullscreen"); if (sessionFullScreenFieldID != null) { if (sessionFullScreenFieldID.intValue() == fieldID) { // we found a full screen mode for this field but we don't have it in the URL, let's deactivate full screen mode. JahiaConsole.println ("DispatchingServletService", "Restoring size, not reading from cache"); session.removeAttribute("org.jahia.fullscreen"); fullScreenActivated = false; cacheRead = false; } } } if (fullScreenFieldID != -1) { if (fullScreenFieldID == fieldID) { JahiaConsole.println ("DispatchingServletService", "Fullscreen mode detected for this field, not reading from cache..."); session.setAttribute("org.jahia.fullscreen", new Integer(fullScreenFieldID)); cacheRead = false; fullScreenActivated = true; } } // Now let's check the request URL to see if the target application is this one or not. String queryStr = jParams.getRequest().getParameter("appid"); // logger.debug("queryStr=[" + queryStr + "]"); if (queryStr != null) { if (queryStr.equals(appUniqueIDStr)) { String appURL = jParams.getRequest().getParameter("appparams"); JahiaConsole.println ("DispatchingServletService", "Action detected : appParams=[" + appURL + "]"); // This is indeed the targeted application ApplicationBean appBean = ServicesRegistry.getInstance(). getJahiaApplicationsManagerService(). getApplication(appID); if (appBean == null) { /* String errorMsg = "AppID : " + appID; throw new JahiaException ( "Cannot retrieve application definition !", errorMsg, JahiaException.DATABASE_ERROR, JahiaException.ERROR); */ return "The referred application is not available"; } if (appBean.getVisibleStatus() == 0) { JahiaConsole.printe ("Application has been deactivated", new JahiaException("JahiaApplicationsDispatchingServletService", "Application " + appID + " has been deactivated", JahiaException.APPLICATION_ERROR, JahiaException.WARNING)); return "Application has been deactivated"; } ServletBean servletBean = getServletBean(appBean, appURL); HttpSession curSession = jParams.getSession(); if (curSession != null) { curSession.setAttribute(Integer.toString(appID), new Integer(appBean. getVisibleStatus())); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -