axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wood...@apache.org
Subject svn commit: r633234 [21/24] - in /webservices/axis2/trunk/java: ./ modules/jaxws-integration/ modules/jaxws-integration/test/ modules/jaxws-integration/test/client/ modules/jaxws-integration/test/org/ modules/jaxws-integration/test/org/apache/ modules/...
Date Mon, 03 Mar 2008 18:48:24 GMT
Added: webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/spi/ClientMetadataHandlerChainHandler.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/spi/ClientMetadataHandlerChainHandler.java?rev=633234&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/spi/ClientMetadataHandlerChainHandler.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/spi/ClientMetadataHandlerChainHandler.java Mon Mar  3 10:47:38 2008
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.axis2.jaxws.spi;
+
+import java.util.Set;
+
+import javax.xml.ws.handler.MessageContext;
+import javax.xml.ws.handler.MessageContext.Scope;
+import javax.xml.ws.handler.soap.SOAPMessageContext;
+
+/*
+ * You can't actually specify whether a handler is for client or server,
+ * you just have to check in the handleMessage and/or handleFault to make
+ * sure what direction we're going.
+ */
+
+public class ClientMetadataHandlerChainHandler implements javax.xml.ws.handler.soap.SOAPHandler<SOAPMessageContext> {
+
+    public void close(MessageContext messagecontext) {
+    }
+
+    public boolean handleFault(SOAPMessageContext messagecontext) {
+        return true;
+    }
+
+    public Set getHeaders() {
+        return null;
+    }
+
+    public boolean handleMessage(SOAPMessageContext messagecontext) {
+        return true;
+    }
+
+}

