You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ode.apache.org by mi...@apache.org on 2009/03/03 03:18:25 UTC

svn commit: r749508 - in /ode/branches/APACHE_ODE_1.X: ./ axis2/src/main/java/org/apache/ode/axis2/ axis2/src/main/java/org/apache/ode/axis2/httpbinding/ bpel-epr/src/main/java/org/apache/ode/il/config/

Author: midon
Date: Tue Mar  3 02:18:25 2009
New Revision: 749508

URL: http://svn.apache.org/viewvc?rev=749508&view=rev
Log:
ODE-533: shared HTTP connection manager

Modified:
    ode/branches/APACHE_ODE_1.X/.gitignore
    ode/branches/APACHE_ODE_1.X/axis2/src/main/java/org/apache/ode/axis2/ODEServer.java
    ode/branches/APACHE_ODE_1.X/axis2/src/main/java/org/apache/ode/axis2/Properties.java
    ode/branches/APACHE_ODE_1.X/axis2/src/main/java/org/apache/ode/axis2/SoapExternalService.java
    ode/branches/APACHE_ODE_1.X/axis2/src/main/java/org/apache/ode/axis2/httpbinding/HttpExternalService.java
    ode/branches/APACHE_ODE_1.X/axis2/src/main/java/org/apache/ode/axis2/httpbinding/HttpHelper.java
    ode/branches/APACHE_ODE_1.X/bpel-epr/src/main/java/org/apache/ode/il/config/OdeConfigProperties.java

Modified: ode/branches/APACHE_ODE_1.X/.gitignore
URL: http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.X/.gitignore?rev=749508&r1=749507&r2=749508&view=diff
==============================================================================
--- ode/branches/APACHE_ODE_1.X/.gitignore (original)
+++ ode/branches/APACHE_ODE_1.X/.gitignore Tue Mar  3 02:18:25 2009
@@ -14,3 +14,4 @@
 bin
 target
 reports
+test-output

Modified: ode/branches/APACHE_ODE_1.X/axis2/src/main/java/org/apache/ode/axis2/ODEServer.java
URL: http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.X/axis2/src/main/java/org/apache/ode/axis2/ODEServer.java?rev=749508&r1=749507&r2=749508&view=diff
==============================================================================
--- ode/branches/APACHE_ODE_1.X/axis2/src/main/java/org/apache/ode/axis2/ODEServer.java (original)
+++ ode/branches/APACHE_ODE_1.X/axis2/src/main/java/org/apache/ode/axis2/ODEServer.java Tue Mar  3 02:18:25 2009
@@ -26,6 +26,8 @@
 import org.apache.commons.collections.map.MultiKeyMap;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
+import org.apache.commons.httpclient.params.HttpConnectionManagerParams;
 import org.apache.ode.axis2.deploy.DeploymentPoller;
 import org.apache.ode.axis2.hooks.ODEAxisService;
 import org.apache.ode.axis2.hooks.ODEMessageReceiver;
@@ -125,6 +127,8 @@
 
     private ManagementService _mgtService;
 
+    private MultiThreadedHttpConnectionManager httpConnectionManager;
+
 
     public void init(ServletConfig config, AxisConfiguration axisConf) throws ServletException {
         init(config.getServletContext().getRealPath("/WEB-INF"), axisConf);
@@ -175,6 +179,8 @@
             initProcessStore(eprContext);
             __log.debug("Initializing BPEL server.");
             initBpelServer(eprContext);
+            __log.debug("Initializing HTTP connection manager");
+            initHttpConnectionManager();
 
             // Register BPEL event listeners configured in axis2.properties file.
             registerEventListeners();
@@ -315,7 +321,14 @@
                     __log.error("Unable to cleanup temp files.", t);
                 }
             }
-            
+            if(httpConnectionManager!=null){
+                __log.debug("shutting down HTTP connection manager.");
+                try {
+                    httpConnectionManager.shutdown();
+                } catch(Throwable t) {
+                    __log.error("Unable to shut down HTTP connection manager.", t);
+                }
+            }
             try {
                 __log.debug("cleaning up temporary files.");
                 TempFileManager.cleanup();
@@ -369,10 +382,10 @@
         try {
             if (WsdlUtils.useHTTPBinding(def, serviceName, portName)) {
                 if(__log.isDebugEnabled())__log.debug("Creating HTTP-bound external service " + serviceName);
-                extService = new HttpExternalService(pconf, serviceName, portName, _executorService, _scheduler, _server);
+                extService = new HttpExternalService(pconf, serviceName, portName, _executorService, _scheduler, _server, httpConnectionManager);
             } else if (WsdlUtils.useSOAPBinding(def, serviceName, portName)) {
                 if(__log.isDebugEnabled())__log.debug("Creating SOAP-bound external service " + serviceName);
-                extService = new SoapExternalService(pconf, serviceName, portName, _executorService, _axisConfig, _scheduler, _server);
+                extService = new SoapExternalService(pconf, serviceName, portName, _executorService, _axisConfig, _scheduler, _server, httpConnectionManager);
             }
         } catch (Exception ex) {
             __log.error("Could not create external service.", ex);
@@ -530,6 +543,24 @@
         _server.init();
     }
 
+    private void initHttpConnectionManager() throws ServletException {
+        httpConnectionManager = new MultiThreadedHttpConnectionManager();
+        // settings may be overridden from ode-axis2.properties using the same properties as HttpClient 
+        int max_per_host = Integer.parseInt(_odeConfig.getProperty(HttpConnectionManagerParams.MAX_HOST_CONNECTIONS, "2"));
+        int max_total = Integer.parseInt(_odeConfig.getProperty(HttpConnectionManagerParams.MAX_TOTAL_CONNECTIONS, "20"));
+        if(__log.isDebugEnabled()) {
+            __log.debug(HttpConnectionManagerParams.MAX_HOST_CONNECTIONS+"="+max_per_host);
+            __log.debug(HttpConnectionManagerParams.MAX_TOTAL_CONNECTIONS+"="+max_total);
+        }
+        if(max_per_host<1 || max_total <1){
+            String errmsg = HttpConnectionManagerParams.MAX_HOST_CONNECTIONS+" and "+ HttpConnectionManagerParams.MAX_TOTAL_CONNECTIONS+" must be positive integers!";
+            __log.error(errmsg);
+            throw new ServletException(errmsg);
+        }
+        httpConnectionManager.getParams().setDefaultMaxConnectionsPerHost(max_per_host);
+        httpConnectionManager.getParams().setMaxTotalConnections(max_total);
+    }
+
     public ProcessStoreImpl getProcessStore() {
         return _store;
     }

Modified: ode/branches/APACHE_ODE_1.X/axis2/src/main/java/org/apache/ode/axis2/Properties.java
URL: http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.X/axis2/src/main/java/org/apache/ode/axis2/Properties.java?rev=749508&r1=749507&r2=749508&view=diff
==============================================================================
--- ode/branches/APACHE_ODE_1.X/axis2/src/main/java/org/apache/ode/axis2/Properties.java (original)
+++ ode/branches/APACHE_ODE_1.X/axis2/src/main/java/org/apache/ode/axis2/Properties.java Tue Mar  3 02:18:25 2009
@@ -20,6 +20,7 @@
 package org.apache.ode.axis2;
 
 import org.apache.axis2.Constants;
+import org.apache.axis2.util.JavaUtils;
 import org.apache.axis2.client.Options;
 import org.apache.axis2.transport.http.HTTPConstants;
 import org.apache.axis2.transport.http.HttpTransportProperties;
@@ -201,6 +202,11 @@
             if (headers != null && !headers.isEmpty()) options.setProperty(HTTPConstants.HTTP_HEADERS, headers);
             if (proxy != null) options.setProperty(HTTPConstants.PROXY, proxy);
 
+            // Set properties that canNOT be overridden
+            if(JavaUtils.isTrueExplicitly(options.getProperty(HTTPConstants.REUSE_HTTP_CLIENT))){
+                if (log.isWarnEnabled()) log.warn("This property cannot be overidden, and must always be false. "+ HTTPConstants.REUSE_HTTP_CLIENT);
+            }
+            options.setProperty(HTTPConstants.REUSE_HTTP_CLIENT, "false");
             return options;
         }
     }

