Author: remy.maucherat(a)jboss.com
Date: 2011-04-01 14:00:38 -0400 (Fri, 01 Apr 2011)
New Revision: 1692
Modified:
trunk/java/org/apache/catalina/connector/Connector.java
trunk/java/org/apache/catalina/core/AprLifecycleListener.java
trunk/java/org/apache/catalina/startup/Embedded.java
Log:
- Relax protocol values.
- Remove bad Connector APIs.
- AprLifecycleListener will now control use of native.
Modified: trunk/java/org/apache/catalina/connector/Connector.java
===================================================================
--- trunk/java/org/apache/catalina/connector/Connector.java 2011-03-31 14:02:29 UTC (rev
1691)
+++ trunk/java/org/apache/catalina/connector/Connector.java 2011-04-01 18:00:38 UTC (rev
1692)
@@ -18,8 +18,6 @@
package org.apache.catalina.connector;
-import java.lang.reflect.Method;
-import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Set;
@@ -33,6 +31,7 @@
import org.apache.catalina.LifecycleException;
import org.apache.catalina.LifecycleListener;
import org.apache.catalina.Service;
+import org.apache.catalina.core.AprLifecycleListener;
import org.apache.catalina.util.LifecycleSupport;
import org.apache.catalina.util.StringManager;
import org.apache.coyote.Adapter;
@@ -72,20 +71,15 @@
// ------------------------------------------------------------ Constructor
- public Connector()
- throws Exception {
- this(null);
- }
-
public Connector(String protocol)
throws Exception {
setProtocol(protocol);
// Instantiate protocol handler
try {
- Class clazz = Class.forName(protocolHandlerClassName);
+ Class<?> clazz = Class.forName(protocolHandlerClassName);
this.protocolHandler = (ProtocolHandler) clazz.newInstance();
} catch (Exception e) {
- log.error
+ throw new IllegalArgumentException
(sm.getString
("coyoteConnector.protocolHandlerInstantiationFailed", e));
}
@@ -269,7 +263,7 @@
protected Set<String> allowedHosts = null;
- protected static HashMap replacements = new HashMap();
+ protected static HashMap<String, String> replacements = new HashMap<String,
String>();
static {
replacements.put("acceptCount", "backlog");
replacements.put("connectionLinger", "soLinger");
@@ -330,15 +324,6 @@
/**
- * 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() {
@@ -356,7 +341,6 @@
public void setService(Service service) {
this.service = service;
- // FIXME: setProperty("service", service);
}
@@ -580,70 +564,18 @@
}
- // ---------------------------------------------- APR Version Constants
-
- private static final int TCN_REQUIRED_MAJOR = 1;
- private static final int TCN_REQUIRED_MINOR = 1;
- private static final int TCN_REQUIRED_PATCH = 3;
- private static boolean aprInitialized = false;
-
- // APR init support
- private static synchronized void initializeAPR()
- {
- if (aprInitialized) {
- return;
- }
- int major = 0;
- int minor = 0;
- int patch = 0;
- try {
- String methodName = "initialize";
- Class paramTypes[] = new Class[1];
- paramTypes[0] = String.class;
- Object paramValues[] = new Object[1];
- paramValues[0] = null;
- Class clazz = Class.forName("org.apache.tomcat.jni.Library");
- Method method = clazz.getMethod(methodName, paramTypes);
- method.invoke(null, paramValues);
- major = clazz.getField("TCN_MAJOR_VERSION").getInt(null);
- minor = clazz.getField("TCN_MINOR_VERSION").getInt(null);
- patch = clazz.getField("TCN_PATCH_VERSION").getInt(null);
- } catch (Throwable t) {
- return;
- }
- if ((major != TCN_REQUIRED_MAJOR) ||
- (minor != TCN_REQUIRED_MINOR) ||
- (patch < TCN_REQUIRED_PATCH)) {
- try {
- // Terminate the APR in case the version
- // is below required.
- String methodName = "terminate";
- Method method = Class.forName("org.apache.tomcat.jni.Library")
- .getMethod(methodName, (Class [])null);
- method.invoke(null, (Object []) null);
- } catch (Throwable t) {
- // Ignore
- }
- return;
- }
- aprInitialized = true;
- }
-
/**
* Set the Coyote protocol which will be used by the connector.
*
* @param protocol The Coyote protocol name
*/
- public void setProtocol(String protocol) {
+ protected void setProtocol(String protocol) {
- // Test APR support
- initializeAPR();
-
- if (aprInitialized) {
- if ("HTTP/1.1".equals(protocol)) {
+ if (AprLifecycleListener.isAprInitialized()) {
+ if ("HTTP/1.1".equals(protocol) ||
"http".equals(protocol)) {
setProtocolHandlerClassName
("org.apache.coyote.http11.Http11AprProtocol");
- } else if ("AJP/1.3".equals(protocol)) {
+ } else if ("AJP/1.3".equals(protocol) ||
"ajp".equals(protocol)) {
setProtocolHandlerClassName
("org.apache.coyote.ajp.AjpAprProtocol");
} else if (protocol != null) {
@@ -653,10 +585,10 @@
("org.apache.coyote.http11.Http11AprProtocol");
}
} else {
- if ("HTTP/1.1".equals(protocol)) {
+ if ("HTTP/1.1".equals(protocol) ||
"http".equals(protocol)) {
setProtocolHandlerClassName
("org.apache.coyote.http11.Http11Protocol");
- } else if ("AJP/1.3".equals(protocol)) {
+ } else if ("AJP/1.3".equals(protocol) ||
"ajp".equals(protocol)) {
setProtocolHandlerClassName
("org.apache.coyote.ajp.AjpProtocol");
} else if (protocol != null) {
@@ -722,7 +654,7 @@
setProperty("proxyName", proxyName);
} else {
this.proxyName = null;
- removeProperty("proxyName");
+ setProperty("proxyName", null);
}
}
@@ -994,7 +926,7 @@
throws MalformedObjectNameException {
String encodedAddr = null;
if (getProperty("address") != null) {
- encodedAddr =
URLEncoder.encode(getProperty("address").toString());
+ encodedAddr = ObjectName.quote(getProperty("address").toString());
}
String addSuffix = (getProperty("address") == null) ? "" :
",address="
+ encodedAddr;
Modified: trunk/java/org/apache/catalina/core/AprLifecycleListener.java
===================================================================
--- trunk/java/org/apache/catalina/core/AprLifecycleListener.java 2011-03-31 14:02:29 UTC
(rev 1691)
+++ trunk/java/org/apache/catalina/core/AprLifecycleListener.java 2011-04-01 18:00:38 UTC
(rev 1692)
@@ -103,11 +103,11 @@
}
try {
String methodName = "initialize";
- Class paramTypes[] = new Class[1];
+ Class<?> paramTypes[] = new Class[1];
paramTypes[0] = String.class;
Object paramValues[] = new Object[1];
paramValues[0] = null;
- Class clazz = Class.forName("org.apache.tomcat.jni.Library");
+ Class<?> clazz =
Class.forName("org.apache.tomcat.jni.Library");
Method method = clazz.getMethod(methodName, paramTypes);
method.invoke(null, paramValues);
major = clazz.getField("TCN_MAJOR_VERSION").getInt(null);
@@ -171,11 +171,11 @@
return;
}
String methodName = "randSet";
- Class paramTypes[] = new Class[1];
+ Class<?> paramTypes[] = new Class[1];
paramTypes[0] = String.class;
Object paramValues[] = new Object[1];
paramValues[0] = SSLRandomSeed;
- Class clazz = Class.forName("org.apache.tomcat.jni.SSL");
+ Class<?> clazz = Class.forName("org.apache.tomcat.jni.SSL");
Method method = clazz.getMethod(methodName, paramTypes);
method.invoke(null, paramValues);
@@ -187,6 +187,10 @@
sslInitialized = true;
}
+ public static boolean isAprInitialized() {
+ return aprInitialized;
+ }
+
public String getSSLEngine() {
return SSLEngine;
}
Modified: trunk/java/org/apache/catalina/startup/Embedded.java
===================================================================
--- trunk/java/org/apache/catalina/startup/Embedded.java 2011-03-31 14:02:29 UTC (rev
1691)
+++ trunk/java/org/apache/catalina/startup/Embedded.java 2011-04-01 18:00:38 UTC (rev
1692)
@@ -340,9 +340,9 @@
} else if (protocol.equals("memory")) {
connector = new
Connector("org.apache.coyote.memory.MemoryProtocolHandler");
} else if (protocol.equals("http")) {
- connector = new Connector();
+ connector = new Connector("http");
} else if (protocol.equals("https")) {
- connector = new Connector();
+ connector = new Connector("http");
connector.setScheme("https");
connector.setSecure(true);
connector.setProperty("SSLEnabled","true");