Added: webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/spi/ClientMetadataHandlerChainTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/spi/ClientMetadataHandlerChainTest.java?rev=633234&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/spi/ClientMetadataHandlerChainTest.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/spi/ClientMetadataHandlerChainTest.java Mon Mar  3 10:47:38 2008
@@ -0,0 +1,599 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.axis2.jaxws.spi;
+
+import org.apache.axis2.jaxws.description.builder.DescriptionBuilderComposite;
+import org.apache.axis2.jaxws.description.builder.HandlerChainAnnot;
+import org.apache.axis2.jaxws.description.impl.DescriptionUtils;
+import org.apache.axis2.jaxws.description.xml.handler.HandlerChainsType;
+
+import javax.jws.HandlerChain;
+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;
+import javax.xml.ws.soap.SOAPBinding;
+
+import java.io.File;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+/**
+ * Verify that handler chains specified using the HandlerChainsType in a sparse
+ * composite are correctly applied to Services and Ports on the client requester. 
+ */
+public class ClientMetadataHandlerChainTest extends TestCase {
+    
+    static String namespaceURI = "http://www.apache.org/test/namespace";
+    static String svcLocalPart = "DummyService";
+    static private String portLocalPart = "DummyPort";
+    private static int uniqueService = 0;
+    
+    /**
+     *  Test creating a service without a sparse composite.  This verifies pre-existing default
+     *  behavior.
+     */
+    public void testServiceAndPortNoComposite() {
+        QName serviceQName = new QName(namespaceURI, svcLocalPart);
+        QName portQName = new QName(namespaceURI, portLocalPart);
+
+        Service service = Service.create(serviceQName);
+        HandlerResolver resolver = service.getHandlerResolver();
+        assertNotNull(resolver);
+        PortInfo pi = new DummyPortInfo();
+        List<Handler> list = resolver.getHandlerChain(pi);
+        assertEquals(0, list.size());
+        
+        ClientMetadataHandlerChainTestSEI port = service.getPort(portQName, ClientMetadataHandlerChainTestSEI.class);
+        // Verify that ports created under the service have no handlers from the sparse composite
+        BindingProvider bindingProvider = (BindingProvider) port;
+        Binding binding = (Binding) bindingProvider.getBinding();
+        List<Handler> portHandlers = binding.getHandlerChain();
+        assertEquals(0, portHandlers.size());
+    }
+
+    /**
+     * Test creating a service with a sparse composite that contains handler configuration
+     * information for this service delegate.  Verify that the handlers are included in the 
+     * chain.
+     */
+    public void testServiceWithComposite() {
+        QName serviceQName = new QName(namespaceURI, svcLocalPart);
+        QName portQName = new QName(namespaceURI, portLocalPart);
+        // Create a composite with a JAXB Handler Config 
+        DescriptionBuilderComposite sparseComposite = new DescriptionBuilderComposite();
+        HandlerChainsType handlerChainsType = getHandlerChainsType();
+        sparseComposite.setHandlerChainsType(handlerChainsType);
+
+        ServiceDelegate.setServiceMetadata(sparseComposite);
+        Service service = Service.create(serviceQName);
+        ClientMetadataHandlerChainTestSEI port = service.getPort(portQName, ClientMetadataHandlerChainTestSEI.class);
+
+        // Verify the HandlerResolver on the service knows about the handlers in the sparse composite
+        HandlerResolver resolver = service.getHandlerResolver();
+        assertNotNull(resolver);
+        PortInfo pi = new DummyPortInfo();
+        List<Handler> list = resolver.getHandlerChain(pi);
+        assertEquals(2, list.size());
+        
+        // Verify that ports created under the service have handlers
+        BindingProvider bindingProvider = (BindingProvider) port;
+        Binding binding = (Binding) bindingProvider.getBinding();
+        List<Handler> portHandlers = binding.getHandlerChain();
+        assertEquals(2, portHandlers.size());
+        assertTrue(containSameHandlers(portHandlers, list));
+        
+        // Verify that a subsequent port are different and that they also gets the correct handlers
+        ClientMetadataHandlerChainTestSEI port2 = service.getPort(portQName, ClientMetadataHandlerChainTestSEI.class);
+        BindingProvider bindingProvider2 = (BindingProvider) port2;
+        Binding binding2 = (Binding) bindingProvider2.getBinding();
+        List<Handler> portHandlers2 = binding2.getHandlerChain();
+        assertNotSame(port, port2);
+        assertEquals(2, portHandlers2.size());
+        assertTrue(containSameHandlers(portHandlers2, list));
+    }
+    
+    /**
+     * Set a sparse composite on a specific Port.  Verify that instances of that Port have the
+     * correct handlers associated and other Ports do not.
+     */
+    public void testPortWithComposite() {
+        QName serviceQName = new QName(namespaceURI, svcLocalPart);
+        QName portQName = new QName(namespaceURI, portLocalPart);
+
+        Service service = Service.create(serviceQName);
+        
+        // Create a composite with a JAXB Handler Config 
+        DescriptionBuilderComposite sparseComposite = new DescriptionBuilderComposite();
+        HandlerChainsType handlerChainsType = getHandlerChainsType();
+        sparseComposite.setHandlerChainsType(handlerChainsType);
+        ServiceDelegate.setPortMetadata(sparseComposite);
+        ClientMetadataHandlerChainTestSEI port = service.getPort(portQName, ClientMetadataHandlerChainTestSEI.class);
+
+        // Verify the HandlerResolver on the service knows about the handlers in the sparse composite
+        HandlerResolver resolver = service.getHandlerResolver();
+        assertNotNull(resolver);
+        PortInfo pi = new DummyPortInfo();
+        List<Handler> list = resolver.getHandlerChain(pi);
+        assertEquals(2, list.size());
+        
+        // Verify that the port created with the sparse metadata has those handlers
+        BindingProvider bindingProvider = (BindingProvider) port;
+        Binding binding = (Binding) bindingProvider.getBinding();
+        List<Handler> portHandlers = binding.getHandlerChain();
+        assertEquals(2, portHandlers.size());
+        assertTrue(containSameHandlers(portHandlers, list));
+        
+        // Verify that a creating another instance of the same port also gets those handlers
+        ClientMetadataHandlerChainTestSEI port2 = service.getPort(portQName, ClientMetadataHandlerChainTestSEI.class);
+        BindingProvider bindingProvider2 = (BindingProvider) port2;
+        Binding binding2 = (Binding) bindingProvider2.getBinding();
+        List<Handler> portHandlers2 = binding2.getHandlerChain();
+        assertNotSame(port, port2);
+        assertEquals(2, portHandlers2.size());
+        assertTrue(containSameHandlers(portHandlers2, list));
+        
+        // Verify that createing a different port doesn't get the handlers
+        QName portQName3 = new QName(namespaceURI, portLocalPart + "3");
+        ClientMetadataHandlerChainTestSEI port3 = service.getPort(portQName3, ClientMetadataHandlerChainTestSEI.class);
+        BindingProvider bindingProvider3 = (BindingProvider) port3;
+        Binding binding3 = (Binding) bindingProvider3.getBinding();
+        List<Handler> portHandlers3 = binding3.getHandlerChain();
+        assertEquals(0, portHandlers3.size());
+        
+        // Verify setting the metadata on a different port (a different QName) will get handlers.
+        QName portQName4 = new QName(namespaceURI, portLocalPart + "4");
+        ServiceDelegate.setPortMetadata(sparseComposite);
+        ClientMetadataHandlerChainTestSEI port4 = service.getPort(portQName4, ClientMetadataHandlerChainTestSEI.class);
+        BindingProvider bindingProvider4 = (BindingProvider) port4;
+        Binding binding4 = (Binding) bindingProvider4.getBinding();
+        List<Handler> portHandlers4 = binding4.getHandlerChain();
+        assertEquals(2, portHandlers4.size());
+        
+        // Verify the service handler resolver knows about boths sets of handlers
+        // attached to the two different port QNames and none are attached for the third port
+        List<Handler> listForPort = resolver.getHandlerChain(pi);
+        assertEquals(2, listForPort.size());
+
+        PortInfo pi4 = new DummyPortInfo(portQName4);
+        List<Handler> listForPort4 = resolver.getHandlerChain(pi4);
+        assertEquals(2, listForPort4.size());
+        
+        PortInfo pi3 = new DummyPortInfo(portQName3);
+        List<Handler> listForPort3 = resolver.getHandlerChain(pi3);
+        assertEquals(0, listForPort3.size());
+    }
+    
+    /**
+     * Verify that handlers specified in a sparse compoiste on the service are only associated with 
+     * that specific service delegate (i.e. Service instance), even if the QNames are the same 
+     * across two instances of a Service.
+     */
+    public void testMultipleServiceDelgatesServiceComposite() {
+        try {
+            // Need to cache the ServiceDescriptions so that they are shared
+            // across the two instances of the same Service.
+            ClientMetadataTest.installCachingFactory();
+            
+            QName serviceQName = new QName(namespaceURI, svcLocalPart);
+            PortInfo pi = new DummyPortInfo();
+
+            // Create a Service specifying a sparse composite and verify the
+            // ports under that service get the correct handlers associated.
+            DescriptionBuilderComposite sparseComposite = new DescriptionBuilderComposite();
+            HandlerChainsType handlerChainsType = getHandlerChainsType();
+            sparseComposite.setHandlerChainsType(handlerChainsType);
+            ServiceDelegate.setServiceMetadata(sparseComposite);
+            Service service1 = Service.create(serviceQName);
+
+            // Create a second instance of the same Service, but without
+            // metadata. Ports created under that service should not get handler's associated.
+            Service service2 = Service.create(serviceQName);
+
+            // No ports created yet, so there should be no relevant handler
+            // chains.
+            HandlerResolver resolver1 = service1.getHandlerResolver();
+            List<Handler> list1 = resolver1.getHandlerChain(pi);
+            assertEquals(0, list1.size());
+
+            // Create the port, it should get handlers.
+            QName portQName1 = new QName(namespaceURI, portLocalPart);
+            ClientMetadataHandlerChainTestSEI port1 =
+                    service1.getPort(portQName1, ClientMetadataHandlerChainTestSEI.class);
+            BindingProvider bindingProvider1 = (BindingProvider) port1;
+            Binding binding1 = (Binding) bindingProvider1.getBinding();
+            List<Handler> portHandlers1 = binding1.getHandlerChain();
+            assertEquals(2, portHandlers1.size());
+            
+            // Refresh the handler list from the resolver after the port is created
+            list1 = resolver1.getHandlerChain(pi);
+            assertTrue(containSameHandlers(portHandlers1, list1));
+
+            // Make sure the 2nd Service instance doesn't have handlers
+            // associated with it
+            HandlerResolver resolver2 = service2.getHandlerResolver();
+            List<Handler> list2 = resolver2.getHandlerChain(pi);
+            assertEquals(0, list2.size());
+
+            // Make sure the same port created under the 2nd service also
+            // doesn't have handlers
+            ClientMetadataHandlerChainTestSEI port2 =
+                    service2.getPort(portQName1, ClientMetadataHandlerChainTestSEI.class);
+            BindingProvider bindingProvider2 = (BindingProvider) port2;
+            Binding binding2 = (Binding) bindingProvider2.getBinding();
+            List<Handler> portHandlers2 = binding2.getHandlerChain();
+            assertEquals(0, portHandlers2.size());
+        }
+        finally {
+            ClientMetadataTest.restoreOriginalFactory();
+        }
+    }
+
+    /**
+     * Verify that handlers specified in a sparse compoiste on the port are only associated with 
+     * that port on that specific service delegate (i.e. Service instance), even if the QNames are the same 
+     * across two instances of a Service.
+     */
+    public void testMultipleServiceDelgatesPortComposite() {
+        try {
+            // Need to cache the ServiceDescriptions so that they are shared
+            // across the two instances of the same Service.
+            ClientMetadataTest.installCachingFactory();
+            
+            QName serviceQName = new QName(namespaceURI, svcLocalPart);
+            PortInfo pi = new DummyPortInfo();
+
+            // Create two instances of the same Service
+            Service service1 = Service.create(serviceQName);
+            Service service2 = Service.create(serviceQName);
+
+            // No ports created yet, so there should be no relevant handler
+            // chains.
+            HandlerResolver resolver1 = service1.getHandlerResolver();
+            List<Handler> list1 = resolver1.getHandlerChain(pi);
+            assertEquals(0, list1.size());
+
+            // Create a Port specifying a sparse composite and verify the
+            // port gets the correct handlers associated.
+            DescriptionBuilderComposite sparseComposite = new DescriptionBuilderComposite();
+            HandlerChainsType handlerChainsType = getHandlerChainsType();
+            sparseComposite.setHandlerChainsType(handlerChainsType);
+            ServiceDelegate.setPortMetadata(sparseComposite);
+            QName portQName1 = new QName(namespaceURI, portLocalPart);
+            ClientMetadataHandlerChainTestSEI port1 =
+                    service1.getPort(portQName1, ClientMetadataHandlerChainTestSEI.class);
+            BindingProvider bindingProvider1 = (BindingProvider) port1;
+            Binding binding1 = (Binding) bindingProvider1.getBinding();
+            List<Handler> portHandlers1 = binding1.getHandlerChain();
+            assertEquals(2, portHandlers1.size());
+            
+            // Refresh the handler list from the resolver after the port is created
+            list1 = resolver1.getHandlerChain(pi);
+            assertTrue(containSameHandlers(portHandlers1, list1));
+
+            // Make sure the 2nd Service instance doesn't have handlers
+            // associated with it
+            HandlerResolver resolver2 = service2.getHandlerResolver();
+            List<Handler> list2 = resolver2.getHandlerChain(pi);
+            assertEquals(0, list2.size());
+
+            // Make sure the same port created under the 2nd service also
+            // doesn't have handlers
+            ClientMetadataHandlerChainTestSEI port2 =
+                    service2.getPort(portQName1, ClientMetadataHandlerChainTestSEI.class);
+            BindingProvider bindingProvider2 = (BindingProvider) port2;
+            Binding binding2 = (Binding) bindingProvider2.getBinding();
+            List<Handler> portHandlers2 = binding2.getHandlerChain();
+            assertEquals(0, portHandlers2.size());
+        }
+        finally {
+            ClientMetadataTest.restoreOriginalFactory();
+        }
+    }
+    
+    /**
+     * Verify that the original functionality of specifying a HandlerChain annotation with a
+     * file member works as it should. 
+     */
+    public void testHandlerChainOnSEI() {
+        QName serviceQN = new QName(namespaceURI, svcLocalPart);
+
+        Service service = Service.create(serviceQN);
+        
+        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(containsHandlerChainAnnotationHandlers(portHandlers));
+    }
+    
+    /**
+     * Verify that handler information in a sparse composite on the Port will override any handler chain
+     * annotation on the SEI. 
+     */
+    public void testSEIHandlerChainOverrideOnPort() {
+        QName serviceQN = new QName(namespaceURI, svcLocalPart + uniqueService++);
+        
+        Service service = Service.create(serviceQN);
+
+        // The SEI has a HandlerChain annotation, but the sparse metadata should override it
+        DescriptionBuilderComposite sparseComposite = new DescriptionBuilderComposite();
+        HandlerChainsType handlerChainsType = getHandlerChainsType();
+        sparseComposite.setHandlerChainsType(handlerChainsType);
+        ServiceDelegate.setPortMetadata(sparseComposite);
+        ClientMetadataHandlerChainTestSEIWithHC port = service.getPort(ClientMetadataHandlerChainTestSEIWithHC.class);
+        BindingProvider bindingProvider = (BindingProvider) port;
+        Binding binding = (Binding) bindingProvider.getBinding();
+        List<Handler> portHandlers = binding.getHandlerChain();
+        assertEquals(2, portHandlers.size());
+        assertTrue(containsSparseCompositeHandlers(portHandlers));
+    }
+    
+    /**
+     * Verify that handler information in a sparse composite on the Service will override any handler chain
+     * annotation on the SEI. 
+     */
+    public void testSEIHandlerChainOverrideOnService() {
+        QName serviceQN = new QName(namespaceURI, svcLocalPart + uniqueService++);
+        
+        // The SEI has a HandlerChain annotation, but the sparse metadata should override it
+        DescriptionBuilderComposite sparseComposite = new DescriptionBuilderComposite();
+        HandlerChainsType handlerChainsType = getHandlerChainsType();
+        sparseComposite.setHandlerChainsType(handlerChainsType);
+        ServiceDelegate.setServiceMetadata(sparseComposite);
+        Service service = Service.create(serviceQN);
+
+        ClientMetadataHandlerChainTestSEIWithHC port = service.getPort(ClientMetadataHandlerChainTestSEIWithHC.class);
+        BindingProvider bindingProvider = (BindingProvider) port;
+        Binding binding = (Binding) bindingProvider.getBinding();
+        List<Handler> portHandlers = binding.getHandlerChain();
+        assertEquals(2, portHandlers.size());
+        assertTrue(containsSparseCompositeHandlers(portHandlers));
+    }
+    
+    /**
+     * Set different composites on the Service and the Port that specify different 
+     * HandlerChainsType values.  
+     */
+    public void testCompositeOnServiceAndPort() {
+        QName serviceQN = new QName(namespaceURI, svcLocalPart + uniqueService++);
+        
+        // Create a service with a composite specifying handlers
+        DescriptionBuilderComposite sparseComposite = new DescriptionBuilderComposite();
+        HandlerChainsType handlerChainsType = getHandlerChainsType();
+        sparseComposite.setHandlerChainsType(handlerChainsType);
+        ServiceDelegate.setServiceMetadata(sparseComposite);
+        Service service = Service.create(serviceQN);
+
+        // Create a port with a composite specifying different handlers
+        DescriptionBuilderComposite portComposite = new DescriptionBuilderComposite();
+        HandlerChainsType portHandlerChainsType = getHandlerChainsType("ClientMetadataHandlerChainTest.xml");
+        portComposite.setHandlerChainsType(portHandlerChainsType);
+        ServiceDelegate.setPortMetadata(portComposite);
+        ClientMetadataHandlerChainTestSEI port = service.getPort(ClientMetadataHandlerChainTestSEI.class);
+        BindingProvider bindingProvider = (BindingProvider) port;
+        Binding binding = (Binding) bindingProvider.getBinding();
+        List<Handler> portHandlers = binding.getHandlerChain();
+
+        // 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);
+
+        // These are the handlers defined in the HandlerChainsType placed on the sparse composite
+        List<Class> compositeHandlerClasses = new ArrayList<Class>();
+        compositeHandlerClasses.add(org.apache.axis2.jaxws.spi.handler.DummySOAPHandler.class);
+        compositeHandlerClasses.add(org.apache.axis2.jaxws.spi.handler.DummyLogicalHandler.class);
+
+        if (inputHandlerClasses.size() != compositeHandlerClasses.size()) {
+            return false;
+        }
+        
+        if (inputHandlerClasses.containsAll(compositeHandlerClasses)) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    /**
+     * Answer if the List contains the same handlers as defined in the SEI
+     * via the HandlerChain.file annotation memeber.
+     * 
+     * @param portHandlers List of handlers
+     * @return true if the list matches what was defined on the SEI via the
+     *   HandlerChain annotation; false otherwise.
+     */
+    private boolean containsHandlerChainAnnotationHandlers(List<Handler> portHandlers) {
+        List<Class> portHandlerClasses = handlerClasses(portHandlers);
+        List<Class> seiHandlerClasses = new ArrayList<Class>();
+        seiHandlerClasses.add(ClientMetadataHandlerChainHandler.class);
+        
+        if (portHandlerClasses.size() != seiHandlerClasses.size()) {
+            return false;
+        }
+        
+        if (portHandlerClasses.containsAll(seiHandlerClasses)) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    /**
+     * Answer if two List<Handler> arguments contain the same handler Class files.
+     * @param list1
+     * @param list2
+     * @return
+     */
+    private boolean containSameHandlers(List<Handler> list1, List<Handler> list2) {
+        if (list1.size() != list2.size()) {
+            return false;
+        }
+
+        List<Class> list1HandlerClasses = handlerClasses(list1);
+        List<Class> list2HandlerClasses = handlerClasses(list2);
+
+        if (list1HandlerClasses.containsAll(list2HandlerClasses)) {
+            return true;
+        } else {
+            return false;
+        }
+            
+    }
+    
+    private List<Class> handlerClasses(List<Handler> listOfHandlers) {
+        List<Class> handlerClasses = new ArrayList<Class>();
+        Iterator<Handler> handlerIterator = listOfHandlers.iterator();
+        while (handlerIterator.hasNext()) {
+            handlerClasses.add(handlerIterator.next().getClass());
+        }
+        return handlerClasses;
+    }
+    
+    private HandlerChainsType getHandlerChainsType() {
+        return getHandlerChainsType("handler.xml");
+    }
+    private HandlerChainsType getHandlerChainsType(String fileName) {
+        InputStream is = getXMLFileStream(fileName);
+        assertNotNull(is);
+        HandlerChainsType returnHCT = DescriptionUtils.loadHandlerChains(is, this.getClass().getClassLoader());
+        assertNotNull(returnHCT);
+        return returnHCT;
+    }
+    private InputStream getXMLFileStream(String fileName) {
+        InputStream is = null;
+        String configLoc = null;
+        try {
+            String sep = "/";
+            configLoc = sep + "test-resources" + sep + "configuration" + sep + "handlers" + sep + fileName;
+            String baseDir = new File(System.getProperty("basedir",".")).getCanonicalPath();
+            is = new File(baseDir + configLoc).toURL().openStream();
+        }
+        catch(Exception e) {
+            e.printStackTrace();
+        }
+        return is;
+    }
+
+    public class DummyPortInfo implements PortInfo {
+        private QName portQN;
+        private QName serviceQN;
+        
+        public DummyPortInfo() {
+            this.portQN = new QName("http://www.apache.org/test/namespace", "DummyPort");
+            this.serviceQN = new QName("http://www.apache.org/test/namespace", "DummyService");
+        }
+        
+        public DummyPortInfo(QName portQN) {
+            this();
+            this.portQN = portQN;
+        }
+
+        public String getBindingID() {
+            return SOAPBinding.SOAP11HTTP_BINDING;
+        }
+
+        public QName getPortName() {
+            return portQN;
+        }
+        
+        public QName getServiceName() {
+            return serviceQN;
+        }
+    }
+
+}
+
+@WebService
+interface ClientMetadataHandlerChainTestSEI {
+    public String echo(String toEcho);
+}
+
+@WebService
+@HandlerChain(file="ClientMetadataHandlerChainTest.xml")
+interface ClientMetadataHandlerChainTestSEIWithHC {
+    public String echo(String toEcho);
+}
+
+@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);
+        }
+}

