📄 connector.java
字号:
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.catalina.connector;
import java.lang.reflect.Method;
import java.net.URLEncoder;
import java.util.HashMap;
import javax.management.MBeanRegistration;
import javax.management.MBeanServer;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
import org.apache.catalina.Container;
import org.apache.catalina.Lifecycle;
import org.apache.catalina.LifecycleException;
import org.apache.catalina.LifecycleListener;
import org.apache.catalina.Service;
import org.apache.catalina.core.StandardEngine;
import org.apache.catalina.util.LifecycleSupport;
import org.apache.catalina.util.StringManager;
import org.apache.coyote.Adapter;
import org.apache.coyote.ProtocolHandler;
import org.apache.juli.logging.Log;
import org.apache.juli.logging.LogFactory;
import org.apache.tomcat.util.IntrospectionUtils;
import org.apache.tomcat.util.http.mapper.Mapper;
import org.apache.tomcat.util.modeler.Registry;
/**
* Implementation of a Coyote connector for Tomcat 5.x.
*
* @author Craig R. McClanahan
* @author Remy Maucherat
* @version $Revision: 480000 $ $Date: 2006-11-28 12:31:04 +0100 (mar., 28 nov. 2006) $
*/
public class Connector
implements Lifecycle, MBeanRegistration
{
private static Log log = LogFactory.getLog(Connector.class);
/**
* Alternate flag to enable recycling of facades.
*/
public static final boolean RECYCLE_FACADES =
Boolean.valueOf(System.getProperty("org.apache.catalina.connector.RECYCLE_FACADES", "false")).booleanValue();
// ------------------------------------------------------------ Constructor
public Connector()
throws Exception {
this(null);
}
public Connector(String protocol)
throws Exception {
setProtocol(protocol);
// Instantiate protocol handler
try {
Class clazz = Class.forName(protocolHandlerClassName);
this.protocolHandler = (ProtocolHandler) clazz.newInstance();
} catch (Exception e) {
log.error
(sm.getString
("coyoteConnector.protocolHandlerInstantiationFailed", e));
}
}
// ----------------------------------------------------- Instance Variables
/**
* The <code>Service</code> we are associated with (if any).
*/
protected Service service = null;
/**
* Do we allow TRACE ?
*/
protected boolean allowTrace = false;
/**
* The Container used for processing requests received by this Connector.
*/
protected Container container = null;
/**
* Use "/" as path for session cookies ?
*/
protected boolean emptySessionPath = false;
/**
* The "enable DNS lookups" flag for this Connector.
*/
protected boolean enableLookups = false;
/*
* Is generation of X-Powered-By response header enabled/disabled?
*/
protected boolean xpoweredBy = false;
/**
* Descriptive information about this Connector implementation.
*/
protected static final String info =
"org.apache.catalina.connector.Connector/2.1";
/**
* The lifecycle event support for this component.
*/
protected LifecycleSupport lifecycle = new LifecycleSupport(this);
/**
* The port number on which we listen for requests.
*/
protected int port = 0;
/**
* The server name to which we should pretend requests to this Connector
* were directed. This is useful when operating Tomcat behind a proxy
* server, so that redirects get constructed accurately. If not specified,
* the server name included in the <code>Host</code> header is used.
*/
protected String proxyName = null;
/**
* The server port to which we should pretent requests to this Connector
* were directed. This is useful when operating Tomcat behind a proxy
* server, so that redirects get constructed accurately. If not specified,
* the port number specified by the <code>port</code> property is used.
*/
protected int proxyPort = 0;
/**
* The redirect port for non-SSL to SSL redirects.
*/
protected int redirectPort = 443;
/**
* The request scheme that will be set on all requests received
* through this connector.
*/
protected String scheme = "http";
/**
* The secure connection flag that will be set on all requests received
* through this connector.
*/
protected boolean secure = false;
/**
* The string manager for this package.
*/
protected StringManager sm =
StringManager.getManager(Constants.Package);
/**
* Maximum size of a POST which will be automatically parsed by the
* container. 2MB by default.
*/
protected int maxPostSize = 2 * 1024 * 1024;
/**
* Maximum size of a POST which will be saved by the container
* during authentication. 4kB by default
*/
protected int maxSavePostSize = 4 * 1024;
/**
* Has this component been initialized yet?
*/
protected boolean initialized = false;
/**
* Has this component been started yet?
*/
protected boolean started = false;
/**
* The shutdown signal to our background thread
*/
protected boolean stopped = false;
/**
* Flag to use IP-based virtual hosting.
*/
protected boolean useIPVHosts = false;
/**
* The background thread.
*/
protected Thread thread = null;
/**
* Coyote Protocol handler class name.
* Defaults to the Coyote HTTP/1.1 protocolHandler.
*/
protected String protocolHandlerClassName =
"org.apache.coyote.http11.Http11Protocol";
/**
* Coyote protocol handler.
*/
protected ProtocolHandler protocolHandler = null;
/**
* Coyote adapter.
*/
protected Adapter adapter = null;
/**
* Mapper.
*/
protected Mapper mapper = new Mapper();
/**
* Mapper listener.
*/
protected MapperListener mapperListener = new MapperListener(mapper);
/**
* URI encoding.
*/
protected String URIEncoding = null;
/**
* URI encoding as body.
*/
protected boolean useBodyEncodingForURI = false;
protected static HashMap replacements = new HashMap();
static {
replacements.put("acceptCount", "backlog");
replacements.put("connectionLinger", "soLinger");
replacements.put("connectionTimeout", "soTimeout");
replacements.put("connectionUploadTimeout", "timeout");
replacements.put("clientAuth", "clientauth");
replacements.put("keystoreFile", "keystore");
replacements.put("randomFile", "randomfile");
replacements.put("rootFile", "rootfile");
replacements.put("keystorePass", "keypass");
replacements.put("keystoreType", "keytype");
replacements.put("sslProtocol", "protocol");
replacements.put("sslProtocols", "protocols");
}
// ------------------------------------------------------------- Properties
/**
* Return a configured property.
*/
public Object getProperty(String name) {
String repl = name;
if (replacements.get(name) != null) {
repl = (String) replacements.get(name);
}
return IntrospectionUtils.getProperty(protocolHandler, repl);
}
/**
* Set a configured property.
*/
public void setProperty(String name, String value) {
String repl = name;
if (replacements.get(name) != null) {
repl = (String) replacements.get(name);
}
IntrospectionUtils.setProperty(protocolHandler, repl, value);
}
/**
* Return a configured property.
*/
public Object getAttribute(String name) {
return getProperty(name);
}
/**
* Set a configured property.
*/
public void setAttribute(String name, Object value) {
setProperty(name, String.valueOf(value));
}
/**
* remove a configured property.
*/
public void removeProperty(String name) {
// FIXME !
//protocolHandler.removeAttribute(name);
}
/**
* Return the <code>Service</code> with which we are associated (if any).
*/
public Service getService() {
return (this.service);
}
/**
* Set the <code>Service</code> with which we are associated (if any).
*
* @param service The service that owns this Engine
*/
public void setService(Service service) {
this.service = service;
// FIXME: setProperty("service", service);
}
/**
* True if the TRACE method is allowed. Default value is "false".
*/
public boolean getAllowTrace() {
return (this.allowTrace);
}
/**
* Set the allowTrace flag, to disable or enable the TRACE HTTP method.
*
* @param allowTrace The new allowTrace flag
*/
public void setAllowTrace(boolean allowTrace) {
this.allowTrace = allowTrace;
setProperty("allowTrace", String.valueOf(allowTrace));
}
/**
* Is this connector available for processing requests?
*/
public boolean isAvailable() {
return (started);
}
/**
* Return the input buffer size for this Connector.
*
* @deprecated
*/
public int getBufferSize() {
return 2048;
}
/**
* Set the input buffer size for this Connector.
*
* @param bufferSize The new input buffer size.
* @deprecated
*/
public void setBufferSize(int bufferSize) {
}
/**
* Return the Container used for processing requests received by this
* Connector.
*/
public Container getContainer() {
if( container==null ) {
// Lazy - maybe it was added later
findContainer();
}
return (container);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -