package org.apache.catalina.connector;
public class Connector extends LifecycleMBeanBase {
public Connector(String protocol) {
setProtocol(protocol);
// Instantiate protocol handler
ProtocolHandler p = null;
try {
Class<?> clazz = Class.forName(protocolHandlerClassName);
p = (ProtocolHandler) clazz.getDeclaredConstructor().newInstance();
} catch (Exception e) {
log.error(sm.getString(
"coyoteConnector.protocolHandlerInstantiationFailed"), e);
} finally {
this.protocolHandler = p;
}
if (!Globals.STRICT_SERVLET_COMPLIANCE) {
URIEncoding = "UTF-8";
URIEncodingLower = URIEncoding.toLowerCase(Locale.ENGLISH);
}
}
/**
* 若在server.xml中,Connector的protocol属性设为"HTTP/1.1",则:
* protocol的真实类型为:org.apache.coyote.http11.Http11NioProtocol(系统未安装Apr) 或 org.apache.coyote.http11.Http11AprProtocol(系统安装了Apr)
* Set the Coyote protocol which will be used by the connector.
* @param protocol The Coyote protocol name
*/
<Connector port="8080" protocol="HTTP/1.1"/>
public void setProtocol(String protocol) {
if (AprLifecycleListener.isAprAvailable()) { // 如果机器上已经安装了Apr,则tomcat会自动检测到。
if ("HTTP/1.1".equals(protocol)) {
setProtocolHandlerClassName("org.apache.coyote.http11.Http11AprProtocol");
} else if ("AJP/1.3".equals(protocol)) {
setProtocolHandlerClassName"org.apache.coyote.ajp.AjpAprProtocol");
} else if (protocol != null) {
setProtocolHandlerClassName(protocol);
} else {
setProtocolHandlerClassName("org.apache.coyote.http11.Http11AprProtocol");
}
} else {
if ("HTTP/1.1".equals(protocol)) {
setProtocolHandlerClassName("org.apache.coyote.http11.Http11NioProtocol");
} else if ("AJP/1.3".equals(protocol)) {
setProtocolHandlerClassName("org.apache.coyote.ajp.AjpNioProtocol");
} else if (protocol != null) {
setProtocolHandlerClassName(protocol);
}
}
}
}
tomcat源码 -- Connector
最新推荐文章于 2020-06-22 13:56:02 发布
本文深入解析了Tomcat中Connector组件的工作原理,特别是如何通过设置不同的protocol属性来选择合适的ProtocolHandler,包括HTTP/1.1和AJP/1.3等协议的处理方式,并介绍了其在不同环境下(如是否安装Apr)的表现差异。
摘要由CSDN通过智能技术生成