Added: webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/spi/ClientMetadataHandlerChainTest.xml
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/spi/ClientMetadataHandlerChainTest.xml?rev=633234&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/spi/ClientMetadataHandlerChainTest.xml (added)
+++ webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/spi/ClientMetadataHandlerChainTest.xml Mon Mar  3 10:47:38 2008
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one
+  ~ or more contributor license agreements. See the NOTICE file
+  ~ distributed with this work for additional information
+  ~ regarding copyright ownership. The ASF licenses this file
+  ~ to you 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.
+  -->
+<jws:handler-chains xmlns:jws="http://java.sun.com/xml/ns/javaee">
+
+	<jws:handler-chain name="LoggingHandlerChain">
+		<jws:handler>
+			<jws:handler-class>org.apache.axis2.jaxws.spi.ClientMetadataHandlerChainHandler</jws:handler-class>
+		</jws:handler>
+	</jws:handler-chain>
+	
+</jws:handler-chains>
+

Added: webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/spi/ClientMetadataPortTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/spi/ClientMetadataPortTest.java?rev=633234&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/spi/ClientMetadataPortTest.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/spi/ClientMetadataPortTest.java Mon Mar  3 10:47:38 2008
@@ -0,0 +1,465 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.axis2.jaxws.spi;
+
+import org.apache.axis2.jaxws.description.DescriptionTestUtils2;
+import org.apache.axis2.jaxws.description.EndpointDescription;
+import org.apache.axis2.jaxws.description.ServiceDescription;
+import org.apache.axis2.jaxws.description.builder.DescriptionBuilderComposite;
+
+import javax.jws.WebService;
+import javax.xml.namespace.QName;
+import javax.xml.ws.Binding;
+import javax.xml.ws.Holder;
+import javax.xml.ws.Service;
+import javax.xml.ws.WebServiceClient;
+import javax.xml.ws.soap.SOAPBinding;
+
+import java.net.URL;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+/**
+ * 
+ */
+public class ClientMetadataPortTest extends TestCase {
+    static final String namespaceURI = "http://description.jaxws.axis2.apache.org";
+    static final String svcLocalPart = "svcLocalPart";
+
+    static final String originalWsdl = "ClientMetadata.wsdl";
+    static final String overridenWsdl = "ClientMetadataOverriden.wsdl";
+    static final String otherWsdl = "ClientMetadataOther.wsdl";
+    static final String multiPortWsdl = "ClientMetadataMultiPort.wsdl";
+
+    static final String originalWsdl_portLocalPart = "portLocalPart";
+    static final String overridenWsdl_portLocalPart = "portLocalPartOverriden";
+    static final String otherWsdl_portLocalPart = "portLocalPartOther";
+    static final String multiPortWsdl_portLocalPart1 = "portLocalPartMulti1";
+    static final String multiPortWsdl_portLocalPart2 = "portLocalPartMulti2";
+    static final String multiPortWsdl_portLocalPart3 = "portLocalPartMulti3";
+    
+    /**
+     * Test the getPort functionality without any composite specified.
+     */
+    public void testOriginalGetPort() {
+        QName serviceQName = new QName(namespaceURI, svcLocalPart);
+        URL wsdlUrl = ClientMetadataTest.getWsdlURL(otherWsdl);
+        Service service = Service.create(wsdlUrl, serviceQName);
+        assertNotNull(service);
+        ServiceDelegate serviceDelegate = DescriptionTestUtils2.getServiceDelegate(service);
+        assertNotNull(serviceDelegate);
+        ServiceDescription serviceDesc = serviceDelegate.getServiceDescription();
+        assertNotNull(serviceDesc);
+        DescriptionBuilderComposite dbcInServiceDesc = DescriptionTestUtils2.getServiceDescriptionComposite(serviceDesc);
+        assertNotNull(dbcInServiceDesc);
+        assertEquals(Service.class, dbcInServiceDesc.getCorrespondingClass());
+        // Since this is a generic Service with no overrides, there will be no WebServiceClient annotation
+        WebServiceClient wsClient = dbcInServiceDesc.getWebServiceClientAnnot();
+        assertNull(wsClient);
+
+        // WSDL was specified on the create, so make sure the right one was used by checking the ports
+        assertTrue("Wrong WSDL used", ClientMetadataTest.validatePort(service, otherWsdl_portLocalPart));
+        
+        QName portQN = new QName(namespaceURI, otherWsdl_portLocalPart);
+        ClientMetadataPortSEI port = service.getPort(portQN, ClientMetadataPortSEI.class);
+        assertNotNull(port);
+    }
+    
+    /**
+     * Specify a sparse composite on a getPort call
+     */
+    public void testGetPortWithComposite() {
+        QName serviceQName = new QName(namespaceURI, svcLocalPart);
+        URL wsdlUrl = ClientMetadataTest.getWsdlURL(otherWsdl);
+        Service service = Service.create(wsdlUrl, serviceQName);
+        ServiceDelegate serviceDelegate = DescriptionTestUtils2.getServiceDelegate(service);
+        assertNull(ServiceDelegate.getServiceMetadata());
+        ServiceDescription serviceDesc = serviceDelegate.getServiceDescription();
+
+        DescriptionBuilderComposite sparseComposite = new DescriptionBuilderComposite();
+        assertNull(ServiceDelegate.getPortMetadata());
+        ServiceDelegate.setPortMetadata(sparseComposite);
+        assertNull(ServiceDelegate.getServiceMetadata());
+        assertSame(sparseComposite, ServiceDelegate.getPortMetadata());
+        QName portQN = new QName(namespaceURI, otherWsdl_portLocalPart);
+        ClientMetadataPortSEI port = service.getPort(portQN, ClientMetadataPortSEI.class);
+        assertNotNull(port);
+        assertNull(ServiceDelegate.getPortMetadata());
+        
+        EndpointDescription epDescArray[] = serviceDesc.getEndpointDescriptions();
+        assertEquals(1, epDescArray.length);
+        DescriptionBuilderComposite epDBC = epDescArray[0].getDescriptionBuilderComposite();
+        assertNotNull(epDBC);
+        assertNotSame(sparseComposite, epDBC);
+        assertSame(sparseComposite, epDBC.getSparseComposite(serviceDelegate));
+    }
+    
+    /**
+     * Do multiple getPorts on the same service specifiying different sparse composite.  Verify that
+     * the sparse composite overwrites the previous one.
+     */
+    public void testMulitpleGetPortSameService() {
+        QName serviceQName = new QName(namespaceURI, svcLocalPart);
+        URL wsdlUrl = ClientMetadataTest.getWsdlURL(otherWsdl);
+        Service service = Service.create(wsdlUrl, serviceQName);
+        ServiceDelegate serviceDelegate = DescriptionTestUtils2.getServiceDelegate(service);
+        assertNull(ServiceDelegate.getServiceMetadata());
+        ServiceDescription serviceDesc = serviceDelegate.getServiceDescription();
+
+        // Do the first getPort on the first Service
+        DescriptionBuilderComposite sparseComposite1 = new DescriptionBuilderComposite();
+        assertNull(ServiceDelegate.getPortMetadata());
+        ServiceDelegate.setPortMetadata(sparseComposite1);
+        assertNull(ServiceDelegate.getServiceMetadata());
+        assertSame(sparseComposite1, ServiceDelegate.getPortMetadata());
+        QName portQN = new QName(namespaceURI, otherWsdl_portLocalPart);
+        ClientMetadataPortSEI port1 = service.getPort(portQN, ClientMetadataPortSEI.class);
+        EndpointDescription epDescArray1[] = serviceDesc.getEndpointDescriptions();
+        assertEquals(1, epDescArray1.length);
+        DescriptionBuilderComposite epDBC1 = epDescArray1[0].getDescriptionBuilderComposite();
+        assertNotNull(epDBC1);
+        assertNotSame(sparseComposite1, epDBC1);
+        assertSame(sparseComposite1, epDBC1.getSparseComposite(serviceDelegate));
+        
+        // Do a second getPort for the same port on the same service using a different composite
+        DescriptionBuilderComposite sparseComposite2 = new DescriptionBuilderComposite();
+        assertNull(ServiceDelegate.getPortMetadata());
+        ServiceDelegate.setPortMetadata(sparseComposite2);
+        assertNull(ServiceDelegate.getServiceMetadata());
+        assertSame(sparseComposite2, ServiceDelegate.getPortMetadata());
+
+        ClientMetadataPortSEI port2 = service.getPort(portQN, ClientMetadataPortSEI.class);
+        EndpointDescription epDescArray2[] = serviceDesc.getEndpointDescriptions();
+        assertEquals(1, epDescArray2.length);
+        DescriptionBuilderComposite epDBC2 = epDescArray2[0].getDescriptionBuilderComposite();
+        assertNotNull(epDBC2);
+        assertNotSame(sparseComposite2, epDBC2);
+        assertSame(sparseComposite2, epDBC1.getSparseComposite(serviceDelegate));
+        // Verify the previous sparse composite was overwritten for this delegate
+        assertNotSame(sparseComposite1, epDBC1.getSparseComposite(serviceDelegate));
+    }
+    
+    /**
+     * Test multiple getPorts using different composites on different services.  Validate the composite
+     * is for each service delegate is different.  Note that we have to install a configuration
+     * factory that will cause the ServiceDescriptions to be cached; the default factory will
+     * not.
+     */
+    public void testGetPortDifferentServices() {
+        
+        try {
+            ClientMetadataTest.installCachingFactory();
+            QName serviceQName = new QName(namespaceURI, svcLocalPart);
+            QName portQN = new QName(namespaceURI, otherWsdl_portLocalPart);
+            URL wsdlUrl = ClientMetadataTest.getWsdlURL(otherWsdl);
+
+            // Create the first service 
+            Service service1 = Service.create(wsdlUrl, serviceQName);
+            ServiceDelegate serviceDelegate1 = DescriptionTestUtils2.getServiceDelegate(service1);
+            assertNull(ServiceDelegate.getServiceMetadata());
+            ServiceDescription serviceDesc1 = serviceDelegate1.getServiceDescription();
+            
+            // Do the first getPort on the first Service
+            DescriptionBuilderComposite sparseComposite1 = new DescriptionBuilderComposite();
+            assertNull(ServiceDelegate.getPortMetadata());
+            ServiceDelegate.setPortMetadata(sparseComposite1);
+            assertNull(ServiceDelegate.getServiceMetadata());
+            assertSame(sparseComposite1, ServiceDelegate.getPortMetadata());
+            ClientMetadataPortSEI port1 = service1.getPort(portQN, ClientMetadataPortSEI.class);
+            EndpointDescription epDescArray1[] = serviceDesc1.getEndpointDescriptions();
+            assertEquals(1, epDescArray1.length);
+            DescriptionBuilderComposite epDBC1 = epDescArray1[0].getDescriptionBuilderComposite();
+            assertNotNull(epDBC1);
+            assertNotSame(sparseComposite1, epDBC1);
+            assertSame(sparseComposite1, epDBC1.getSparseComposite(serviceDelegate1));
+            
+            // Create the second service 
+            Service service2 = Service.create(wsdlUrl, serviceQName);
+            ServiceDelegate serviceDelegate2 = DescriptionTestUtils2.getServiceDelegate(service2);
+            assertNull(ServiceDelegate.getServiceMetadata());
+            ServiceDescription serviceDesc2 = serviceDelegate2.getServiceDescription();
+
+            // Do the getPort on the second Service
+            DescriptionBuilderComposite sparseComposite2 = new DescriptionBuilderComposite();
+            assertNull(ServiceDelegate.getPortMetadata());
+            ServiceDelegate.setPortMetadata(sparseComposite2);
+            assertNull(ServiceDelegate.getServiceMetadata());
+            assertSame(sparseComposite2, ServiceDelegate.getPortMetadata());
+            ClientMetadataPortSEI port2 = service2.getPort(portQN, ClientMetadataPortSEI.class);
+            EndpointDescription epDescArray2[] = serviceDesc2.getEndpointDescriptions();
+            assertEquals(1, epDescArray2.length);
+            DescriptionBuilderComposite epDBC2 = epDescArray2[0].getDescriptionBuilderComposite();
+            assertNotNull(epDBC2);
+            assertNotSame(sparseComposite2, epDBC2);
+            
+            // Since we installed a caching configuration factory above, the ServiceDescriptions
+            // should match for the two service delegates.  The EndpointDesc and the composite
+            // in the EndpointDesc should be the same.  The sparse composite should be unique to
+            // each service delegate.
+            assertNotSame(serviceDelegate1, serviceDelegate2);
+            assertSame(serviceDesc1, serviceDesc2);
+            assertSame(epDBC1, epDBC2);
+            assertSame(epDescArray1[0], epDescArray2[0]);
+            assertNotSame(sparseComposite1, sparseComposite2);
+            assertSame(sparseComposite1, epDBC1.getSparseComposite(serviceDelegate1));
+            assertSame(sparseComposite2, epDBC2.getSparseComposite(serviceDelegate2));
+        } finally {
+            ClientMetadataTest.restoreOriginalFactory();
+        }
+    }
+    
+    /**
+     * Test doing GET_PORT on seperate ports under the same service.  They should have unique
+     * EndpointDesriptions and the sparse composites should be unique to the service delegate and
+     * endpoint.
+     */
+    public void testMultiplePortsSameService() {
+        QName serviceQName = new QName(namespaceURI, svcLocalPart);
+        URL wsdlUrl = ClientMetadataTest.getWsdlURL(multiPortWsdl);
+        QName portQN1 = new QName(namespaceURI, multiPortWsdl_portLocalPart1);
+        QName portQN2 = new QName(namespaceURI, multiPortWsdl_portLocalPart2);
+
+        Service service = Service.create(wsdlUrl, serviceQName);
+        ServiceDelegate serviceDelegate = DescriptionTestUtils2.getServiceDelegate(service);
+        assertNull(ServiceDelegate.getServiceMetadata());
+        ServiceDescription serviceDesc = serviceDelegate.getServiceDescription();
+
+        // Do the first getPort on the first Service
+        DescriptionBuilderComposite sparseComposite1 = new DescriptionBuilderComposite();
+        ServiceDelegate.setPortMetadata(sparseComposite1);
+        assertNull(ServiceDelegate.getServiceMetadata());
+        assertSame(sparseComposite1, ServiceDelegate.getPortMetadata());
+        ClientMetadataPortSEI port1 = service.getPort(portQN1, ClientMetadataPortSEI.class);
+        EndpointDescription epDescArray1[] = serviceDesc.getEndpointDescriptions();
+        assertEquals(1, epDescArray1.length);
+        DescriptionBuilderComposite epDBC1 = epDescArray1[0].getDescriptionBuilderComposite();
+        assertNotNull(epDBC1);
+        assertNotSame(sparseComposite1, epDBC1);
+        assertSame(sparseComposite1, epDBC1.getSparseComposite(serviceDelegate));
+        
+        // Do a second getPort for a different port on the same service using a different composite
+        DescriptionBuilderComposite sparseComposite2 = new DescriptionBuilderComposite();
+        assertNull(ServiceDelegate.getPortMetadata());
+        ServiceDelegate.setPortMetadata(sparseComposite2);
+        assertNull(ServiceDelegate.getServiceMetadata());
+        assertSame(sparseComposite2, ServiceDelegate.getPortMetadata());
+        ClientMetadataPortSEI port2 = service.getPort(portQN2, ClientMetadataPortSEI.class);
+        EndpointDescription epDescArray2[] = serviceDesc.getEndpointDescriptions();
+        assertEquals(2, epDescArray2.length);
+        EndpointDescription epdPort1 = serviceDesc.getEndpointDescription(portQN1);
+        EndpointDescription epdPort2 = serviceDesc.getEndpointDescription(portQN2);
+        assertNotNull(epdPort1);
+        assertNotNull(epdPort2);
+        assertNotSame(epdPort1, epdPort2);
+        
+        DescriptionBuilderComposite epDBC2 = epdPort2.getDescriptionBuilderComposite();
+        assertNotNull(epDBC2);
+        
+        assertSame(epDescArray1[0], epdPort1);
+        assertNotSame(epDBC1, epDBC2);
+        
+        assertSame(sparseComposite2, epDBC2.getSparseComposite(serviceDelegate));
+        assertNotSame(sparseComposite2, epDBC1.getSparseComposite(serviceDelegate));
+        
+        assertSame(sparseComposite1, epDBC1.getSparseComposite(serviceDelegate));
+        assertNotSame(sparseComposite1, epDBC2.getSparseComposite(serviceDelegate));
+    }
+
+    /**
+     * Validate setting a prefered port when creating the service results in a particular
+     * port being returned on the getPort(Class) call.
+     */
+    public void testPreferredPort() {
+        // Without setting a prefered port, the first port in the WSDL should
+        // be returned.
+        QName serviceQName = new QName(namespaceURI, svcLocalPart);
+        URL wsdlUrl = ClientMetadataTest.getWsdlURL(multiPortWsdl);
+        QName portQN1 = new QName(namespaceURI, multiPortWsdl_portLocalPart1);
+        
+        Service service1 = Service.create(wsdlUrl, serviceQName);
+        ClientMetadataPortSEI port1 = service1.getPort(ClientMetadataPortSEI.class);
+        assertNotNull(port1);
+        // Get the endpoint address to verify which port we got.  Note that the WSDL is setup
+        // so that the endpoint address ends with the name of the port for testing.
+        BindingProvider bindingProvider1 = (BindingProvider) port1;
+        Map<String, Object> requestContext1 = bindingProvider1.getRequestContext();
+        String endpointAddress1 = (String) requestContext1.get(BindingProvider.ENDPOINT_ADDRESS_PROPERTY);
+        assertNotNull(endpointAddress1);
+        // FIXME: We should get the first port in the WSDL, but that isn't working
+        // Depending on the JDK in use, the 2nd or 3rd port is returned
+//        assertTrue(endpointAddress.endsWith(multiPortWsdl_portLocalPart1));
+        
+        // Set a prefered port and create the service
+        QName portQN2 = new QName(namespaceURI, multiPortWsdl_portLocalPart2);
+        DescriptionBuilderComposite sparseComposite2 = new DescriptionBuilderComposite();
+        sparseComposite2.setPreferredPort(portQN2);
+        ServiceDelegate.setServiceMetadata(sparseComposite2);
+        Service service2 = Service.create(wsdlUrl, serviceQName);
+        ClientMetadataPortSEI port2 = service2.getPort(ClientMetadataPortSEI.class);
+        BindingProvider bindingProvider2 = (BindingProvider) port2;
+        Map<String, Object> requestContext2 = bindingProvider2.getRequestContext();
+        String endpointAddress2 = (String) requestContext2.get(BindingProvider.ENDPOINT_ADDRESS_PROPERTY);
+        assertNotNull(endpointAddress2);
+        assertTrue(endpointAddress2.endsWith(multiPortWsdl_portLocalPart2));
+        
+    }
+    /**
+     * Validate setting a prefered port when creating the service results in a particular
+     * port being returned on the getPort(Class) call.  The ServiceDesc in this case 
+     * are cached.
+     */
+    public void testPreferredPortCachedService() {
+        try {
+            ClientMetadataTest.installCachingFactory();
+
+            // Without setting a prefered port, the first port in the WSDL should
+            // be returned.
+            QName serviceQName = new QName(namespaceURI, svcLocalPart);
+            URL wsdlUrl = ClientMetadataTest.getWsdlURL(multiPortWsdl);
+            QName portQN1 = new QName(namespaceURI, multiPortWsdl_portLocalPart1);
+            
+            Service service1 = Service.create(wsdlUrl, serviceQName);
+            ServiceDelegate serviceDelegate1 = DescriptionTestUtils2.getServiceDelegate(service1);
+            ServiceDescription svcDesc1 = serviceDelegate1.getServiceDescription();
+            ClientMetadataPortSEI port1 = service1.getPort(ClientMetadataPortSEI.class);
+            assertNotNull(port1);
+            // Get the endpoint address to verify which port we got.  Note that the WSDL is setup
+            // so that the endpoint address ends with the name of the port for testing.
+            BindingProvider bindingProvider1 = (BindingProvider) port1;
+            Map<String, Object> requestContext1 = bindingProvider1.getRequestContext();
+            String endpointAddress1 = (String) requestContext1.get(BindingProvider.ENDPOINT_ADDRESS_PROPERTY);
+            assertNotNull(endpointAddress1);
+            // FIXME: We should get the first port in the WSDL, but that isn't working
+            // Depending on the JDK in use, the 2nd or 3rd port is returned
+//            assertTrue(endpointAddress.endsWith(multiPortWsdl_portLocalPart1));
+            
+            // Set a prefered port and create the service
+            QName portQN2 = new QName(namespaceURI, multiPortWsdl_portLocalPart2);
+            DescriptionBuilderComposite sparseComposite2 = new DescriptionBuilderComposite();
+            sparseComposite2.setPreferredPort(portQN2);
+            ServiceDelegate.setServiceMetadata(sparseComposite2);
+            Service service2 = Service.create(wsdlUrl, serviceQName);
+            ServiceDelegate serviceDelegate2 = DescriptionTestUtils2.getServiceDelegate(service2);
+            ServiceDescription svcDesc2 = serviceDelegate2.getServiceDescription();
+            assertNotSame(service1, service2);
+            assertNotSame(serviceDelegate1, serviceDelegate2);
+            assertSame(svcDesc1, svcDesc2);
+            
+            ClientMetadataPortSEI port2 = service2.getPort(ClientMetadataPortSEI.class);
+            BindingProvider bindingProvider2 = (BindingProvider) port2;
+            Map<String, Object> requestContext2 = bindingProvider2.getRequestContext();
+            String endpointAddress2 = (String) requestContext2.get(BindingProvider.ENDPOINT_ADDRESS_PROPERTY);
+            assertNotNull(endpointAddress2);
+            assertTrue(endpointAddress2.endsWith(multiPortWsdl_portLocalPart2));
+            
+            // Create a third service without a composite and make sure the previous composite
+            // setting of preferred port doesn't affect this one.
+            Service service3 = Service.create(wsdlUrl, serviceQName);
+            ServiceDelegate serviceDelegate3 = DescriptionTestUtils2.getServiceDelegate(service3);
+            ServiceDescription svcDesc3 = serviceDelegate3.getServiceDescription();
+            assertNotSame(service2, service3);
+            assertNotSame(serviceDelegate1, serviceDelegate3);
+            assertNotSame(serviceDelegate2, serviceDelegate3);
+            assertSame(svcDesc1, svcDesc3);
+            
+            ClientMetadataPortSEI port3 = service3.getPort(ClientMetadataPortSEI.class);
+            assertNotNull(port3);
+            BindingProvider bindingProvider3 = (BindingProvider) port3;
+            Map<String, Object> requestContext3 = bindingProvider3.getRequestContext();
+            String endpointAddress3 = (String) requestContext3.get(BindingProvider.ENDPOINT_ADDRESS_PROPERTY);
+            assertNotNull(endpointAddress1);
+            // FIXME: We should get the first port in the WSDL, but that isn't working
+            // Depending on the JDK in use, the 2nd or 3rd port is returned
+//            assertTrue(endpointAddress.endsWith(multiPortWsdl_portLocalPart1));
+
+        } finally {
+            ClientMetadataTest.restoreOriginalFactory();
+        }
+    }
+    
+    /**
+     * Validate enabling MTOM when creating the service results ports created under that service
+     * have MTOM enabled.
+     */
+    public void testEnableMTOM() {
+        QName serviceQName = new QName(namespaceURI, svcLocalPart);
+        URL wsdlUrl = ClientMetadataTest.getWsdlURL(multiPortWsdl);
+        DescriptionBuilderComposite sparseComposite = new DescriptionBuilderComposite();
+        sparseComposite.setIsMTOMEnabled(true);
+        ServiceDelegate.setServiceMetadata(sparseComposite);
+        Service service = Service.create(wsdlUrl, serviceQName);
+        ClientMetadataPortSEI port = service.getPort(ClientMetadataPortSEI.class);
+        assertNotNull(port);
+        // Verify that MTOM is enabled on this port.
+        BindingProvider bindingProvider = (BindingProvider) port;
+        SOAPBinding binding = (SOAPBinding) bindingProvider.getBinding();
+        assertTrue(binding.isMTOMEnabled());
+        
+        // Verify that specific ports under this service also have MTOM enabled
+        QName port1QN = new QName(namespaceURI, multiPortWsdl_portLocalPart1);
+        ClientMetadataPortSEI port1 = service.getPort(port1QN, ClientMetadataPortSEI.class);
+        SOAPBinding binding1 = ((SOAPBinding) ((BindingProvider) port1).getBinding());
+        assertTrue(binding1.isMTOMEnabled());
+        
+        QName port2QN = new QName(namespaceURI, multiPortWsdl_portLocalPart2);
+        ClientMetadataPortSEI port2 = service.getPort(port2QN, ClientMetadataPortSEI.class);
+        SOAPBinding binding2 = ((SOAPBinding) ((BindingProvider) port2).getBinding());
+        assertTrue(binding2.isMTOMEnabled());
+    }
+    
+    /**
+     * Validate enabling MTOM when creating the service results in enablement only
+     * for that service delegate, and not a different service delegate referencing
+     * the same service.
+     */
+    public void testEnableMTOMCachedService() {
+        try {
+            ClientMetadataTest.installCachingFactory();
+
+            QName serviceQName = new QName(namespaceURI, svcLocalPart);
+            URL wsdlUrl = ClientMetadataTest.getWsdlURL(multiPortWsdl);
+
+            DescriptionBuilderComposite sparseComposite = new DescriptionBuilderComposite();
+            sparseComposite.setIsMTOMEnabled(true);
+            ServiceDelegate.setServiceMetadata(sparseComposite);
+            Service service1 = Service.create(wsdlUrl, serviceQName);
+            
+            Service service2 = Service.create(wsdlUrl, serviceQName);
+            
+            QName portQN = new QName(namespaceURI, multiPortWsdl_portLocalPart1);
+            ClientMetadataPortSEI port1 = service1.getPort(portQN, ClientMetadataPortSEI.class);
+            ClientMetadataPortSEI port2 = service2.getPort(portQN, ClientMetadataPortSEI.class);
+
+            SOAPBinding binding1 = ((SOAPBinding) ((BindingProvider) port1).getBinding());
+            assertTrue(binding1.isMTOMEnabled());
+            
+            SOAPBinding binding2 = ((SOAPBinding) ((BindingProvider) port2).getBinding());
+            assertFalse(binding2.isMTOMEnabled());
+
+        } finally {
+            ClientMetadataTest.restoreOriginalFactory();
+        }
+    }
+}
+
+@WebService(name="EchoMessagePortType", targetNamespace="http://description.jaxws.axis2.apache.org")
+interface ClientMetadataPortSEI {
+    public String echoMessage(String string);
+}



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


Mime
View raw message