You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by an...@apache.org on 2007/04/23 12:52:35 UTC

svn commit: r531422 - in /incubator/tuscany/java/sca/modules/binding-ws-axis2: ./ src/main/java/org/apache/tuscany/binding/axis2/

Author: antelder
Date: Mon Apr 23 03:52:22 2007
New Revision: 531422

URL: http://svn.apache.org/viewvc?view=rev&rev=531422
Log:
TUSCANY-1218, apply fix from Simon Nash to fix java.net.ConnectException: Connection refused problem

Modified:
    incubator/tuscany/java/sca/modules/binding-ws-axis2/pom.xml
    incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2BindingBuilder.java
    incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ModuleActivator.java
    incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ReferenceBinding.java
    incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ServiceBinding.java
    incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2TargetInvoker.java

Modified: incubator/tuscany/java/sca/modules/binding-ws-axis2/pom.xml
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-ws-axis2/pom.xml?view=diff&rev=531422&r1=531421&r2=531422
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-ws-axis2/pom.xml (original)
+++ incubator/tuscany/java/sca/modules/binding-ws-axis2/pom.xml Mon Apr 23 03:52:22 2007
@@ -168,7 +168,7 @@
                <groupId>commons-httpclient</groupId>
                <artifactId>commons-httpclient</artifactId>
                <version>3.0.1</version>
-               <scope>runtime</scope>
+               <scope>compile</scope>
             </dependency>
 
             <dependency>

Modified: incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2BindingBuilder.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2BindingBuilder.java?view=diff&rev=531422&r1=531421&r2=531422
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2BindingBuilder.java (original)
+++ incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2BindingBuilder.java Mon Apr 23 03:52:22 2007
@@ -20,6 +20,7 @@
 
 import java.net.URI;
 import java.util.List;
+import java.util.ArrayList;
 
 import javax.wsdl.Port;
 import javax.wsdl.extensions.soap.SOAPAddress;
@@ -46,19 +47,35 @@
  */
 public class Axis2BindingBuilder extends BindingBuilderExtension<WebServiceBinding> {
 
-    // TODO: what to do about the base URI?
-    private static final String BASE_URI = "http://localhost:8080/";
-
     private ServletHostExtensionPoint servletHost;
-
     private ConfigurationContext configContext;
-//
-//    private WorkContext workContext;
+
+    // track reference bindings and service bindings so that resources can be released
+    // needed because the stop methods in ReferenceImpl and ServiceImpl aren't being called
+    // TODO: revisit this as part of the lifecycle work
+    private List<ReferenceBinding> referenceBindings = new ArrayList<ReferenceBinding>();
+    private List<ServiceBinding> serviceBindings = new ArrayList<ServiceBinding>();
+
+    // TODO: what to do about the base URI?
+    private static final String BASE_URI = "http://localhost:8080/";
 
     public Axis2BindingBuilder() {
         initAxis();
     }
 
+    // release resources held by bindings
+    // called by stop method of Axis2ModuleActivator
+    // needed because the stop methods in ReferenceImpl and ServiceImpl aren't being called
+    // TODO: revisit this as part of the lifecycle work
+    protected void destroy() {
+       for (ReferenceBinding binding : referenceBindings) {
+          binding.stop();
+       }
+       for (ServiceBinding binding : serviceBindings) {
+          binding.stop();
+       }
+    }
+
     public void setServletHost(ServletHostExtensionPoint servletHost) {
         this.servletHost = servletHost;
     }
@@ -71,18 +88,21 @@
     @Override
     public ReferenceBinding build(CompositeReference compositeReference, WebServiceBinding wsBinding, DeploymentContext context) throws BuilderException {
 
-        // Set to use the Axiom data binding 
         InterfaceContract contract = wsBinding.getBindingInterfaceContract();
         if (contract == null) {
             contract = compositeReference.getInterfaceContract();
             wsBinding.setBindingInterfaceContract(contract);
         }
+
+        // Set to use the Axiom data binding 
         contract.getInterface().setDefaultDataBinding(OMElement.class.getName());        
 
         URI targetURI = wsBinding.getURI() != null ? URI.create(wsBinding.getURI()) : URI.create("foo");
         URI name = URI.create(context.getComponentId() + "#" + compositeReference.getName());
 
-        return new Axis2ReferenceBinding(name, targetURI, wsBinding);
+        ReferenceBinding referenceBinding = new Axis2ReferenceBinding(name, targetURI, wsBinding);
+        referenceBindings.add(referenceBinding); // track binding so that its resources can be released
+        return referenceBinding;
     }
 
     @Override
@@ -98,14 +118,15 @@
         contract.getInterface().setDefaultDataBinding(OMElement.class.getName());
 
         URI uri = computeActualURI(wsBinding, BASE_URI, compositeService).normalize();
+        
+        // TODO: if <binding.ws> specifies the wsdl service then should create a service for every port
 
-        ServiceBinding serviceBinding = new Axis2ServiceBinding(uri, wsBinding, servletHost, configContext, null);
-
+        ServiceBinding serviceBinding = new Axis2ServiceBinding(uri, wsBinding, servletHost, configContext);
+        serviceBindings.add(serviceBinding); // track binding so that its resources can be released
         return serviceBinding;
     }
 
     protected void initAxis() {
-        // TODO: consider having a system component wrapping the Axis2 ConfigContext
         try {
             this.configContext = new TuscanyAxisConfigurator().getConfigurationContext();
         } catch (AxisFault e) {
@@ -203,8 +224,8 @@
      */
     protected URI getEndpoint(Port wsdlPort) {
         if (wsdlPort != null) {
-            final List wsdlPortExtensions = wsdlPort.getExtensibilityElements();
-            for (final Object extension : wsdlPortExtensions) {
+            List wsdlPortExtensions = wsdlPort.getExtensibilityElements();
+            for (Object extension : wsdlPortExtensions) {
                 if (extension instanceof SOAPAddress) {
                     return URI.create(((SOAPAddress) extension).getLocationURI());
                 }

Modified: incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ModuleActivator.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ModuleActivator.java?view=diff&rev=531422&r1=531421&r2=531422
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ModuleActivator.java (original)
+++ incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ModuleActivator.java Mon Apr 23 03:52:22 2007
@@ -30,6 +30,8 @@
 
 public class Axis2ModuleActivator implements ModuleActivator {
 
+    private Axis2BindingBuilder builder;
+
     public void start(ExtensionPointRegistry extensionPointRegistry) {
 
         StAXArtifactProcessorExtensionPoint artifactProcessorRegistry = extensionPointRegistry.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
@@ -38,7 +40,7 @@
         ServletHostExtensionPoint servletHost = extensionPointRegistry.getExtensionPoint(ServletHostExtensionPoint.class);
         
         BuilderRegistry builderRegistry = extensionPointRegistry.getExtensionPoint(BuilderRegistry.class);
-        Axis2BindingBuilder builder = new Axis2BindingBuilder();
+        builder = new Axis2BindingBuilder();
         builder.setBuilderRegistry(builderRegistry);
         builder.setServletHost(servletHost);
         builder.init();
@@ -46,6 +48,10 @@
     }
 
     public void stop(ExtensionPointRegistry registry) {
+        // release resources held by bindings
+        // needed because the stop methods in ReferenceImpl and ServiceImpl aren't being called
+        // TODO: revisit this as part of the lifecycle work
+        builder.destroy(); // release connections
     }
 
     public Map<Class, Object> getExtensionPoints() {

Modified: incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ReferenceBinding.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ReferenceBinding.java?view=diff&rev=531422&r1=531421&r2=531422
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ReferenceBinding.java (original)
+++ incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ReferenceBinding.java Mon Apr 23 03:52:22 2007
@@ -37,11 +37,13 @@
 import org.apache.axis2.context.ConfigurationContext;
 import org.apache.axis2.description.AxisService;
 import org.apache.axis2.transport.http.HTTPConstants;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
 import org.apache.tuscany.binding.ws.WebServiceBinding;
 import org.apache.tuscany.binding.ws.xml.WebServiceConstants;
+import org.apache.tuscany.interfacedef.InterfaceContract;
 import org.apache.tuscany.interfacedef.Operation;
 import org.apache.tuscany.spi.component.TargetInvokerCreationException;
-import org.apache.tuscany.spi.component.WorkContext;
 import org.apache.tuscany.spi.extension.ReferenceBindingExtension;
 import org.apache.tuscany.spi.wire.TargetInvoker;
 
@@ -50,7 +52,6 @@
  */
 public class Axis2ReferenceBinding extends ReferenceBindingExtension {
 
-    private WorkContext workContext;
     private ServiceClient serviceClient;
     private WebServiceBinding wsBinding;
 
@@ -61,54 +62,54 @@
         this.bindingServiceContract = wsBinding.getBindingInterfaceContract();
     }
 
+    public void stop() {
+        // close all connections that we have initiated, so that the jetty server
+        // can be restarted without seeing ConnectExceptions
+        HttpClient httpClient = (HttpClient)serviceClient.getServiceContext().getConfigurationContext()
+                .getProperty(HTTPConstants.CACHED_HTTP_CLIENT);
+        if (httpClient != null) {
+            ((MultiThreadedHttpConnectionManager)httpClient.getHttpConnectionManager()).shutdown();
+        }
+        super.stop();
+    }
+
     public QName getBindingType() {
         return WebServiceConstants.BINDING_WS_QNAME;
     }
 
     public TargetInvoker createTargetInvoker(String targetName, Operation operation, boolean isCallback) throws TargetInvokerCreationException {
         Axis2TargetInvoker invoker;
-//        boolean operationHasCallback = operation.getInterface().contract.getCallbackInterface() != null;
-// TODO: this isn't right, need to get the InterfaceContract         
-        if (isCallback) {
-            // FIXME: SDODataBinding needs to pass in TypeHelper and classLoader
-            // as parameters.
-            Axis2AsyncTargetInvoker asyncInvoker =
-                (Axis2AsyncTargetInvoker) createOperationInvoker(serviceClient,
-                    operation,
-                    true,
-                    false);
-            // FIXME: This makes the (BIG) assumption that there is only one
-            // callback method
-            // Relaxing this assumption, however, does not seem to be trivial,
-            // it may depend on knowledge
-            // of what actual callback method was invoked by the service at the
-            // other end
-//            Operation callbackOperation = findCallbackOperation();
-            Operation callbackOperation = null;
-            Axis2CallbackInvocationHandler invocationHandler =
-                new Axis2CallbackInvocationHandler(wire);
+
+        if (wsBinding.getBindingInterfaceContract().getCallbackInterface() == null) {
+            invoker = createOperationInvoker(serviceClient, operation, false, operation.isNonBlocking());
+        } else {
+            // FIXME: SDODataBinding needs to pass in TypeHelper and classLoader as parameters.
+
+            // FIXME: This makes the (BIG) assumption that there is only one callback method
+            // Relaxing this assumption, however, does not seem to be trivial, it may depend on knowledge
+            // of what actual callback method was invoked by the service at the other end
+            Operation callbackOperation = findCallbackOperation();
+            Axis2CallbackInvocationHandler invocationHandler = new Axis2CallbackInvocationHandler(wire);
             Axis2ReferenceCallbackTargetInvoker callbackInvoker =
                 new Axis2ReferenceCallbackTargetInvoker(callbackOperation, wire, invocationHandler);
-            asyncInvoker.setCallbackTargetInvoker(callbackInvoker);
 
+            Axis2AsyncTargetInvoker asyncInvoker = 
+                (Axis2AsyncTargetInvoker) createOperationInvoker(serviceClient, operation, true, false);
+            asyncInvoker.setCallbackTargetInvoker(callbackInvoker);
             invoker = asyncInvoker;
-        } else {
-            invoker = createOperationInvoker(serviceClient, operation, false, operation.isNonBlocking());
         }
         return invoker;
     }
 
-//    private Operation findCallbackOperation() {
-//        ServiceContract contract = wire.getTargetContract(); // TODO: which end?
-//        Operation callbackOperation = null;
-//        Collection callbackOperations = contract.getCallbackOperations().values();
-//        if (callbackOperations.size() != 1) {
-//            throw new Axis2BindingRunTimeException("Can only handle one callback operation");
-//        } else {
-//            callbackOperation = (Operation) callbackOperations.iterator().next();
-//        }
-//        return callbackOperation;
-//    }
+    private Operation findCallbackOperation() {
+        InterfaceContract contract = wire.getTargetContract(); // TODO: which end?
+        List callbackOperations = contract.getCallbackInterface().getOperations();
+        if (callbackOperations.size() != 1) {
+            throw new RuntimeException("Can only handle one callback operation");
+        }
+        Operation callbackOperation = (Operation) callbackOperations.get(0);
+        return callbackOperation;
+    }
 
     /**
      * Create an Axis2 ServiceClient
@@ -149,7 +150,7 @@
             options.setAction(soapAction);
         }
 
-        options.setTimeOutInMilliSeconds(5 * 60 * 1000);
+        options.setTimeOutInMilliSeconds(30 * 1000); // 30 seconds
 
         SOAPFactory soapFactory = OMAbstractFactory.getSOAP11Factory();
         QName wsdlOperationQName = new QName(wsBinding.getNamespace(), operationName);

Modified: incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ServiceBinding.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ServiceBinding.java?view=diff&rev=531422&r1=531421&r2=531422
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ServiceBinding.java (original)
+++ incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ServiceBinding.java Mon Apr 23 03:52:22 2007
@@ -21,7 +21,6 @@
 import static org.osoa.sca.Constants.SCA_NS;
 
 import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
 import java.net.URI;
 import java.util.Collections;
 import java.util.HashMap;
@@ -53,7 +52,6 @@
 import org.apache.tuscany.interfacedef.Operation;
 import org.apache.tuscany.interfacedef.Operation.ConversationSequence;
 import org.apache.tuscany.spi.Scope;
-import org.apache.tuscany.spi.builder.BuilderConfigException;
 import org.apache.tuscany.spi.component.TargetInvokerCreationException;
 import org.apache.tuscany.spi.component.WorkContext;
 import org.apache.tuscany.spi.component.WorkContextTunnel;
@@ -69,11 +67,10 @@
  * An implementation of a {@link ServiceBindingExtension} configured with the Axis2 binding
  */
 public class Axis2ServiceBinding extends ServiceBindingExtension {
+
     private ConfigurationContext configContext;
     private WebServiceBinding wsBinding;
     private Map<Object, InvocationContext> invCtxMap = new HashMap<Object, InvocationContext>();
-    private String serviceName;
-//    private WorkContext workContext;
     private Set<String> seenConversations = Collections.synchronizedSet(new HashSet<String>());
     private ServletHostExtensionPoint servletHost;
 
@@ -82,8 +79,7 @@
     public Axis2ServiceBinding(URI uri,
                                WebServiceBinding wsBinding,
                                ServletHostExtensionPoint servletHost,
-                               ConfigurationContext configContext,
-                               WorkContext workContext) {
+                               ConfigurationContext configContext) {
 
         super(uri);
 
@@ -91,8 +87,6 @@
         this.wsBinding = wsBinding;
         this.servletHost = servletHost;
         this.configContext = configContext;
-        this.serviceName = uri.toString(); // TODO: whats this for, better name
-//        this.workContext = workContext;
 
         start(); // TODO: hack while start isn't getting called by runtime 
     }
@@ -112,7 +106,6 @@
         servletHost.addServletMapping(8080, getUri().getPath(), servlet);
     }
 
-    @Destroy
     public void stop() {
         servletHost.removeServletMapping(8080, getUri().getPath());
         try {
@@ -264,24 +257,6 @@
                 workContext.clearIdentifier(Scope.CONVERSATION);
             }
         }
-    }
-
-    protected Object getFromAddress() {
-        return this.serviceName;
-    }
-
-    /**
-     * Get the Method from an interface matching the WSDL operation name
-     */
-    protected Method getMethod(Class<?> serviceInterface, String operationName) throws BuilderConfigException {
-        for (Method m : serviceInterface.getMethods()) {
-            if (m.getName().equalsIgnoreCase(operationName)) {
-                return m;
-            }
-        }
-        throw new BuilderConfigException("no operation named " + operationName
-            + " found on service interface: "
-            + serviceInterface.getName());
     }
 
     public QName getBindingType() {

Modified: incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2TargetInvoker.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2TargetInvoker.java?view=diff&rev=531422&r1=531421&r2=531422
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2TargetInvoker.java (original)
+++ incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2TargetInvoker.java Mon Apr 23 03:52:22 2007
@@ -39,6 +39,7 @@
 import org.apache.tuscany.spi.Scope;
 import org.apache.tuscany.spi.component.WorkContext;
 import org.apache.tuscany.spi.extension.TargetInvokerExtension;
+import org.apache.axis2.transport.http.HTTPConstants;
 
 /**
  * Axis2TargetInvoker uses an Axis2 OperationClient to invoke a remote web service
@@ -66,6 +67,10 @@
             Object[] args = (Object[]) payload;
             OperationClient operationClient = createOperationClient(args, workContext);
 
+            // ensure connections are tracked so that they can be closed by the reference binding
+            MessageContext requestMC = operationClient.getMessageContext(WSDLConstants.MESSAGE_LABEL_OUT_VALUE);
+            requestMC.getOptions().setProperty(HTTPConstants.REUSE_HTTP_CLIENT, Boolean.TRUE);
+            
             operationClient.execute(true);
 
             MessageContext responseMC = operationClient.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org