You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by ba...@apache.org on 2008/02/19 20:58:33 UTC

svn commit: r629210 - in /webservices/axis2/trunk/java/modules/jaxws: src/org/apache/axis2/jaxws/handler/HandlerResolverImpl.java test/org/apache/axis2/jaxws/spi/ClientMetadataHandlerChainTest.java

Author: barrettj
Date: Tue Feb 19 11:58:28 2008
New Revision: 629210

URL: http://svn.apache.org/viewvc?rev=629210&view=rev
Log:
Add test for correct precedence between HandlerChain annotations on Service and Port and sparse composite overrides of same.  Fix logic to pass test.

Modified:
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/HandlerResolverImpl.java
    webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/spi/ClientMetadataHandlerChainTest.java

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/HandlerResolverImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/HandlerResolverImpl.java?rev=629210&r1=629209&r2=629210&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/HandlerResolverImpl.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/HandlerResolverImpl.java Tue Feb 19 11:58:28 2008
@@ -138,19 +138,59 @@
          * TODO: do a better job checking that the return value matches up
          * with the PortInfo object before we add it to the chain.
          */
+
+        // The HandlerChain annotation can be specified on:
+        // - a service implementation (per JSR-181) which is on the service-provider side
+        // - an SEI (per JSR-181), which can be on both the service-provider and 
+        //   service-requester sides
+        // - a generated Service (per JSR-224), which is on the service-requester side
+        //
+        // The order of precedence here is a bit counter intuitive if the HandlerChain annotation
+        // is present on more than one class.  
+        // - For the service-provider, JSR-181 [p. 25, Section 4.6.1]
+        //   states that the service implementation's HandlerChain takes is used if it is present
+        //   on both the implementation and the SEI.
+        // - Following that same pattern, we conclude that a generated service HandlerChain should
+        //   take precedence if the annotation is on both the Service and the SEI.
+        //
+        // The reasoning for this is (probably) that the SEI can be used by multiple endpoints 
+        // and / or multiple Service requesters, so the endpoint implementation and the Service
+        // should have the final say in what handlers are run, rather than the SEI.
+        //
+        // Adding Deployment Descriptors complicates this further.  A DD should have the absolute 
+        // final say (such as a JSR-109 client DD).  Given that, on a service-requester if the
+        // Service has a HandlerChain and the SEI has a HandlerChain and the DD specifies a 
+        // HandlerChain for a port, then the DD should win.  Since DDs are implented as information
+        // in a sparse composite, then that means the sparse composite wins.
         
+        // Get the HandlerChains specified on the Endpoint (service-provider) or on the Service
+        // (service-requester).
         handlerChainsType = serviceDesc.getHandlerChain(serviceDelegateKey);  
-        // if there's a handlerChain on the serviceDesc, it means the WSDL defined an import for a HandlerChain.
-        // the spec indicates that if a handlerchain also appears on the SEI on the client.
+
+        // HandlerChains apply to specific Port Compoments (service-provider) or Ports (
+        // (service-requesters) so find the appropriate one.
         EndpointDescription ed = null;
         if(portinfo !=null){
              ed = serviceDesc.getEndpointDescription(portinfo.getPortName());
         }
         
+        // Get the HandlerChain information, if any, off the SEI (service-provider or 
+        // service-requster) and check for any DD overrides.
         if (ed != null) {
-            HandlerChainsType handlerCT_fromEndpointDesc = ed.getHandlerChain(serviceDelegateKey);
-            if (handlerChainsType == null) {
-                handlerChainsType = handlerCT_fromEndpointDesc;
+            // If there was no handler chains information specifed on the endpoint (service-
+            // provider) or the Service (service-requester)
+            // -- OR -- 
+            // If the handler chains associated with a particular instance of a service delegate
+            // DOES NOT match the handler chains across all service delegates, then there was
+            // sparse composite information specified for this service delegate.  Sparse composite
+            // information is how Deployment Descriptor information is specified, and that 
+            // overrides the annotations as described in the long-winded comment above.
+            // -- THEN --
+            // Use this handler chains information
+            HandlerChainsType hct_includingComposite = ed.getHandlerChain(serviceDelegateKey);
+            HandlerChainsType hct_noComposite = ed.getHandlerChain();
+            if (handlerChainsType == null || (hct_includingComposite != hct_noComposite)) {
+                handlerChainsType = hct_includingComposite;
             } 
         } else {
             // There is no EndpointDescription that matches the portInfo specified so 

Modified: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/spi/ClientMetadataHandlerChainTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/spi/ClientMetadataHandlerChainTest.java?rev=629210&r1=629209&r2=629210&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/spi/ClientMetadataHandlerChainTest.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/spi/ClientMetadataHandlerChainTest.java Tue Feb 19 11:58:28 2008
@@ -27,6 +27,7 @@
 import javax.jws.WebService;
 import javax.xml.namespace.QName;
 import javax.xml.ws.Service;
+import javax.xml.ws.WebServiceClient;
 import javax.xml.ws.handler.Handler;
 import javax.xml.ws.handler.HandlerResolver;
 import javax.xml.ws.handler.PortInfo;
@@ -34,6 +35,7 @@
 
 import java.io.File;
 import java.io.InputStream;
+import java.net.URL;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
@@ -46,9 +48,9 @@
  */
 public class ClientMetadataHandlerChainTest extends TestCase {
     
-    private String namespaceURI = "http://www.apache.org/test/namespace";
-    private String svcLocalPart = "DummyService";
-    private String portLocalPart = "DummyPort";
+    static String namespaceURI = "http://www.apache.org/test/namespace";
+    static String svcLocalPart = "DummyService";
+    static private String portLocalPart = "DummyPort";
     private static int uniqueService = 0;
     
     /**
@@ -322,12 +324,12 @@
 
         Service service = Service.create(serviceQN);
         
-        ClientMetadatahandlerChainTestSEIWithHC port = service.getPort(ClientMetadatahandlerChainTestSEIWithHC.class);
+        ClientMetadataHandlerChainTestSEIWithHC port = service.getPort(ClientMetadataHandlerChainTestSEIWithHC.class);
         BindingProvider bindingProvider = (BindingProvider) port;
         Binding binding = (Binding) bindingProvider.getBinding();
         List<Handler> portHandlers = binding.getHandlerChain();
         assertEquals(1, portHandlers.size());
-        assertTrue(containsSeiHandlers(portHandlers));
+        assertTrue(containsHandlerChainAnnotationHandlers(portHandlers));
     }
     
     /**
@@ -344,7 +346,7 @@
         HandlerChainsType handlerChainsType = getHandlerChainsType();
         sparseComposite.setHandlerChainsType(handlerChainsType);
         ServiceDelegate.setPortMetadata(sparseComposite);
-        ClientMetadatahandlerChainTestSEIWithHC port = service.getPort(ClientMetadatahandlerChainTestSEIWithHC.class);
+        ClientMetadataHandlerChainTestSEIWithHC port = service.getPort(ClientMetadataHandlerChainTestSEIWithHC.class);
         BindingProvider bindingProvider = (BindingProvider) port;
         Binding binding = (Binding) bindingProvider.getBinding();
         List<Handler> portHandlers = binding.getHandlerChain();
@@ -366,7 +368,7 @@
         ServiceDelegate.setServiceMetadata(sparseComposite);
         Service service = Service.create(serviceQN);
 
-        ClientMetadatahandlerChainTestSEIWithHC port = service.getPort(ClientMetadatahandlerChainTestSEIWithHC.class);
+        ClientMetadataHandlerChainTestSEIWithHC port = service.getPort(ClientMetadataHandlerChainTestSEIWithHC.class);
         BindingProvider bindingProvider = (BindingProvider) port;
         Binding binding = (Binding) bindingProvider.getBinding();
         List<Handler> portHandlers = binding.getHandlerChain();
@@ -398,17 +400,53 @@
         Binding binding = (Binding) bindingProvider.getBinding();
         List<Handler> portHandlers = binding.getHandlerChain();
 
-        // If there is a HandlerChainsType on both the Service and the Port, then currently the
-        // handlers on the service are applied and the ones from the port are ignored.  It may be
-        // that behavior should be changed so the HandlerChainsType on the Port takes precedence.
-        // In the current User Stories in JSR-109 DDs, there should not be deployment information
-        // for both a service and port, since the DD information is specified as a single 
-        // <service-ref>, which can only be one or the other, not both.
-        assertEquals(2, portHandlers.size());
-        assertTrue(containsSparseCompositeHandlers(portHandlers));
+        // If there is a HandlerChainsType composite specified on both the Service and the Port,
+        // then the composite specified on the Port should be the one used to associate the 
+        // handlers for that Port.
+        assertEquals(1, portHandlers.size());
+        assertTrue(containsHandlerChainAnnotationHandlers(portHandlers));
     }
     
+    /**
+     * Verfiy that a HandlerChain annotation on the Service is associated with the Port 
+     */
+    public void testGeneratedServiceWithHC() {
+        ClientMetadataHandlerChainTestServiceWithHC service = new ClientMetadataHandlerChainTestServiceWithHC();
+        ClientMetadataHandlerChainTestSEI port = service.getPort(ClientMetadataHandlerChainTestSEI.class);
+
+        BindingProvider bindingProvider = (BindingProvider) port;
+        Binding binding = (Binding) bindingProvider.getBinding();
+        List<Handler> portHandlers = binding.getHandlerChain();
+        assertEquals(1, portHandlers.size());
+        assertTrue(containsHandlerChainAnnotationHandlers(portHandlers));
+
+    }
     
+    /**
+     * Verfiy that given a HandlerChain annotation on the Service and a Port and a sparse composite
+     * on the Port associates the handlers from the sparse composite on the Port.
+     */
+    public void testGeneratedServiceWithHCPortOverride() {
+        ClientMetadataHandlerChainTestServiceWithHC service = new ClientMetadataHandlerChainTestServiceWithHC();
+
+        // Set a HandlerChainsType on the sparse composite for the Port creation; it should override the 
+        // HandlerChain annotation on the Service.
+        DescriptionBuilderComposite sparseComposite = new DescriptionBuilderComposite();
+        HandlerChainsType handlerChainsType = getHandlerChainsType();
+        sparseComposite.setHandlerChainsType(handlerChainsType);
+        ServiceDelegate.setPortMetadata(sparseComposite);
+        ClientMetadataHandlerChainTestSEI port = service.getPort(ClientMetadataHandlerChainTestSEI.class);
+
+        BindingProvider bindingProvider = (BindingProvider) port;
+        Binding binding = (Binding) bindingProvider.getBinding();
+        List<Handler> portHandlers = binding.getHandlerChain();
+        assertEquals(2, portHandlers.size());
+        assertTrue(containsSparseCompositeHandlers(portHandlers));
+    }
+
+    // =============================================================================================
+    // Helper methods and classes
+    // =============================================================================================
     private boolean containsSparseCompositeHandlers(List<Handler> handlerList) {
         List<Class> inputHandlerClasses = handlerClasses(handlerList);
 
@@ -436,7 +474,7 @@
      * @return true if the list matches what was defined on the SEI via the
      *   HandlerChain annotation; false otherwise.
      */
-    private boolean containsSeiHandlers(List<Handler> portHandlers) {
+    private boolean containsHandlerChainAnnotationHandlers(List<Handler> portHandlers) {
         List<Class> portHandlerClasses = handlerClasses(portHandlers);
         List<Class> seiHandlerClasses = new ArrayList<Class>();
         seiHandlerClasses.add(ClientMetadataHandlerChainHandler.class);
@@ -544,6 +582,18 @@
 
 @WebService
 @HandlerChain(file="ClientMetadataHandlerChainTest.xml")
-interface ClientMetadatahandlerChainTestSEIWithHC {
+interface ClientMetadataHandlerChainTestSEIWithHC {
     public String echo(String toEcho);
-}
\ No newline at end of file
+}
+
+@WebServiceClient
+@HandlerChain(file="ClientMetadataHandlerChainTest.xml")
+class ClientMetadataHandlerChainTestServiceWithHC extends javax.xml.ws.Service {
+        public ClientMetadataHandlerChainTestServiceWithHC() {
+            super(null,
+                  new QName(ClientMetadataHandlerChainTest.namespaceURI, ClientMetadataHandlerChainTest.svcLocalPart));
+        }
+        public ClientMetadataHandlerChainTestServiceWithHC(URL wsdlLocation, QName serviceName) {
+            super(wsdlLocation, serviceName);
+        }
+}



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