Modified: ode/branches/APACHE_ODE_1.X/axis2/src/main/java/org/apache/ode/axis2/SoapExternalService.java
URL: http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.X/axis2/src/main/java/org/apache/ode/axis2/SoapExternalService.java?rev=749508&r1=749507&r2=749508&view=diff
==============================================================================
--- ode/branches/APACHE_ODE_1.X/axis2/src/main/java/org/apache/ode/axis2/SoapExternalService.java (original)
+++ ode/branches/APACHE_ODE_1.X/axis2/src/main/java/org/apache/ode/axis2/SoapExternalService.java Tue Mar  3 02:18:25 2009
@@ -32,9 +32,11 @@
 import org.apache.axis2.description.OutOnlyAxisOperation;
 import org.apache.axis2.engine.AxisConfiguration;
 import org.apache.axis2.transport.jms.JMSConstants;
+import org.apache.axis2.transport.http.HTTPConstants;
 import org.apache.axis2.wsdl.WSDLConstants;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
 import org.apache.neethi.Policy;
 import org.apache.neethi.PolicyEngine;
 import org.apache.ode.axis2.util.SoapMessageConverter;
@@ -100,7 +102,7 @@
     private ProcessConf _pconf;
 
     public SoapExternalService(ProcessConf pconf, QName serviceName, String portName, ExecutorService executorService,
-                               AxisConfiguration axisConfig, Scheduler sched, BpelServer server) throws AxisFault {
+                               AxisConfiguration axisConfig, Scheduler sched, BpelServer server, MultiThreadedHttpConnectionManager connManager) throws AxisFault {
         _definition = pconf.getDefinitionForService(serviceName);
         _serviceName = serviceName;
         _portName = portName;
@@ -115,6 +117,9 @@
         _axisServiceWatchDog = WatchDog.watchFile(fileToWatch, new ServiceFileObserver(fileToWatch));
         _axisOptionsWatchDog = new WatchDog<Map, OptionsObserver>(new EndpointPropertiesMutable(), new OptionsObserver());
         _configContext = new ConfigurationContext(_axisConfig);
+        _configContext.setProperty(HTTPConstants.MUTTITHREAD_HTTP_CONNECTION_MANAGER, connManager);
+        // make sure the client is not shared, see also org.apache.ode.axis2.Properties.Axis2
+        _configContext.setProperty(HTTPConstants.REUSE_HTTP_CLIENT, "false");
 
         // initial endpoint reference
         Element eprElmt = ODEService.genEPRfromWSDL(_definition, serviceName, portName);
@@ -131,7 +136,7 @@
 
             // Override options are passed to the axis MessageContext so we can
             // retrieve them in our session out changeHandler.
-            MessageContext mctx = new MessageContext();
+            final MessageContext mctx = new MessageContext();
             /* make the given options the parent so it becomes the defaults of the MessageContexgt. That allows the user to override
             *  specific options on a given message context and not affect the overall options.
             */
@@ -175,7 +180,12 @@
                         _executorService.submit(new Callable<Object>() {
                             public Object call() throws Exception {
                                 try {
-                                    operationClient.execute(true);
+                                    try {
+                                        operationClient.execute(true);
+                                    } finally {
+                                        // make sure the HTTP connection is released to the pool!
+                                        mctx.getTransportOut().getSender().cleanup(mctx);
+                                    }
                                     MessageContext response = operationClient.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
                                     MessageContext flt = operationClient.getMessageContext(WSDLConstants.MESSAGE_LABEL_FAULT_VALUE);
                                     if (response != null && __log.isDebugEnabled())

Modified: ode/branches/APACHE_ODE_1.X/axis2/src/main/java/org/apache/ode/axis2/httpbinding/HttpExternalService.java
URL: http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.X/axis2/src/main/java/org/apache/ode/axis2/httpbinding/HttpExternalService.java?rev=749508&r1=749507&r2=749508&view=diff
==============================================================================
--- ode/branches/APACHE_ODE_1.X/axis2/src/main/java/org/apache/ode/axis2/httpbinding/HttpExternalService.java (original)
+++ ode/branches/APACHE_ODE_1.X/axis2/src/main/java/org/apache/ode/axis2/httpbinding/HttpExternalService.java Tue Mar  3 02:18:25 2009
@@ -83,7 +83,9 @@
 
     protected Binding portBinding;
 
-    public HttpExternalService(ProcessConf pconf, QName serviceName, String portName, ExecutorService executorService, Scheduler scheduler, BpelServer server) {
+    public HttpExternalService(ProcessConf pconf, QName serviceName, String portName,
+                               ExecutorService executorService, Scheduler scheduler, BpelServer server,
+                               MultiThreadedHttpConnectionManager connManager) {
         if (log.isDebugEnabled())
             log.debug("new HTTP External service, service name=[" + serviceName + "]; port name=[" + portName + "]");
         this.portName = portName;
@@ -117,7 +119,7 @@
         endpointReference = EndpointFactory.convertToWSA(ODEService.createServiceRef(eprElmt));
 
         httpMethodConverter = new HttpMethodConverter(definition, serviceName, portName);
-        connections = new MultiThreadedHttpConnectionManager();
+        connections = connManager;
     }
 
     public String getPortName() {

Modified: ode/branches/APACHE_ODE_1.X/axis2/src/main/java/org/apache/ode/axis2/httpbinding/HttpHelper.java
URL: http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.X/axis2/src/main/java/org/apache/ode/axis2/httpbinding/HttpHelper.java?rev=749508&r1=749507&r2=749508&view=diff
==============================================================================
--- ode/branches/APACHE_ODE_1.X/axis2/src/main/java/org/apache/ode/axis2/httpbinding/HttpHelper.java (original)
+++ ode/branches/APACHE_ODE_1.X/axis2/src/main/java/org/apache/ode/axis2/httpbinding/HttpHelper.java Tue Mar  3 02:18:25 2009
@@ -105,7 +105,7 @@
                         && !"digest".equalsIgnoreCase(scheme)) {
                     throw new IllegalArgumentException("Unknown Authentication scheme: [" + scheme + "] Accepted values are: Basic, Digest, Server-Decides");
                 } else {
-                    if(log.isDebugEnabled()) log.debug("credentials provided");
+                    if(log.isDebugEnabled()) log.debug("credentials provided: scheme="+scheme+" user="+username+" password=********");
                     client.getState().setCredentials(
                             new AuthScope(targetURI.getHost(), targetURI.getPort(), AuthScope.ANY_REALM, scheme),
                             new UsernamePasswordCredentials(username, password));

Modified: ode/branches/APACHE_ODE_1.X/bpel-epr/src/main/java/org/apache/ode/il/config/OdeConfigProperties.java
URL: http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.X/bpel-epr/src/main/java/org/apache/ode/il/config/OdeConfigProperties.java?rev=749508&r1=749507&r2=749508&view=diff
==============================================================================
--- ode/branches/APACHE_ODE_1.X/bpel-epr/src/main/java/org/apache/ode/il/config/OdeConfigProperties.java (original)
+++ ode/branches/APACHE_ODE_1.X/bpel-epr/src/main/java/org/apache/ode/il/config/OdeConfigProperties.java Tue Mar  3 02:18:25 2009
@@ -247,11 +247,11 @@
     }
 
 
-    protected String getProperty(String pname) {
+    public String getProperty(String pname) {
         return _props.getProperty(_prefix + pname);
     }
 
-    protected String getProperty(String key, String dflt) {
+    public String getProperty(String key, String dflt) {
         return _props.getProperty(_prefix + key, dflt);
     }