📄 opencmshttpservlet.java
字号:
/*
* File : $Source: /usr/local/cvs/opencms/src/com/opencms/core/Attic/OpenCmsHttpServlet.java,v $
* Date : $Date: 2003/04/25 07:40:20 $
* Version: $Revision: 1.47 $
*
* This library is part of OpenCms -
* the Open Source Content Mananagement System
*
* Copyright (C) 2001 The OpenCms Group
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* For further information about OpenCms, please see the
* OpenCms Website: http://www.opencms.org
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package com.opencms.core;
import com.opencms.boot.CmsBase;
import com.opencms.boot.CmsMain;
import com.opencms.boot.I_CmsLogChannels;
import com.opencms.file.CmsFile;
import com.opencms.file.CmsObject;
import com.opencms.util.Utils;
import java.io.IOException;
import java.util.Date;
import java.util.Hashtable;
import java.util.Properties;
import java.util.StringTokenizer;
import javax.servlet.ServletConfig;
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 source.org.apache.java.util.Configurations;
import source.org.apache.java.util.ExtendedProperties;
/**
* This the main servlet of the OpenCms system.<p>
*
* From here, all other operations are invoked.
* Any incoming request is handled in multiple steps:
*
* <ol><li>The requesting user is authenticated and a CmsObject with the user information
* is created. The CmsObject is used to access all functions of OpenCms, limited by
* the authenticated users permissions. If the user is not identified, it is set to the default (guest)
* user.</li>
*
* <li>The requested document is loaded into OpenCms and depending on its type
* (and the users persmissions to display or modify it),
* it is send to one of the OpenCms launchers do be processed.</li>
*
* <li>
* The loaded launcher will then decide what to do with the contents of the
* requested document. In case of an XMLTemplate the template mechanism will
* be started, in case of a JSP the JSP handling mechanism is invoked,
* in case of an image (or other static file) this will simply be returned etc.
* </li></ol>
*
* @author Michael Emmerich
* @author Alexander Kandzior (a.kandzior@alkacon.com)
*
* @version $Revision: 1.47 $ $Date: 2003/04/25 07:40:20 $
*/
public class OpenCmsHttpServlet extends HttpServlet implements I_CmsConstants,I_CmsLogChannels {
/**
* The name of the redirect entry in the configuration file.
*/
static final String C_PROPERTY_REDIRECT = "redirect";
/**
* The name of the redirect location entry in the configuration file.
*/
static final String C_PROPERTY_REDIRECTLOCATION = "redirectlocation";
/**
* The configuration for the OpenCms servlet.
*/
private Configurations m_configurations;
/**
* The session storage for all active users.
*/
private CmsCoreSession m_sessionStorage;
/**
* The reference to the OpenCms system.
*/
private OpenCms m_opencms;
/**
* Storage for the clusterurl.
*/
private String m_clusterurl = null;
/**
* Flag to indicate if basic or form based authentication is used.
*/
private boolean m_UseBasicAuthentication;
/**
* URI of the authentication form (read from properties).
*/
private String m_AuthenticationFormURI;
/**
* Flag for debugging.
*/
private static final boolean DEBUG = false;
/**
* Prefix for error messages for initialization errors.
*/
private static final String C_ERRORMSG = "OpenCms initialization error!\n\n";
/**
* Prints the OpenCms copyright information to all log-files.<p>
*/
private void printCopyrightInformation() {
String copy[] = C_COPYRIGHT;
// log to error-stream
System.err.println("\n\nStarting OpenCms, version " + A_OpenCms.getVersionName());
for(int i = 0;i < copy.length;i++) {
System.err.println(copy[i]);
}
// log with opencms-logger
if(C_LOGGING && A_OpenCms.isLogging(C_OPENCMS_INIT)) {
A_OpenCms.log(C_OPENCMS_INIT, ". OpenCms version " + A_OpenCms.getVersionName());
for(int i = 0;i < copy.length;i++) {
A_OpenCms.log(C_OPENCMS_INIT, ". " + copy[i]);
}
}
}
/**
* Throws a servlet exception that is also logged and written to the error output console.<p>
*
* @param cause the original Exception
* @throws ServletException the <code>cause</code> parameter
*/
private void throwInitException(ServletException cause) throws ServletException {
String message = cause.getMessage();
if (message == null) message = cause.toString();
System.err.println("\n--------------------\nCritical error during OpenCms servlet init phase:\n" + message);
System.err.println("Giving up, unable to start OpenCms.\n--------------------");
if(C_LOGGING && A_OpenCms.isLogging(C_OPENCMS_CRITICAL)) {
A_OpenCms.log(C_OPENCMS_CRITICAL, message);
}
throw cause;
}
/**
* Initialization of the OpenCms servlet (overloaded Servlet API method).<p>
*
* The connection information for the database is read
* from the <code>opencms.properties</code> configuration file and all
* resource brokers are initialized via the initalizer,
* which usually will be an instance of a <code>OpenCms</code> class.
*
* @param config configuration of OpenCms from <code>web.xml</code>
* @throws ServletException when sevlet initalization fails
*/
public void init(ServletConfig config) throws ServletException {
super.init(config);
A_OpenCms.initVersion(this);
// Check for OpenCms home (base) directory path
String base = config.getInitParameter("opencms.home");
if (DEBUG) System.err.println("BASE: " + config.getServletContext().getRealPath("/"));
if (DEBUG) System.err.println("BASE2: " + System.getProperty("user.dir"));
if(base == null || "".equals(base)) {
if (DEBUG) System.err.println("No OpenCms home folder given. Trying to guess...");
base = CmsMain.searchBaseFolder(config.getServletContext().getRealPath("/"));
if(base == null || "".equals(base)) {
throwInitException(new ServletException(C_ERRORMSG + "OpenCms base folder could not be guessed. Please define init parameter \"opencms.home\" in servlet engine configuration.\n\n"));
}
}
base = CmsBase.setBasePath(base);
String logFile;
ExtendedProperties extendedProperties = null;
// Collect the configurations
try {
extendedProperties = new ExtendedProperties(CmsBase.getPropertiesPath(true));
}
catch(Exception e) {
throwInitException(new ServletException(C_ERRORMSG + "Trouble reading property file " + CmsBase.getPropertiesPath(true) + ".\n\n", e));
}
// Change path to log file, if given path is not absolute
logFile = (String)extendedProperties.get("log.file");
if(logFile != null) {
extendedProperties.put("log.file", CmsBase.getAbsolutePath(logFile));
}
// Create the configurations object
m_configurations = new Configurations(extendedProperties);
// Initialize the logging
A_OpenCms.initializeServletLogging(m_configurations);
if(C_LOGGING && A_OpenCms.isLogging(C_OPENCMS_INIT)) {
A_OpenCms.log(C_OPENCMS_INIT, ".");
A_OpenCms.log(C_OPENCMS_INIT, ".");
A_OpenCms.log(C_OPENCMS_INIT, ".");
A_OpenCms.log(C_OPENCMS_INIT, ".");
printCopyrightInformation();
A_OpenCms.log(C_OPENCMS_INIT, ". ...............................................................");
A_OpenCms.log(C_OPENCMS_INIT, ". Startup time : " + (new Date(System.currentTimeMillis())));
A_OpenCms.log(C_OPENCMS_INIT, ". Servlet container : " + config.getServletContext().getServerInfo());
A_OpenCms.log(C_OPENCMS_INIT, ". OpenCms version : " + A_OpenCms.getVersionName());
A_OpenCms.log(C_OPENCMS_INIT, ". OpenCms base path : " + CmsBase.getBasePath());
A_OpenCms.log(C_OPENCMS_INIT, ". OpenCms property file: " + CmsBase.getPropertiesPath(true));
A_OpenCms.log(C_OPENCMS_INIT, ". OpenCms logfile : " + CmsBase.getAbsolutePath(logFile));
}
// check cluster configuration
m_clusterurl = (String)m_configurations.getString(C_CLUSTERURL, "");
if((! "".equals(m_clusterurl)) && C_LOGGING && A_OpenCms.isLogging(C_OPENCMS_INIT)) A_OpenCms.log(C_OPENCMS_INIT, ". Clusterurl : " + m_clusterurl);
try {
// create the OpenCms object
m_opencms = new OpenCms(m_configurations);
} catch (CmsException cmsex) {
if (cmsex.getType() == CmsException.C_RB_INIT_ERROR) {
throwInitException(new ServletException(C_ERRORMSG + "Could not connect to the database. Is the database up and running?\n\n", cmsex));
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -