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

📄 contextfilter.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            if (debug) Debug.log("[Request]: " + httpRequest.getRequestURI(), module);            String requestPath = httpRequest.getServletPath();            if (requestPath == null) requestPath = "";            if (requestPath.lastIndexOf("/") > 0) {                if (requestPath.indexOf("/") == 0) {                    requestPath = "/" + requestPath.substring(1, requestPath.indexOf("/", 1));                } else {                    requestPath = requestPath.substring(1, requestPath.indexOf("/"));                }            }            String requestInfo = httpRequest.getServletPath();            if (requestInfo == null) requestInfo = "";            if (requestInfo.lastIndexOf("/") >= 0) {                requestInfo = requestInfo.substring(0, requestInfo.lastIndexOf("/")) + "/*";            }            StringBuffer contextUriBuffer = new StringBuffer();            if (httpRequest.getContextPath() != null) {                contextUriBuffer.append(httpRequest.getContextPath());            }            if (httpRequest.getServletPath() != null) {                contextUriBuffer.append(httpRequest.getServletPath());            }            if (httpRequest.getPathInfo() != null) {                contextUriBuffer.append(httpRequest.getPathInfo());            }            String contextUri = contextUriBuffer.toString();            // Verbose Debugging            if (Debug.verboseOn()) {                for (int i = 0; i < allowList.size(); i++) {                    Debug.logVerbose("[Allow]: " + allowList.get(i), module);                }                Debug.logVerbose("[Request path]: " + requestPath, module);                Debug.logVerbose("[Request info]: " + requestInfo, module);                Debug.logVerbose("[Servlet path]: " + httpRequest.getServletPath(), module);            }            // check to make sure the requested url is allowed            if (!allowList.contains(requestPath) && !allowList.contains(requestInfo) && !allowList.contains(httpRequest.getServletPath())) {                String filterMessage = "[Filtered request]: " + contextUri;                if (redirectPath == null) {                    int error = 404;                    try {                        error = Integer.parseInt(errorCode);                    } catch (NumberFormatException nfe) {                        Debug.logWarning(nfe, "Error code specified would not parse to Integer : " + errorCode, module);                    }                    filterMessage = filterMessage + " (" + error + ")";                    wrapper.sendError(error, contextUri);                } else {                    filterMessage = filterMessage + " (" + redirectPath + ")";                    if (!redirectPath.toLowerCase().startsWith("http")) {                        redirectPath = httpRequest.getContextPath() + redirectPath;                    }                    wrapper.sendRedirect(redirectPath);                }                Debug.logWarning(filterMessage, module);                return;            }        }        // we're done checking; continue on        chain.doFilter(request, response);    }    /**     * @see javax.servlet.Filter#destroy()     */    public void destroy() {        getDispatcher().deregister();        config = null;    }    protected LocalDispatcher getDispatcher() {        LocalDispatcher dispatcher = (LocalDispatcher) config.getServletContext().getAttribute("dispatcher");        if (dispatcher == null) {            GenericDelegator delegator = getDelegator();            if (delegator == null) {                Debug.logError("[ContextFilter.init] ERROR: delegator not defined.", module);                return null;            }            Collection readers = null;            String readerFiles = config.getServletContext().getInitParameter("serviceReaderUrls");            if (readerFiles != null) {                readers = new ArrayList();                List readerList = StringUtil.split(readerFiles, ";");                Iterator i = readerList.iterator();                while (i.hasNext()) {                    try {                        String name = (String) i.next();                        URL readerURL = config.getServletContext().getResource(name);                        if (readerURL != null)                            readers.add(readerURL);                    } catch (NullPointerException npe) {                        Debug.logInfo(npe, "[ContextFilter.init] ERROR: Null pointer exception thrown.", module);                    } catch (MalformedURLException e) {                        Debug.logError(e, "[ContextFilter.init] ERROR: cannot get URL from String.", module);                    }                }            }            // get the unique name of this dispatcher            String dispatcherName = config.getServletContext().getInitParameter("localDispatcherName");            if (dispatcherName == null)                Debug.logError("No localDispatcherName specified in the web.xml file", module);            dispatcher = new WebAppDispatcher(dispatcherName, delegator, readers);            config.getServletContext().setAttribute("dispatcher", dispatcher);            if (dispatcher == null)                Debug.logError("[ContextFilter.init] ERROR: dispatcher could not be initialized.", module);        }        return dispatcher;    }    protected GenericDelegator getDelegator() {        GenericDelegator delegator = (GenericDelegator) config.getServletContext().getAttribute("delegator");        if (delegator == null) {            String delegatorName = config.getServletContext().getInitParameter("entityDelegatorName");            if (delegatorName == null || delegatorName.length() <= 0) {                delegatorName = "default";            }            if (Debug.infoOn()) Debug.logInfo("[ContextFilter.init] Getting Entity Engine Delegator with delegator name " + delegatorName, module);            delegator = GenericDelegator.getGenericDelegator(delegatorName);            config.getServletContext().setAttribute("delegator", delegator);            if (delegator == null) {                Debug.logError("[ContextFilter.init] ERROR: delegator factory returned null for delegatorName \"" + delegatorName + "\"", module);            }        }        return delegator;    }    protected Security getSecurity() {        Security security = (Security) config.getServletContext().getAttribute("security");        if (security == null) {            GenericDelegator delegator = (GenericDelegator) config.getServletContext().getAttribute("delegator");            if (delegator != null) {                try {                    security = SecurityFactory.getInstance(delegator);                } catch (SecurityConfigurationException e) {                    Debug.logError(e, "[ServiceDispatcher.init] : No instance of security imeplemtation found.", module);                }            }            config.getServletContext().setAttribute("security", security);            if (security == null) {                Debug.logError("[ContextFilter.init] ERROR: security create failed.", module);            }        }        return security;    }    protected void putAllInitParametersInAttributes() {        Enumeration initParamEnum = config.getServletContext().getInitParameterNames();        while (initParamEnum.hasMoreElements()) {            String initParamName = (String) initParamEnum.nextElement();            String initParamValue = config.getServletContext().getInitParameter(initParamName);            if (Debug.infoOn()) Debug.logInfo("Adding web.xml context-param to application attribute with name [" + initParamName + "] and value [" + initParamValue + "]", module);            config.getServletContext().setAttribute(initParamName, initParamValue);        }    }    protected String getServerId() {        String serverId = (String) config.getServletContext().getAttribute("_serverId");        if (serverId == null) {            serverId = config.getServletContext().getInitParameter("ofbizServerName");            config.getServletContext().setAttribute("_serverId", serverId);        }        return serverId;    }    protected boolean getContainers() throws ServletException {        try {            ContainerLoader.loadContainers(CONTAINER_CONFIG, null);        } catch (StartupException e) {            Debug.logError(e, module);            throw new ServletException("Unable to load containers; cannot start ContextFilter");        }        return true;    }}

⌨️ 快捷键说明

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