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

📄 requesthandler.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        String charset = getServletContext().getInitParameter("charset");        if (charset == null || charset.length() == 0) charset = req.getCharacterEncoding();        if (charset == null || charset.length() == 0) charset = "UTF-8";        String viewCharset = requestManager.getViewEncoding(view);        //NOTE: if the viewCharset is "none" then no charset will be used        if (viewCharset != null && viewCharset.length() > 0) charset = viewCharset;        if (!"none".equals(charset)) {            try {                req.setCharacterEncoding(charset);            } catch (UnsupportedEncodingException e) {                throw new RequestHandlerException("Could not set character encoding to " + charset, e);            } catch (IllegalStateException e) {                Debug.logInfo(e, "Could not set character encoding to " + charset + ", something has probably already committed the stream", module);            }        }        // setup content type        String contentType = "text/html";        String viewContentType = requestManager.getViewContentType(view);        if (viewContentType != null && viewContentType.length() > 0) contentType = viewContentType;        if (charset.length() > 0 && !"none".equals(charset)) {            resp.setContentType(contentType + "; charset=" + charset);        } else {            resp.setContentType(contentType);        }        if (Debug.verboseOn()) Debug.logVerbose("The ContentType for the " + view + " view is: " + contentType, module);        try {            if (Debug.verboseOn()) Debug.logVerbose("Rendering view [" + nextPage + "] of type [" + viewType + "]", module);            ViewHandler vh = viewFactory.getViewHandler(viewType);            vh.render(view, nextPage, requestManager.getViewInfo(view), contentType, charset, req, resp);        } catch (ViewHandlerException e) {            Throwable throwable = e.getNested() != null ? e.getNested() : e;            throw new RequestHandlerException(e.getNonNestedMessage(), throwable);        }        // before getting the view generation time flush the response output to get more consistent results        try {            resp.flushBuffer();        } catch (java.io.IOException e) {            throw new RequestHandlerException("Error flushing response buffer", e);        }        String vname = (String) req.getAttribute("_CURRENT_VIEW_");        if (vname != null) {            ServerHitBin.countView(cname + "." + vname, req, viewStartTime,                System.currentTimeMillis() - viewStartTime, userLogin, delegator);        }    }    public static String getDefaultServerRootUrl(HttpServletRequest request, boolean secure) {        String httpsPort = UtilProperties.getPropertyValue("url.properties", "port.https", "443");        String httpsServer = UtilProperties.getPropertyValue("url.properties", "force.https.host");        String httpPort = UtilProperties.getPropertyValue("url.properties", "port.http", "80");        String httpServer = UtilProperties.getPropertyValue("url.properties", "force.http.host");        boolean useHttps = UtilProperties.propertyValueEqualsIgnoreCase("url.properties", "port.https.enabled", "Y");        StringBuffer newURL = new StringBuffer();        if (secure && useHttps) {            String server = httpsServer;            if (server == null || server.length() == 0) {                server = request.getServerName();            }            newURL.append("https://");            newURL.append(server);            if (!httpsPort.equals("443")) {                newURL.append(":").append(httpsPort);            }        } else {            String server = httpServer;            if (server == null || server.length() == 0) {                server = request.getServerName();            }            newURL.append("http://");            newURL.append(server);            if (!httpPort.equals("80")) {                newURL.append(":").append(httpPort);            }        }        return newURL.toString();    }    public String makeLinkWithQueryString(HttpServletRequest request, HttpServletResponse response, String url) {        String initialLink = this.makeLink(request, response, url);        String queryString = this.makeQueryString(request);        return initialLink + queryString;    }    public String makeLink(HttpServletRequest request, HttpServletResponse response, String url) {        return makeLink(request, response, url, false, false, true);    }    public String makeLink(HttpServletRequest request, HttpServletResponse response, String url, boolean fullPath, boolean secure, boolean encode) {        GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator");        String webSiteId = WebSiteWorker.getWebSiteId(request);        String httpsPort = null;        String httpsServer = null;        String httpPort = null;        String httpServer = null;        Boolean enableHttps = null;        // load the properties from the website entity        GenericValue webSite = null;        if (webSiteId != null) {            try {                webSite = delegator.findByPrimaryKeyCache("WebSite", UtilMisc.toMap("webSiteId", webSiteId));                if (webSite != null) {                    httpsPort = webSite.getString("httpsPort");                    httpsServer = webSite.getString("httpsHost");                    httpPort = webSite.getString("httpPort");                    httpServer = webSite.getString("httpHost");                    enableHttps = webSite.getBoolean("enableHttps");                }            } catch (GenericEntityException e) {                Debug.logWarning(e, "Problems with WebSite entity; using global defaults", module);            }        }        // fill in any missing properties with fields from the global file        if (UtilValidate.isEmpty(httpsPort)) {            httpsPort = UtilProperties.getPropertyValue("url.properties", "port.https", "443");        }        if (UtilValidate.isEmpty(httpServer)) {            httpsServer = UtilProperties.getPropertyValue("url.properties", "force.https.host");        }        if (UtilValidate.isEmpty(httpPort)) {            httpPort = UtilProperties.getPropertyValue("url.properties", "port.http", "80");        }        if (UtilValidate.isEmpty(httpServer)) {            httpServer = UtilProperties.getPropertyValue("url.properties", "force.http.host");        }        if (enableHttps == null) {            enableHttps = new Boolean(UtilProperties.propertyValueEqualsIgnoreCase("url.properties", "port.https.enabled", "Y"));        }        // create the path the the control servlet        String controlPath = (String) request.getAttribute("_CONTROL_PATH_");        String requestUri = RequestHandler.getRequestUri(url);        StringBuffer newURL = new StringBuffer();        boolean useHttps = enableHttps.booleanValue();        boolean didFullSecure = false;        boolean didFullStandard = false;        if (useHttps || fullPath || secure) {            if (secure || (useHttps && requestManager.requiresHttps(requestUri) && !request.isSecure())) {                String server = httpsServer;                if (server == null || server.length() == 0) {                    server = request.getServerName();                }                newURL.append("https://");                newURL.append(server);                if (!httpsPort.equals("443")) {                    newURL.append(":").append(httpsPort);                }                didFullSecure = true;            } else if (fullPath || (useHttps && !requestManager.requiresHttps(requestUri) && request.isSecure())) {                String server = httpServer;                if (server == null || server.length() == 0) {                    server = request.getServerName();                }                newURL.append("http://");                newURL.append(server);                if (!httpPort.equals("80")) {                    newURL.append(":" + httpPort);                }                didFullStandard = true;            }        }        newURL.append(controlPath);        // now add the actual passed url, but if it doesn't start with a / add one first        if (!url.startsWith("/")) {            newURL.append("/");        }        newURL.append(url);        String encodedUrl = null;        if (encode) {            boolean forceManualJsessionid = false;            // if this isn't a secure page, but we made a secure URL, make sure we manually add the jsessionid since the response.encodeURL won't do that            if (!request.isSecure() && didFullSecure) {                forceManualJsessionid = true;            }            // if this is a secure page, but we made a standard URL, make sure we manually add the jsessionid since the response.encodeURL won't do that            if (request.isSecure() && didFullStandard) {                forceManualJsessionid = true;            }            if (response != null && !forceManualJsessionid) {                encodedUrl = response.encodeURL(newURL.toString());            } else {                String sessionId = ";jsessionid=" + request.getSession().getId();                // this should be inserted just after the "?" for the parameters, if there is one, or at the end of the string                int questionIndex = newURL.indexOf("?");                if (questionIndex == -1) {                    newURL.append(sessionId);                } else {                    newURL.insert(questionIndex, sessionId);                }                encodedUrl = newURL.toString();            }        } else {            encodedUrl = newURL.toString();        }        //if (encodedUrl.indexOf("null") > 0) {            //Debug.logError("in makeLink, controlPath:" + controlPath + " url:" + url, "");            //throw new RuntimeException("in makeLink, controlPath:" + controlPath + " url:" + url);        //}        //Debug.logInfo("Making URL, encode=" + encode + " for URL: " + newURL + "\n encodedUrl: " + encodedUrl, module);        return encodedUrl;    }    public static String makeUrl(HttpServletRequest request, HttpServletResponse response, String url) {        return makeUrl(request, response, url, false, false, false);    }    public static String makeUrl(HttpServletRequest request, HttpServletResponse response, String url, boolean fullPath, boolean secure, boolean encode) {        ServletContext ctx = (ServletContext) request.getAttribute("servletContext");        RequestHandler rh = (RequestHandler) ctx.getAttribute("_REQUEST_HANDLER_");        return rh.makeLink(request, response, url, fullPath, secure, encode);    }    public void runAfterLoginEvents(HttpServletRequest request, HttpServletResponse response) {        List afterLoginEvents = requestManager.getAfterLoginEventList();        if (afterLoginEvents != null) {            Iterator i = afterLoginEvents.iterator();            while (i.hasNext()) {                Map eventMap = (Map) i.next();                String eType = (String) eventMap.get(ConfigXMLReader.EVENT_TYPE);                String ePath = (String) eventMap.get(ConfigXMLReader.EVENT_PATH);                String eMeth = (String) eventMap.get(ConfigXMLReader.EVENT_METHOD);                try {                    String returnString = this.runEvent(request, response, eType, ePath, eMeth);                    if (returnString != null && !returnString.equalsIgnoreCase("success")) {                        throw new EventHandlerException("Pre-Processor event did not return 'success'.");                    }                } catch (EventHandlerException e) {                    Debug.logError(e, module);                }            }        }    }    public void runBeforeLogoutEvents(HttpServletRequest request, HttpServletResponse response) {        List beforeLogoutEvents = requestManager.getBeforeLogoutEventList();        if (beforeLogoutEvents != null) {            Iterator i = beforeLogoutEvents.iterator();            while (i.hasNext()) {                Map eventMap = (Map) i.next();                String eType = (String) eventMap.get(ConfigXMLReader.EVENT_TYPE);                String ePath = (String) eventMap.get(ConfigXMLReader.EVENT_PATH);                String eMeth = (String) eventMap.get(ConfigXMLReader.EVENT_METHOD);                try {                    String returnString = this.runEvent(request, response, eType, ePath, eMeth);                    if (returnString != null && !returnString.equalsIgnoreCase("success")) {                        throw new EventHandlerException("Pre-Processor event did not return 'success'.");                    }                } catch (EventHandlerException e) {                    Debug.logError(e, module);                }            }        }    }}

⌨️ 快捷键说明

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