-/*\r
- * Copyright 1999-2006 The Apache Software Foundation\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.apache.coyote.http11;\r
-\r
-import java.net.InetAddress;\r
-import java.net.Socket;\r
-import java.net.URLEncoder;\r
-import java.util.HashMap;\r
-import java.util.Iterator;\r
-import java.util.concurrent.Executor;\r
-\r
-import javax.management.MBeanRegistration;\r
-import javax.management.MBeanServer;\r
-import javax.management.ObjectName;\r
-\r
-import org.apache.coyote.ActionCode;\r
-import org.apache.coyote.ActionHook;\r
-import org.apache.coyote.Adapter;\r
-import org.apache.coyote.ProtocolHandler;\r
-import org.apache.coyote.RequestGroupInfo;\r
-import org.apache.coyote.RequestInfo;\r
-import org.apache.tomcat.util.modeler.Registry;\r
-import org.apache.tomcat.util.net.JIoEndpoint;\r
-import org.apache.tomcat.util.net.SSLImplementation;\r
-import org.apache.tomcat.util.net.ServerSocketFactory;\r
-import org.apache.tomcat.util.net.JIoEndpoint.Handler;\r
-import org.apache.tomcat.util.res.StringManager;\r
-\r
-\r
-/**\r
- * Abstract the protocol implementation, including threading, etc.\r
- * Processor is single threaded and specific to stream-based protocols,\r
- * will not fit Jk protocols like JNI.\r
- *\r
- * @author Remy Maucherat\r
- * @author Costin Manolache\r
- * @deprecated\r
- */\r
-public class Http11Protocol \r
- implements ProtocolHandler, MBeanRegistration {\r
-\r
-\r
- protected static org.apache.commons.logging.Log log\r
- = org.apache.commons.logging.LogFactory.getLog(Http11Protocol.class);\r
-\r
- /**\r
- * The string manager for this package.\r
- */\r
- protected static StringManager sm =\r
- StringManager.getManager(Constants.Package);\r
-\r
-\r
- // ------------------------------------------------------------ Constructor\r
-\r
-\r
- public Http11Protocol() {\r
- setSoLinger(Constants.DEFAULT_CONNECTION_LINGER);\r
- setSoTimeout(Constants.DEFAULT_CONNECTION_TIMEOUT);\r
- //setServerSoTimeout(Constants.DEFAULT_SERVER_SOCKET_TIMEOUT);\r
- setTcpNoDelay(Constants.DEFAULT_TCP_NO_DELAY);\r
- }\r
-\r
- \r
- // ----------------------------------------------------------------- Fields\r
-\r
-\r
- protected Http11ConnectionHandler cHandler = new Http11ConnectionHandler(this);\r
- protected JIoEndpoint endpoint = new JIoEndpoint();\r
-\r
-\r
- // *\r
- protected ObjectName tpOname = null;\r
- // *\r
- protected ObjectName rgOname = null;\r
-\r
-\r
- protected ServerSocketFactory socketFactory = null;\r
- protected SSLImplementation sslImplementation = null;\r
-\r
-\r
- // ----------------------------------------- ProtocolHandler Implementation\r
- // *\r
-\r
-\r
- protected HashMap<String, Object> attributes = new HashMap<String, Object>();\r
-\r
- \r
- /**\r
- * Pass config info\r
- */\r
- public void setAttribute(String name, Object value) {\r
- if (log.isTraceEnabled()) {\r
- log.trace(sm.getString("http11protocol.setattribute", name, value));\r
- }\r
- attributes.put(name, value);\r
- }\r
-\r
- public Object getAttribute(String key) {\r
- return attributes.get(key);\r
- }\r
-\r
- public Iterator getAttributeNames() {\r
- return attributes.keySet().iterator();\r
- }\r
-\r
-\r
- /**\r
- * The adapter, used to call the connector.\r
- */\r
- protected Adapter adapter;\r
- public void setAdapter(Adapter adapter) { this.adapter = adapter; }\r
- public Adapter getAdapter() { return adapter; }\r
-\r
-\r
- public void init() throws Exception {\r
- endpoint.setName(getName());\r
- endpoint.setHandler(cHandler);\r
-\r
- // Verify the validity of the configured socket factory\r
- try {\r
- if (secure) {\r
- sslImplementation =\r
- SSLImplementation.getInstance(sslImplementationName);\r
- socketFactory = sslImplementation.getServerSocketFactory();\r
- endpoint.setServerSocketFactory(socketFactory);\r
- } else if (socketFactoryName != null) {\r
- socketFactory = (ServerSocketFactory) Class.forName(socketFactoryName).newInstance();\r
- endpoint.setServerSocketFactory(socketFactory);\r
- }\r
- } catch (Exception ex) {\r
- log.error(sm.getString("http11protocol.socketfactory.initerror"),\r
- ex);\r
- throw ex;\r
- }\r
-\r
- if (socketFactory!=null) {\r
- Iterator<String> attE = attributes.keySet().iterator();\r
- while( attE.hasNext() ) {\r
- String key = attE.next();\r
- Object v=attributes.get(key);\r
- socketFactory.setAttribute(key, v);\r
- }\r
- }\r
- \r
- try {\r
- endpoint.init();\r
- } catch (Exception ex) {\r
- log.error(sm.getString("http11protocol.endpoint.initerror"), ex);\r
- throw ex;\r
- }\r
- if (log.isInfoEnabled())\r
- log.info(sm.getString("http11protocol.init", getName()));\r
-\r
- }\r
-\r
- public void start() throws Exception {\r
- if (this.domain != null) {\r
- try {\r
- tpOname = new ObjectName\r
- (domain + ":" + "type=ThreadPool,name=" + getName());\r
- Registry.getRegistry(null, null)\r
- .registerComponent(endpoint, tpOname, null );\r
- } catch (Exception e) {\r
- log.error("Can't register endpoint");\r
- }\r
- rgOname=new ObjectName\r
- (domain + ":type=GlobalRequestProcessor,name=" + getName());\r
- Registry.getRegistry(null, null).registerComponent\r
- ( cHandler.global, rgOname, null );\r
- }\r
-\r
- try {\r
- endpoint.start();\r
- } catch (Exception ex) {\r
- log.error(sm.getString("http11protocol.endpoint.starterror"), ex);\r
- throw ex;\r
- }\r
- if (log.isInfoEnabled())\r
- log.info(sm.getString("http11protocol.start", getName()));\r
- }\r
-\r
- public void pause() throws Exception {\r
- try {\r
- endpoint.pause();\r
- } catch (Exception ex) {\r
- log.error(sm.getString("http11protocol.endpoint.pauseerror"), ex);\r
- throw ex;\r
- }\r
- if (log.isInfoEnabled())\r
- log.info(sm.getString("http11protocol.pause", getName()));\r
- }\r
-\r
- public void resume() throws Exception {\r
- try {\r
- endpoint.resume();\r
- } catch (Exception ex) {\r
- log.error(sm.getString("http11protocol.endpoint.resumeerror"), ex);\r
- throw ex;\r
- }\r
- if (log.isInfoEnabled())\r
- log.info(sm.getString("http11protocol.resume", getName()));\r
- }\r
-\r
- public void destroy() throws Exception {\r
- if (log.isInfoEnabled())\r
- log.info(sm.getString("http11protocol.stop", getName()));\r
- endpoint.destroy();\r
- if (tpOname!=null)\r
- Registry.getRegistry(null, null).unregisterComponent(tpOname);\r
- if (rgOname != null)\r
- Registry.getRegistry(null, null).unregisterComponent(rgOname);\r
- }\r
-\r
- \r
- // ------------------------------------------------------------- Properties\r
-\r
- \r
- // *\r
- /**\r
- * This field indicates if the protocol is secure from the perspective of\r
- * the client (= https is used).\r
- */\r
- protected boolean secure;\r
- public boolean getSecure() { return secure; }\r
- public void setSecure(boolean b) { secure = b; }\r
- \r
- \r
- /**\r
- * Name of the socket factory.\r
- */\r
- protected String socketFactoryName = null;\r
- public String getSocketFactory() { return socketFactoryName; }\r
- public void setSocketFactory(String valueS) { socketFactoryName = valueS; }\r
- \r
- \r
- /**\r
- * Name of the SSL implementation.\r
- */\r
- protected String sslImplementationName=null;\r
- public String getSSLImplementation() { return sslImplementationName; }\r
- public void setSSLImplementation( String valueS) {\r
- sslImplementationName = valueS;\r
- setSecure(true);\r
- }\r
- \r
- \r
- // HTTP\r
- /**\r
- * Maximum number of requests which can be performed over a keepalive \r
- * connection. The default is the same as for Apache HTTP Server.\r
- */\r
- protected int maxKeepAliveRequests = 100;\r
- public int getMaxKeepAliveRequests() { return maxKeepAliveRequests; }\r
- public void setMaxKeepAliveRequests(int mkar) { maxKeepAliveRequests = mkar; }\r
-\r
-\r
- // HTTP\r
- /**\r
- * This timeout represents the socket timeout which will be used while\r
- * the adapter execution is in progress, unless disableUploadTimeout\r
- * is set to true. The default is the same as for Apache HTTP Server\r
- * (300 000 milliseconds).\r
- */\r
- protected int timeout = 300000;\r
- public int getTimeout() { return timeout; }\r
- public void setTimeout(int timeout) { this.timeout = timeout; }\r
-\r
-\r
- // *\r
- /**\r
- * Maximum size of the post which will be saved when processing certain\r
- * requests, such as a POST.\r
- */\r
- protected int maxSavePostSize = 4 * 1024;\r
- public int getMaxSavePostSize() { return maxSavePostSize; }\r
- public void setMaxSavePostSize(int valueI) { maxSavePostSize = valueI; }\r
-\r
-\r
- // HTTP\r
- /**\r
- * Maximum size of the HTTP message header.\r
- */\r
- protected int maxHttpHeaderSize = 8 * 1024;\r
- public int getMaxHttpHeaderSize() { return maxHttpHeaderSize; }\r
- public void setMaxHttpHeaderSize(int valueI) { maxHttpHeaderSize = valueI; }\r
-\r
-\r
- // HTTP\r
- /**\r
- * If true, the regular socket timeout will be used for the full duration\r
- * of the connection.\r
- */\r
- protected boolean disableUploadTimeout = true;\r
- public boolean getDisableUploadTimeout() { return disableUploadTimeout; }\r
- public void setDisableUploadTimeout(boolean isDisabled) { disableUploadTimeout = isDisabled; }\r
-\r
-\r
- // HTTP\r
- /**\r
- * Integrated compression support.\r
- */\r
- protected String compression = "off";\r
- public String getCompression() { return compression; }\r
- public void setCompression(String valueS) { compression = valueS; }\r
- \r
- \r
- // HTTP\r
- protected String noCompressionUserAgents = null;\r
- public String getNoCompressionUserAgents() { return noCompressionUserAgents; }\r
- public void setNoCompressionUserAgents(String valueS) { noCompressionUserAgents = valueS; }\r
-\r
- \r
- // HTTP\r
- protected String compressableMimeTypes = "text/html,text/xml,text/plain";\r
- public String getCompressableMimeType() { return compressableMimeTypes; }\r
- public void setCompressableMimeType(String valueS) { compressableMimeTypes = valueS; }\r
- \r
- \r
- // HTTP\r
- protected int compressionMinSize = 2048;\r
- public int getCompressionMinSize() { return compressionMinSize; }\r
- public void setCompressionMinSize(int valueI) { compressionMinSize = valueI; }\r
-\r
-\r
- // HTTP\r
- /**\r
- * User agents regular expressions which should be restricted to HTTP/1.0 support.\r
- */\r
- protected String restrictedUserAgents = null;\r
- public String getRestrictedUserAgents() { return restrictedUserAgents; }\r
- public void setRestrictedUserAgents(String valueS) { restrictedUserAgents = valueS; }\r
- \r
- \r
- // HTTP\r
- /**\r
- * Server header.\r
- */\r
- protected String server;\r
- public void setServer( String server ) { this.server = server; }\r
- public String getServer() { return server; }\r
-\r
-\r
- // --------------------------------------------------------- Public methods\r
-\r
- // *\r
- public Executor getExecutor() {\r
- return endpoint.getExecutor();\r
- }\r
- \r
- // *\r
- public void setExecutor(Executor executor) {\r
- endpoint.setExecutor(executor);\r
- }\r
- \r
- // *\r
- public int getMaxThreads() {\r
- return endpoint.getMaxThreads();\r
- }\r
-\r
- // *\r
- public void setMaxThreads( int maxThreads ) {\r
- endpoint.setMaxThreads(maxThreads);\r
- }\r
-\r
- // *\r
- public void setThreadPriority(int threadPriority) {\r
- endpoint.setThreadPriority(threadPriority);\r
- }\r
-\r
- // *\r
- public int getThreadPriority() {\r
- return endpoint.getThreadPriority();\r
- }\r
-\r
- // *\r
- public int getBacklog() {\r
- return endpoint.getBacklog();\r
- }\r
-\r
- // *\r
- public void setBacklog( int i ) {\r
- endpoint.setBacklog(i);\r
- }\r
-\r
- // *\r
- public int getPort() {\r
- return endpoint.getPort();\r
- }\r
-\r
- // *\r
- public void setPort( int port ) {\r
- endpoint.setPort(port);\r
- }\r
-\r
- // *\r
- public InetAddress getAddress() {\r
- return endpoint.getAddress();\r
- }\r
-\r
- // *\r
- public void setAddress(InetAddress ia) {\r
- endpoint.setAddress( ia );\r
- }\r
-\r
- // *\r
- public String getName() {\r
- String encodedAddr = "";\r
- if (getAddress() != null) {\r
- encodedAddr = "" + getAddress();\r
- if (encodedAddr.startsWith("/"))\r
- encodedAddr = encodedAddr.substring(1);\r
- encodedAddr = URLEncoder.encode(encodedAddr) + "-";\r
- }\r
- return ("http-" + encodedAddr + endpoint.getPort());\r
- }\r
-\r
- // *\r
- public boolean getTcpNoDelay() {\r
- return endpoint.getTcpNoDelay();\r
- }\r
-\r
- // *\r
- public void setTcpNoDelay( boolean b ) {\r
- endpoint.setTcpNoDelay( b );\r
- }\r
-\r
- // *\r
- public int getSoLinger() {\r
- return endpoint.getSoLinger();\r
- }\r
-\r
- // *\r
- public void setSoLinger( int i ) {\r
- endpoint.setSoLinger( i );\r
- }\r
-\r
- // *\r
- public int getSoTimeout() {\r
- return endpoint.getSoTimeout();\r
- }\r
-\r
- // *\r
- public void setSoTimeout( int i ) {\r
- endpoint.setSoTimeout(i);\r
- }\r
-\r
- // HTTP\r
- /**\r
- * Return the Keep-Alive policy for the connection.\r
- */\r
- public boolean getKeepAlive() {\r
- return ((maxKeepAliveRequests != 0) && (maxKeepAliveRequests != 1));\r
- }\r
-\r
- // HTTP\r
- /**\r
- * Set the keep-alive policy for this connection.\r
- */\r
- public void setKeepAlive(boolean keepAlive) {\r
- if (!keepAlive) {\r
- setMaxKeepAliveRequests(1);\r
- }\r
- }\r
-\r
- /*\r
- * Note: All the following are JSSE/java.io specific attributes.\r
- */\r
- \r
- public String getKeystore() {\r
- return (String) getAttribute("keystore");\r
- }\r
-\r
- public void setKeystore( String k ) {\r
- setAttribute("keystore", k);\r
- }\r
-\r
- public String getKeypass() {\r
- return (String) getAttribute("keypass");\r
- }\r
-\r
- public void setKeypass( String k ) {\r
- attributes.put("keypass", k);\r
- //setAttribute("keypass", k);\r
- }\r
-\r
- public String getKeytype() {\r
- return (String) getAttribute("keystoreType");\r
- }\r
-\r
- public void setKeytype( String k ) {\r
- setAttribute("keystoreType", k);\r
- }\r
-\r
- public String getClientauth() {\r
- return (String) getAttribute("clientauth");\r
- }\r
-\r
- public void setClientauth( String k ) {\r
- setAttribute("clientauth", k);\r
- }\r
-\r
- public String getProtocols() {\r
- return (String) getAttribute("protocols");\r
- }\r
-\r
- public void setProtocols(String k) {\r
- setAttribute("protocols", k);\r
- }\r
-\r
- public String getAlgorithm() {\r
- return (String) getAttribute("algorithm");\r
- }\r
-\r
- public void setAlgorithm( String k ) {\r
- setAttribute("algorithm", k);\r
- }\r
-\r
- public String getCiphers() {\r
- return (String) getAttribute("ciphers");\r
- }\r
-\r
- public void setCiphers(String ciphers) {\r
- setAttribute("ciphers", ciphers);\r
- }\r
-\r
- public String getKeyAlias() {\r
- return (String) getAttribute("keyAlias");\r
- }\r
-\r
- public void setKeyAlias(String keyAlias) {\r
- setAttribute("keyAlias", keyAlias);\r
- }\r
-\r
- // ----------------------------------- Http11ConnectionHandler Inner Class\r
-\r
- protected static class Http11ConnectionHandler implements Handler {\r
- protected Http11Protocol protocol;\r
- protected static int count = 0;\r
- protected RequestGroupInfo global = new RequestGroupInfo();\r
- protected ThreadLocal<Http11Processor> localProcessor = new ThreadLocal<Http11Processor>();\r
-\r
- Http11ConnectionHandler(Http11Protocol proto) {\r
- this.protocol = proto;\r
- }\r
-\r
- public boolean process(Socket socket) {\r
- Http11Processor processor = null;\r
- try {\r
- processor = localProcessor.get();\r
- if (processor == null) {\r
- processor =\r
- new Http11Processor(protocol.maxHttpHeaderSize, protocol.endpoint);\r
- processor.setAdapter(protocol.adapter);\r
- processor.setMaxKeepAliveRequests(protocol.maxKeepAliveRequests);\r
- processor.setTimeout(protocol.timeout);\r
- processor.setDisableUploadTimeout(protocol.disableUploadTimeout);\r
- processor.setCompression(protocol.compression);\r
- processor.setCompressionMinSize(protocol.compressionMinSize);\r
- processor.setNoCompressionUserAgents(protocol.noCompressionUserAgents);\r
- processor.setCompressableMimeTypes(protocol.compressableMimeTypes);\r
- processor.setRestrictedUserAgents(protocol.restrictedUserAgents);\r
- processor.setMaxSavePostSize(protocol.maxSavePostSize);\r
- processor.setServer(protocol.server);\r
- localProcessor.set(processor);\r
- if (protocol.getDomain() != null) {\r
- synchronized (this) {\r
- try {\r
- RequestInfo rp = processor.getRequest().getRequestProcessor();\r
- rp.setGlobalProcessor(global);\r
- ObjectName rpName = new ObjectName\r
- (protocol.getDomain() + ":type=RequestProcessor,worker="\r
- + protocol.getName() + ",name=HttpRequest" + count++);\r
- Registry.getRegistry(null, null).registerComponent(rp, rpName, null);\r
- } catch (Exception e) {\r
- log.warn("Error registering request");\r
- }\r
- }\r
- }\r
- }\r
-\r
- if (processor instanceof ActionHook) {\r
- ((ActionHook) processor).action(ActionCode.ACTION_START, null);\r
- }\r
-\r
- if (protocol.secure && (protocol.sslImplementation != null)) {\r
- processor.setSSLSupport\r
- (protocol.sslImplementation.getSSLSupport(socket));\r
- } else {\r
- processor.setSSLSupport(null);\r
- }\r
- \r
- processor.process(socket);\r
- return false;\r
-\r
- } catch(java.net.SocketException e) {\r
- // SocketExceptions are normal\r
- Http11Protocol.log.debug\r
- (sm.getString\r
- ("http11protocol.proto.socketexception.debug"), e);\r
- } catch (java.io.IOException e) {\r
- // IOExceptions are normal\r
- Http11Protocol.log.debug\r
- (sm.getString\r
- ("http11protocol.proto.ioexception.debug"), e);\r
- }\r
- // Future developers: if you discover any other\r
- // rare-but-nonfatal exceptions, catch them here, and log as\r
- // above.\r
- catch (Throwable e) {\r
- // any other exception or error is odd. Here we log it\r
- // with "ERROR" level, so it will show up even on\r
- // less-than-verbose logs.\r
- Http11Protocol.log.error\r
- (sm.getString("http11protocol.proto.error"), e);\r
- } finally {\r
- // if(proto.adapter != null) proto.adapter.recycle();\r
- // processor.recycle();\r
-\r
- if (processor instanceof ActionHook) {\r
- ((ActionHook) processor).action(ActionCode.ACTION_STOP, null);\r
- }\r
- }\r
- return false;\r
- }\r
- }\r
-\r
-\r
- // -------------------- JMX related methods --------------------\r
-\r
- // *\r
- protected String domain;\r
- protected ObjectName oname;\r
- protected MBeanServer mserver;\r
-\r
- public ObjectName getObjectName() {\r
- return oname;\r
- }\r
-\r
- public String getDomain() {\r
- return domain;\r
- }\r
-\r
- public ObjectName preRegister(MBeanServer server,\r
- ObjectName name) throws Exception {\r
- oname=name;\r
- mserver=server;\r
- domain=name.getDomain();\r
- return name;\r
- }\r
-\r
- public void postRegister(Boolean registrationDone) {\r
- }\r
-\r
- public void preDeregister() throws Exception {\r
- }\r
-\r
- public void postDeregister() {\r
- }\r
-}\r
+/*
+ * Copyright 1999-2006 The Apache Software Foundation
+ *
+ * Licensed 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.coyote.http11;
+
+import java.net.InetAddress;
+import java.net.Socket;
+import java.net.URLEncoder;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.concurrent.Executor;
+
+import javax.management.MBeanRegistration;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+import org.apache.coyote.ActionCode;
+import org.apache.coyote.ActionHook;
+import org.apache.coyote.Adapter;
+import org.apache.coyote.ProtocolHandler;
+import org.apache.coyote.RequestGroupInfo;
+import org.apache.coyote.RequestInfo;
+import org.apache.tomcat.util.modeler.Registry;
+import org.apache.tomcat.util.net.JIoEndpoint;
+import org.apache.tomcat.util.net.SSLImplementation;
+import org.apache.tomcat.util.net.ServerSocketFactory;
+import org.apache.tomcat.util.net.JIoEndpoint.Handler;
+import org.apache.tomcat.util.res.StringManager;
+
+
+/**
+ * Abstract the protocol implementation, including threading, etc.
+ * Processor is single threaded and specific to stream-based protocols,
+ * will not fit Jk protocols like JNI.
+ *
+ * @author Remy Maucherat
+ * @author Costin Manolache
+ * @deprecated
+ */
+public class Http11Protocol
+ implements ProtocolHandler, MBeanRegistration {
+
+
+ protected static org.apache.commons.logging.Log log
+ = org.apache.commons.logging.LogFactory.getLog(Http11Protocol.class);
+
+ /**
+ * The string manager for this package.
+ */
+ protected static StringManager sm =
+ StringManager.getManager(Constants.Package);
+
+
+ // ------------------------------------------------------------ Constructor
+
+
+ public Http11Protocol() {
+ setSoLinger(Constants.DEFAULT_CONNECTION_LINGER);
+ setSoTimeout(Constants.DEFAULT_CONNECTION_TIMEOUT);
+ //setServerSoTimeout(Constants.DEFAULT_SERVER_SOCKET_TIMEOUT);
+ setTcpNoDelay(Constants.DEFAULT_TCP_NO_DELAY);
+ }
+
+
+ // ----------------------------------------------------------------- Fields
+
+
+ protected Http11ConnectionHandler cHandler = new Http11ConnectionHandler(this);
+ protected JIoEndpoint endpoint = new JIoEndpoint();
+
+
+ // *
+ protected ObjectName tpOname = null;
+ // *
+ protected ObjectName rgOname = null;
+
+
+ protected ServerSocketFactory socketFactory = null;
+ protected SSLImplementation sslImplementation = null;
+
+
+ // ----------------------------------------- ProtocolHandler Implementation
+ // *
+
+
+ protected HashMap<String, Object> attributes = new HashMap<String, Object>();
+
+
+ /**
+ * Pass config info
+ */
+ public void setAttribute(String name, Object value) {
+ if (log.isTraceEnabled()) {
+ log.trace(sm.getString("http11protocol.setattribute", name, value));
+ }
+ attributes.put(name, value);
+ }
+
+ public Object getAttribute(String key) {
+ return attributes.get(key);
+ }
+
+ public Iterator getAttributeNames() {
+ return attributes.keySet().iterator();
+ }
+
+
+ /**
+ * The adapter, used to call the connector.
+ */
+ protected Adapter adapter;
+ public void setAdapter(Adapter adapter) { this.adapter = adapter; }
+ public Adapter getAdapter() { return adapter; }
+
+
+ public void init() throws Exception {
+ endpoint.setName(getName());
+ endpoint.setHandler(cHandler);
+
+ // Verify the validity of the configured socket factory
+ try {
+ if (secure) {
+ sslImplementation =
+ SSLImplementation.getInstance(sslImplementationName);
+ socketFactory = sslImplementation.getServerSocketFactory();
+ endpoint.setServerSocketFactory(socketFactory);
+ } else if (socketFactoryName != null) {
+ socketFactory = (ServerSocketFactory) Class.forName(socketFactoryName).newInstance();
+ endpoint.setServerSocketFactory(socketFactory);
+ }
+ } catch (Exception ex) {
+ log.error(sm.getString("http11protocol.socketfactory.initerror"),
+ ex);
+ throw ex;
+ }
+
+ if (socketFactory!=null) {
+ Iterator<String> attE = attributes.keySet().iterator();
+ while( attE.hasNext() ) {
+ String key = attE.next();
+ Object v=attributes.get(key);
+ socketFactory.setAttribute(key, v);
+ }
+ }
+
+ try {
+ endpoint.init();
+ } catch (Exception ex) {
+ log.error(sm.getString("http11protocol.endpoint.initerror"), ex);
+ throw ex;
+ }
+ if (log.isInfoEnabled())
+ log.info(sm.getString("http11protocol.init", getName()));
+
+ }
+
+ public void start() throws Exception {
+ if (this.domain != null) {
+ try {
+ tpOname = new ObjectName
+ (domain + ":" + "type=ThreadPool,name=" + getName());
+ Registry.getRegistry(null, null)
+ .registerComponent(endpoint, tpOname, null );
+ } catch (Exception e) {
+ log.error("Can't register endpoint");
+ }
+ rgOname=new ObjectName
+ (domain + ":type=GlobalRequestProcessor,name=" + getName());
+ Registry.getRegistry(null, null).registerComponent
+ ( cHandler.global, rgOname, null );
+ }
+
+ try {
+ endpoint.start();
+ } catch (Exception ex) {
+ log.error(sm.getString("http11protocol.endpoint.starterror"), ex);
+ throw ex;
+ }
+ if (log.isInfoEnabled())
+ log.info(sm.getString("http11protocol.start", getName()));
+ }
+
+ public void pause() throws Exception {
+ try {
+ endpoint.pause();
+ } catch (Exception ex) {
+ log.error(sm.getString("http11protocol.endpoint.pauseerror"), ex);
+ throw ex;
+ }
+ if (log.isInfoEnabled())
+ log.info(sm.getString("http11protocol.pause", getName()));
+ }
+
+ public void resume() throws Exception {
+ try {
+ endpoint.resume();
+ } catch (Exception ex) {
+ log.error(sm.getString("http11protocol.endpoint.resumeerror"), ex);
+ throw ex;
+ }
+ if (log.isInfoEnabled())
+ log.info(sm.getString("http11protocol.resume", getName()));
+ }
+
+ public void destroy() throws Exception {
+ if (log.isInfoEnabled())
+ log.info(sm.getString("http11protocol.stop", getName()));
+ endpoint.destroy();
+ if (tpOname!=null)
+ Registry.getRegistry(null, null).unregisterComponent(tpOname);
+ if (rgOname != null)
+ Registry.getRegistry(null, null).unregisterComponent(rgOname);
+ }
+
+
+ // ------------------------------------------------------------- Properties
+
+
+ // *
+ /**
+ * This field indicates if the protocol is secure from the perspective of
+ * the client (= https is used).
+ */
+ protected boolean secure;
+ public boolean getSecure() { return secure; }
+ public void setSecure(boolean b) { secure = b; }
+
+
+ /**
+ * Name of the socket factory.
+ */
+ protected String socketFactoryName = null;
+ public String getSocketFactory() { return socketFactoryName; }
+ public void setSocketFactory(String valueS) { socketFactoryName = valueS; }
+
+
+ /**
+ * Name of the SSL implementation.
+ */
+ protected String sslImplementationName=null;
+ public String getSSLImplementation() { return sslImplementationName; }
+ public void setSSLImplementation( String valueS) {
+ sslImplementationName = valueS;
+ setSecure(true);
+ }
+
+
+ // HTTP
+ /**
+ * Maximum number of requests which can be performed over a keepalive
+ * connection. The default is the same as for Apache HTTP Server.
+ */
+ protected int maxKeepAliveRequests = 100;
+ public int getMaxKeepAliveRequests() { return maxKeepAliveRequests; }
+ public void setMaxKeepAliveRequests(int mkar) { maxKeepAliveRequests = mkar; }
+
+
+ // HTTP
+ /**
+ * This timeout represents the socket timeout which will be used while
+ * the adapter execution is in progress, unless disableUploadTimeout
+ * is set to true. The default is the same as for Apache HTTP Server
+ * (300 000 milliseconds).
+ */
+ protected int timeout = 300000;
+ public int getTimeout() { return timeout; }
+ public void setTimeout(int timeout) { this.timeout = timeout; }
+
+
+ // *
+ /**
+ * Maximum size of the post which will be saved when processing certain
+ * requests, such as a POST.
+ */
+ protected int maxSavePostSize = 4 * 1024;
+ public int getMaxSavePostSize() { return maxSavePostSize; }
+ public void setMaxSavePostSize(int valueI) { maxSavePostSize = valueI; }
+
+
+ // HTTP
+ /**
+ * Maximum size of the HTTP message header.
+ */
+ protected int maxHttpHeaderSize = 8 * 1024;
+ public int getMaxHttpHeaderSize() { return maxHttpHeaderSize; }
+ public void setMaxHttpHeaderSize(int valueI) { maxHttpHeaderSize = valueI; }
+
+
+ // HTTP
+ /**
+ * If true, the regular socket timeout will be used for the full duration
+ * of the connection.
+ */
+ protected boolean disableUploadTimeout = true;
+ public boolean getDisableUploadTimeout() { return disableUploadTimeout; }
+ public void setDisableUploadTimeout(boolean isDisabled) { disableUploadTimeout = isDisabled; }
+
+
+ // HTTP
+ /**
+ * Integrated compression support.
+ */
+ protected String compression = "off";
+ public String getCompression() { return compression; }
+ public void setCompression(String valueS) { compression = valueS; }
+
+
+ // HTTP
+ protected String noCompressionUserAgents = null;
+ public String getNoCompressionUserAgents() { return noCompressionUserAgents; }
+ public void setNoCompressionUserAgents(String valueS) { noCompressionUserAgents = valueS; }
+
+
+ // HTTP
+ protected String compressableMimeTypes = "text/html,text/xml,text/plain";
+ public String getCompressableMimeType() { return compressableMimeTypes; }
+ public void setCompressableMimeType(String valueS) { compressableMimeTypes = valueS; }
+
+
+ // HTTP
+ protected int compressionMinSize = 2048;
+ public int getCompressionMinSize() { return compressionMinSize; }
+ public void setCompressionMinSize(int valueI) { compressionMinSize = valueI; }
+
+
+ // HTTP
+ /**
+ * User agents regular expressions which should be restricted to HTTP/1.0 support.
+ */
+ protected String restrictedUserAgents = null;
+ public String getRestrictedUserAgents() { return restrictedUserAgents; }
+ public void setRestrictedUserAgents(String valueS) { restrictedUserAgents = valueS; }
+
+
+ // HTTP
+ /**
+ * Server header.
+ */
+ protected String server;
+ public void setServer( String server ) { this.server = server; }
+ public String getServer() { return server; }
+
+
+ // --------------------------------------------------------- Public methods
+
+ // *
+ public Executor getExecutor() {
+ return endpoint.getExecutor();
+ }
+
+ // *
+ public void setExecutor(Executor executor) {
+ endpoint.setExecutor(executor);
+ }
+
+ // *
+ public int getMaxThreads() {
+ return endpoint.getMaxThreads();
+ }
+
+ // *
+ public void setMaxThreads( int maxThreads ) {
+ endpoint.setMaxThreads(maxThreads);
+ }
+
+ // *
+ public void setThreadPriority(int threadPriority) {
+ endpoint.setThreadPriority(threadPriority);
+ }
+
+ // *
+ public int getThreadPriority() {
+ return endpoint.getThreadPriority();
+ }
+
+ // *
+ public int getBacklog() {
+ return endpoint.getBacklog();
+ }
+
+ // *
+ public void setBacklog( int i ) {
+ endpoint.setBacklog(i);
+ }
+
+ // *
+ public int getPort() {
+ return endpoint.getPort();
+ }
+
+ // *
+ public void setPort( int port ) {
+ endpoint.setPort(port);
+ }
+
+ // *
+ public InetAddress getAddress() {
+ return endpoint.getAddress();
+ }
+
+ // *
+ public void setAddress(InetAddress ia) {
+ endpoint.setAddress( ia );
+ }
+
+ // *
+ public String getName() {
+ String encodedAddr = "";
+ if (getAddress() != null) {
+ encodedAddr = "" + getAddress();
+ if (encodedAddr.startsWith("/"))
+ encodedAddr = encodedAddr.substring(1);
+ encodedAddr = URLEncoder.encode(encodedAddr) + "-";
+ }
+ return ("http-" + encodedAddr + endpoint.getPort());
+ }
+
+ // *
+ public boolean getTcpNoDelay() {
+ return endpoint.getTcpNoDelay();
+ }
+
+ // *
+ public void setTcpNoDelay( boolean b ) {
+ endpoint.setTcpNoDelay( b );
+ }
+
+ // *
+ public int getSoLinger() {
+ return endpoint.getSoLinger();
+ }
+
+ // *
+ public void setSoLinger( int i ) {
+ endpoint.setSoLinger( i );
+ }
+
+ // *
+ public int getSoTimeout() {
+ return endpoint.getSoTimeout();
+ }
+
+ // *
+ public void setSoTimeout( int i ) {
+ endpoint.setSoTimeout(i);
+ }
+
+ // HTTP
+ /**
+ * Return the Keep-Alive policy for the connection.
+ */
+ public boolean getKeepAlive() {
+ return ((maxKeepAliveRequests != 0) && (maxKeepAliveRequests != 1));
+ }
+
+ // HTTP
+ /**
+ * Set the keep-alive policy for this connection.
+ */
+ public void setKeepAlive(boolean keepAlive) {
+ if (!keepAlive) {
+ setMaxKeepAliveRequests(1);
+ }
+ }
+
+ /*
+ * Note: All the following are JSSE/java.io specific attributes.
+ */
+
+ public String getKeystore() {
+ return (String) getAttribute("keystore");
+ }
+
+ public void setKeystore( String k ) {
+ setAttribute("keystore", k);
+ }
+
+ public String getKeypass() {
+ return (String) getAttribute("keypass");
+ }
+
+ public void setKeypass( String k ) {
+ attributes.put("keypass", k);
+ //setAttribute("keypass", k);
+ }
+
+ public String getKeytype() {
+ return (String) getAttribute("keystoreType");
+ }
+
+ public void setKeytype( String k ) {
+ setAttribute("keystoreType", k);
+ }
+
+ public String getClientauth() {
+ return (String) getAttribute("clientauth");
+ }
+
+ public void setClientauth( String k ) {
+ setAttribute("clientauth", k);
+ }
+
+ public String getProtocols() {
+ return (String) getAttribute("protocols");
+ }
+
+ public void setProtocols(String k) {
+ setAttribute("protocols", k);
+ }
+
+ public String getAlgorithm() {
+ return (String) getAttribute("algorithm");
+ }
+
+ public void setAlgorithm( String k ) {
+ setAttribute("algorithm", k);
+ }
+
+ public String getCiphers() {
+ return (String) getAttribute("ciphers");
+ }
+
+ public void setCiphers(String ciphers) {
+ setAttribute("ciphers", ciphers);
+ }
+
+ public String getKeyAlias() {
+ return (String) getAttribute("keyAlias");
+ }
+
+ public void setKeyAlias(String keyAlias) {
+ setAttribute("keyAlias", keyAlias);
+ }
+
+ // ----------------------------------- Http11ConnectionHandler Inner Class
+
+ protected static class Http11ConnectionHandler implements Handler {
+ protected Http11Protocol protocol;
+ protected static int count = 0;
+ protected RequestGroupInfo global = new RequestGroupInfo();
+ protected ThreadLocal<Http11Processor> localProcessor = new ThreadLocal<Http11Processor>();
+
+ Http11ConnectionHandler(Http11Protocol proto) {
+ this.protocol = proto;
+ }
+
+ public boolean process(Socket socket) {
+ Http11Processor processor = null;
+ try {
+ processor = localProcessor.get();
+ if (processor == null) {
+ processor =
+ new Http11Processor(protocol.maxHttpHeaderSize, protocol.endpoint);
+ processor.setAdapter(protocol.adapter);
+ processor.setMaxKeepAliveRequests(protocol.maxKeepAliveRequests);
+ processor.setTimeout(protocol.timeout);
+ processor.setDisableUploadTimeout(protocol.disableUploadTimeout);
+ processor.setCompression(protocol.compression);
+ processor.setCompressionMinSize(protocol.compressionMinSize);
+ processor.setNoCompressionUserAgents(protocol.noCompressionUserAgents);
+ processor.setCompressableMimeTypes(protocol.compressableMimeTypes);
+ processor.setRestrictedUserAgents(protocol.restrictedUserAgents);
+ processor.setMaxSavePostSize(protocol.maxSavePostSize);
+ processor.setServer(protocol.server);
+ localProcessor.set(processor);
+ if (protocol.getDomain() != null) {
+ synchronized (this) {
+ try {
+ RequestInfo rp = processor.getRequest().getRequestProcessor();
+ rp.setGlobalProcessor(global);
+ ObjectName rpName = new ObjectName
+ (protocol.getDomain() + ":type=RequestProcessor,worker="
+ + protocol.getName() + ",name=HttpRequest" + count++);
+ Registry.getRegistry(null, null).registerComponent(rp, rpName, null);
+ } catch (Exception e) {
+ log.warn("Error registering request");
+ }
+ }
+ }
+ }
+
+ if (processor instanceof ActionHook) {
+ ((ActionHook) processor).action(ActionCode.ACTION_START, null);
+ }
+
+ if (protocol.secure && (protocol.sslImplementation != null)) {
+ processor.setSSLSupport
+ (protocol.sslImplementation.getSSLSupport(socket));
+ } else {
+ processor.setSSLSupport(null);
+ }
+
+ processor.process(socket);
+ return false;
+
+ } catch(java.net.SocketException e) {
+ // SocketExceptions are normal
+ Http11Protocol.log.debug
+ (sm.getString
+ ("http11protocol.proto.socketexception.debug"), e);
+ } catch (java.io.IOException e) {
+ // IOExceptions are normal
+ Http11Protocol.log.debug
+ (sm.getString
+ ("http11protocol.proto.ioexception.debug"), e);
+ }
+ // Future developers: if you discover any other
+ // rare-but-nonfatal exceptions, catch them here, and log as
+ // above.
+ catch (Throwable e) {
+ // any other exception or error is odd. Here we log it
+ // with "ERROR" level, so it will show up even on
+ // less-than-verbose logs.
+ Http11Protocol.log.error
+ (sm.getString("http11protocol.proto.error"), e);
+ } finally {
+ // if(proto.adapter != null) proto.adapter.recycle();
+ // processor.recycle();
+
+ if (processor instanceof ActionHook) {
+ ((ActionHook) processor).action(ActionCode.ACTION_STOP, null);
+ }
+ }
+ return false;
+ }
+ }
+
+
+ // -------------------- JMX related methods --------------------
+
+ // *
+ protected String domain;
+ protected ObjectName oname;
+ protected MBeanServer mserver;
+
+ public ObjectName getObjectName() {
+ return oname;
+ }
+
+ public String getDomain() {
+ return domain;
+ }
+
+ public ObjectName preRegister(MBeanServer server,
+ ObjectName name) throws Exception {
+ oname=name;
+ mserver=server;
+ domain=name.getDomain();
+ return name;
+ }
+
+ public void postRegister(Boolean registrationDone) {
+ }
+
+ public void preDeregister() throws Exception {
+ }
+
+ public void postDeregister() {
+ }
+}