📄 controlservlet.java
字号:
/* * $Id: ControlServlet.java 5462 2005-08-05 18:35:48Z jonesde $ * * Copyright (c) 2001-2003 The Open For Business Project - www.ofbiz.org * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * THE USE OR OTHER DEALINGS IN THE SOFTWARE. */package org.ofbiz.webapp.control;import javax.servlet.RequestDispatcher;import javax.servlet.ServletConfig;import javax.servlet.ServletContext;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import javax.servlet.http.HttpSession;import java.io.IOException;import java.util.Enumeration;import com.ibm.bsf.BSFManager;import org.ofbiz.base.util.Debug;import org.ofbiz.base.util.UtilHttp;import org.ofbiz.base.util.UtilJ2eeCompat;import org.ofbiz.base.util.UtilTimer;import org.ofbiz.base.util.UtilValidate;import org.ofbiz.entity.GenericDelegator;import org.ofbiz.entity.GenericValue;import org.ofbiz.entity.transaction.GenericTransactionException;import org.ofbiz.entity.transaction.TransactionUtil;import org.ofbiz.security.Security;import org.ofbiz.service.LocalDispatcher;import org.ofbiz.webapp.stats.ServerHitBin;/** * ControlServlet.java - Master servlet for the web application. * * @author <a href="mailto:jaz@ofbiz.org">Andy Zeneski</a> * @author <a href="mailto:jonesde@ofbiz.org">David E. Jones</a> * @version $Rev: 5462 $ * @since 2.0 */public class ControlServlet extends HttpServlet { public static final String module = ControlServlet.class.getName(); public ControlServlet() { super(); } /** * @see javax.servlet.Servlet#init(javax.servlet.ServletConfig) */ public void init(ServletConfig config) throws ServletException { super.init(config); if (Debug.infoOn()) { Debug.logInfo("[ControlServlet.init] Loading Control Servlet mounted on path " + config.getServletContext().getRealPath("/"), module); } // configure custom BSF engines configureBsf(); // initialize the request handler getRequestHandler(); } /** * @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) */ public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request, response); } /** * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) */ public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // setup DEFAULT chararcter encoding and content type, this will be overridden in the RequestHandler for view rendering String charset = getServletContext().getInitParameter("charset"); if (charset == null || charset.length() == 0) charset = request.getCharacterEncoding(); if (charset == null || charset.length() == 0) charset = "UTF-8"; Debug.logInfo("The character encoding of the request is: [" + request.getCharacterEncoding() + "]. The character encoding we will use for the request and response is: [" + charset + "]", module); if (!"none".equals(charset)) { request.setCharacterEncoding(charset); } // setup content type String contentType = "text/html"; if (charset.length() > 0 && !"none".equals(charset)) { response.setContentType(contentType + "; charset=" + charset); response.setCharacterEncoding(charset); } else { response.setContentType(contentType); } long requestStartTime = System.currentTimeMillis(); HttpSession session = request.getSession(); GenericValue userLogin = (GenericValue) session.getAttribute("userLogin"); //Debug.log("Cert Chain: " + request.getAttribute("javax.servlet.request.X509Certificate"), module); // workaraound if we are in the root webapp String webappName = UtilHttp.getApplicationName(request); String rname = ""; if (request.getPathInfo() != null) { rname = request.getPathInfo().substring(1); } if (rname.indexOf('/') > 0) { rname = rname.substring(0, rname.indexOf('/')); } UtilTimer timer = null; if (Debug.timingOn()) { timer = new UtilTimer(); timer.setLog(true); timer.timerString("[" + rname + "] Servlet Starting, doing setup", module); } // Setup the CONTROL_PATH for JSP dispatching. request.setAttribute("_CONTROL_PATH_", request.getContextPath() + request.getServletPath()); if (Debug.verboseOn()) Debug.logVerbose("Control Path: " + request.getAttribute("_CONTROL_PATH_"), module); // for convenience, and necessity with event handlers, make security and delegator available in the request: // try to get it from the session first so that we can have a delegator/dispatcher/security for a certain user if desired GenericDelegator delegator = null; String delegatorName = (String) session.getAttribute("delegatorName"); if (UtilValidate.isNotEmpty(delegatorName)) { delegator = GenericDelegator.getGenericDelegator(delegatorName); } if (delegator == null) { delegator = (GenericDelegator) getServletContext().getAttribute("delegator"); } if (delegator == null) { Debug.logError("[ControlServlet] ERROR: delegator not found in ServletContext", module); } else { request.setAttribute("delegator", delegator); // always put this in the session too so that session events can use the delegator session.setAttribute("delegatorName", delegator.getDelegatorName()); } LocalDispatcher dispatcher = (LocalDispatcher) session.getAttribute("dispatcher"); if (dispatcher == null) { dispatcher = (LocalDispatcher) getServletContext().getAttribute("dispatcher"); } if (dispatcher == null) { Debug.logError("[ControlServlet] ERROR: dispatcher not found in ServletContext", module); } request.setAttribute("dispatcher", dispatcher);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -