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 2009/09/25 00:10:26 UTC

svn commit: r818641 - in /webservices/axis2/trunk/java/modules: jaxws/test/org/apache/axis2/jaxws/client/ kernel/ kernel/src/org/apache/axis2/context/ kernel/src/org/apache/axis2/context/externalize/ kernel/test/org/apache/axis2/context/externalize/

Author: barrettj
Date: Thu Sep 24 22:10:26 2009
New Revision: 818641

URL: http://svn.apache.org/viewvc?rev=818641&view=rev
Log:
Add the service QName and port local name to the serialized data for an AxisService.  This information can be used when the service is deserialized to activate the appropriate AxisService in the case where the AxisService name is not unique or not matched.  This can happen in the case where multiple AxisServices were created for the same service and portname, and so a unique ID was appended to the AxisService name.  In that case, the serialized AxisService name may not match the current AxisService names after a system restart.  If an exact name match can not be found after deserialization during activation, then a match is made on the sevice QName and port local name.

Added tests for same.

Also removed the generic exclude of tests with the name *Util*.java.  Added explicit excludes for the two tests currently being excluded by that pattern.

Added:
    webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/client/PortDeserializationTests.java
    webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/context/externalize/
    webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/context/externalize/ActivateUtilsTest.java
Modified:
    webservices/axis2/trunk/java/modules/kernel/pom.xml
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/MessageContext.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/OperationContext.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/ServiceContext.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/externalize/ActivateUtils.java

Added: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/client/PortDeserializationTests.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/client/PortDeserializationTests.java?rev=818641&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/client/PortDeserializationTests.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/client/PortDeserializationTests.java Thu Sep 24 22:10:26 2009
@@ -0,0 +1,385 @@
+/*
+ * 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.client;
+
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.description.AxisService;
+import org.apache.axis2.description.AxisServiceGroup;
+import org.apache.axis2.description.Parameter;
+import org.apache.axis2.description.WSDL11ToAllAxisServicesBuilder;
+import org.apache.axis2.jaxws.description.EndpointDescription;
+import org.apache.axis2.jaxws.spi.ClientMetadataTest;
+
+import javax.xml.namespace.QName;
+import javax.xml.ws.Dispatch;
+import javax.xml.ws.Service;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+import junit.framework.TestCase;
+
+/**
+ * Test the serialization of a MessageContext and subsequent deserialization to ensure the
+ * JAXWS and Axis2 objects for the relevant ports are hooked back up correctly.  In particluar,
+ * make sure the AxisServices can be hooked back up with the MEssageContexts correctly.
+ * 
+ * This is done as a JAX-WS test rather than an Axis2 test to verify the behavior of ports 
+ * added by JAX-WS, particluarly dynamic ports.
+ */
+public class PortDeserializationTests extends TestCase {
+    static final String namespaceURI = "http://client.jaxws.axis2.apache.org";
+    static final String svcLocalPart = "svcLocalPart";
+    
+    static final String dynamicPort = "dynamicPort";
+    static final String bindingID = null;
+    static final String epr = "http://dummy/endpoint/address";
+
+    /**
+     * Validate that a message context can be serialized and deserialized with the Axis2 
+     * and JAX-WS description objects not being recreated.  This is similar to a message
+     * being serialized and deserialized without the server being stopped.
+     */
+    public void testDynamicPortSingleServiceNoRecreate() {
+        try {
+            ClientMetadataTest.installCachingFactory();
+            QName svc1QN = new QName(namespaceURI + "?1", svcLocalPart);
+
+            Service svc1 = Service.create(svc1QN);
+            QName portQN = new QName(namespaceURI, dynamicPort + "_1");
+            svc1.addPort(portQN, bindingID, epr);
+            Dispatch<String> port1 = svc1.createDispatch(portQN, String.class, Service.Mode.PAYLOAD);
+            
+            // We need to get the AxisService so we can set in on a MessageContext and test 
+            // serialization / deserialization.  We do this using NON-Public, INTERNAL SPIs
+            // since we need to get at the internals of the engine
+            org.apache.axis2.jaxws.spi.BindingProvider bindingProvider = 
+                (org.apache.axis2.jaxws.spi.BindingProvider) port1;
+            EndpointDescription endpointDesc = bindingProvider.getEndpointDescription();
+            AxisService axisService = endpointDesc.getAxisService();
+            assertNotNull(axisService);
+            assertEquals(svc1QN.getLocalPart()+ "." + portQN.getLocalPart(), axisService.getName());
+
+            // Now that the AxisService is setup, create an Axis2 message context, set the
+            // AxisService on it.  Serialize it out then read it back in.
+            MessageContext msgCtx = new MessageContext();
+            msgCtx.setAxisService(axisService);
+            msgCtx.setAxisServiceGroup(axisService.getAxisServiceGroup());
+            ByteArrayOutputStream baos = serializeMessageContext(msgCtx);
+            
+            // Read in the message context and activate it, which is required by message
+            // context deserialization to connect the message context to existing runtime 
+            // objects such as AxisService
+            MessageContext mcRead = deserializeMessageContext(baos);
+            ConfigurationContext configContext = endpointDesc.getServiceDescription().getAxisConfigContext();
+            assertNotNull(configContext);
+            mcRead.activate(configContext);
+            
+            AxisService asRead = mcRead.getAxisService();
+            assertNotNull(asRead);
+            assertEquals(axisService.getName(), asRead.getName());
+            assertSame(axisService, asRead);
+            AxisServiceGroup agRead = mcRead.getAxisServiceGroup();
+            assertNotNull(agRead);
+            
+            // This keeps the port from being GC'd and causing the AxisService to be freed
+            // before the test method completes.
+            assertNotNull(port1);
+
+        } catch (Exception t) {
+            t.printStackTrace();
+            fail("Caught throwable " + t);
+        } finally {
+            ClientMetadataTest.restoreOriginalFactory();
+        }
+    }
+    
+    /**
+     * Validate that a message context can be serialized and deserialized with the Axis2 
+     * and JAX-WS description objects not being recreated.  This is similar to a message
+     * being serialized and deserialized without the server being stopped.
+     * 
+     * This test uses two services with different namespaces, each with a dynamic port of the
+     * same name.
+     */
+    public void testDynamicPortMultipleServiceNoRecreate() {
+        try {
+            ClientMetadataTest.installCachingFactory();
+            QName svc1QN = new QName(namespaceURI + "?1", svcLocalPart);
+            QName svc2QN = new QName(namespaceURI + "?2", svcLocalPart);
+
+            Service svc1 = Service.create(svc1QN);
+            Service svc2 = Service.create(svc2QN);
+
+            // Create the same port under the two different services.  Each port gets a unique
+            // EPR so it will cause a new port to be created (rather than shared) which in 
+            // turn causes a new AxisService to be crated.
+            QName portQN = new QName(namespaceURI, dynamicPort + "_1");
+            svc1.addPort(portQN, bindingID, epr + "1");
+            Dispatch<String> port1 = svc1.createDispatch(portQN, String.class, Service.Mode.PAYLOAD);
+            svc2.addPort(portQN, bindingID, epr + "2");
+            Dispatch<String> port2 = svc2.createDispatch(portQN, String.class, Service.Mode.PAYLOAD);
+            
+            // We need to get the AxisService so we can set in on a MessageContext and test 
+            // serialization / deserialization.  We do this using NON-Public, INTERNAL SPIs
+            // since we need to get at the internals of the engine
+            
+            // Check the AxisService created for both ports.
+            org.apache.axis2.jaxws.spi.BindingProvider bindingProvider1 = 
+                (org.apache.axis2.jaxws.spi.BindingProvider) port1;
+            EndpointDescription endpointDesc1 = bindingProvider1.getEndpointDescription();
+            AxisService axisService1 = endpointDesc1.getAxisService();
+            assertNotNull(axisService1);
+            assertEquals(svc1QN.getLocalPart()+ "." + portQN.getLocalPart(), axisService1.getName());
+            
+            org.apache.axis2.jaxws.spi.BindingProvider bindingProvider2 = 
+                (org.apache.axis2.jaxws.spi.BindingProvider) port2;
+            EndpointDescription endpointDesc2 = bindingProvider2.getEndpointDescription();
+            AxisService axisService2 = endpointDesc2.getAxisService();
+            assertNotNull(axisService2);
+            assertNotSame(axisService1, axisService2);
+            // The 2nd AxisService created gets a unique ID appended to the name
+            String baseName = svc2QN.getLocalPart()+ "." + portQN.getLocalPart();
+            assertFalse(baseName.equals(axisService2.getName()));
+            assertTrue(axisService2.getName().startsWith(baseName));
+            
+            // Now that the AxisService is setup, create two Axis2 message contexts, set the
+            // AxisServices on them.  Serialize them out
+            MessageContext msgCtx1 = new MessageContext();
+            msgCtx1.setAxisService(axisService1);
+            msgCtx1.setAxisServiceGroup(axisService1.getAxisServiceGroup());
+            ByteArrayOutputStream baos1 = serializeMessageContext(msgCtx1);
+            
+            MessageContext msgCtx2 = new MessageContext();
+            msgCtx2.setAxisService(axisService2);
+            msgCtx2.setAxisServiceGroup(axisService2.getAxisServiceGroup());
+            ByteArrayOutputStream baos2 = serializeMessageContext(msgCtx2);
+            
+            // Read in the message contexts and activate them, which is required by message
+            // context deserialization to connect the message context to existing runtime 
+            // objects such as AxisService
+            MessageContext mcRead1 = deserializeMessageContext(baos1);
+            ConfigurationContext configContext1 = endpointDesc1.getServiceDescription().getAxisConfigContext();
+            assertNotNull(configContext1);
+            mcRead1.activate(configContext1);
+            AxisService asRead1 = mcRead1.getAxisService();
+            assertNotNull(asRead1);
+            assertEquals(axisService1.getName(), asRead1.getName());
+            assertSame(axisService1, asRead1);
+            AxisServiceGroup agRead1 = mcRead1.getAxisServiceGroup();
+            assertNotNull(agRead1);
+
+            
+            // Do the same for the second Message Context
+            MessageContext mcRead2 = deserializeMessageContext(baos2);
+            ConfigurationContext configContext2 = endpointDesc2.getServiceDescription().getAxisConfigContext();
+            assertNotNull(configContext2);
+            assertSame(configContext1, configContext2);
+            mcRead2.activate(configContext2);
+            AxisService asRead2 = mcRead2.getAxisService();
+            assertNotNull(asRead2);
+            assertEquals(axisService2.getName(), asRead2.getName());
+            assertSame(axisService2, asRead2);
+            AxisServiceGroup agRead2 = mcRead2.getAxisServiceGroup();
+            assertNotNull(agRead2);
+            
+            // These keep the ports from being GC'd before the test method completes and
+            // freeing up the AxisServices
+            assertNotNull(port1);
+            assertNotNull(port2);
+            
+        } catch (Exception t) {
+            t.printStackTrace();
+            fail("Caught throwable " + t);
+        } finally {
+            ClientMetadataTest.restoreOriginalFactory();
+        }
+    }
+    /**
+     * Validate that a message context can be serialized and deserialized with the Axis2 
+     * and JAX-WS description objects being recreated before the deserialization.  This is 
+     * similar to a message being serialized, the server being restarted and then the 
+     * messgage being deserialized.  In this case it must be hooked up with new instances 
+     * of what should be identical objects such as AxisServices.
+     */
+    public void testDynamicPortMultipleServiceWithRecreate() {
+        try {
+            ClientMetadataTest.installCachingFactory();
+            QName svc1QN = new QName(namespaceURI + "?1", svcLocalPart);
+            QName svc2QN = new QName(namespaceURI + "?2", svcLocalPart);
+            QName portQN = new QName(namespaceURI, dynamicPort + "_1");
+            
+            Service svc1 = Service.create(svc1QN);
+            Service svc2 = Service.create(svc2QN);
+
+            // Create the same port under the two different services.  Each port gets a unique
+            // EPR so it will cause a new port to be created (rather than shared) which in 
+            // turn causes a new AxisService to be crated.
+            svc1.addPort(portQN, bindingID, epr + "1");
+            Dispatch<String> port1 = svc1.createDispatch(portQN, String.class, Service.Mode.PAYLOAD);
+            svc2.addPort(portQN, bindingID, epr + "2");
+            Dispatch<String> port2 = svc2.createDispatch(portQN, String.class, Service.Mode.PAYLOAD);
+            
+            // We need to get the AxisService so we can set in on a MessageContext and test 
+            // serialization / deserialization.  We do this using NON-Public, INTERNAL SPIs
+            // since we need to get at the internals of the engine
+            
+            // Check the AxisService created for both ports.
+            org.apache.axis2.jaxws.spi.BindingProvider bindingProvider1 = 
+                (org.apache.axis2.jaxws.spi.BindingProvider) port1;
+            EndpointDescription endpointDesc1 = bindingProvider1.getEndpointDescription();
+            AxisService axisService1 = endpointDesc1.getAxisService();
+            assertNotNull(axisService1);
+            assertEquals(svc1QN.getLocalPart()+ "." + portQN.getLocalPart(), axisService1.getName());
+            
+            org.apache.axis2.jaxws.spi.BindingProvider bindingProvider2 = 
+                (org.apache.axis2.jaxws.spi.BindingProvider) port2;
+            EndpointDescription endpointDesc2 = bindingProvider2.getEndpointDescription();
+            AxisService axisService2 = endpointDesc2.getAxisService();
+            assertNotNull(axisService2);
+            assertNotSame(axisService1, axisService2);
+            // The 2nd AxisService created gets a unique ID appended to the name
+            String baseName = svc2QN.getLocalPart()+ "." + portQN.getLocalPart();
+            assertFalse(baseName.equals(axisService2.getName()));
+            assertTrue(axisService2.getName().startsWith(baseName));
+            
+            // Now that the AxisService is setup, create two Axis2 message contexts, set the
+            // AxisServices on them.  Serialize them out
+            MessageContext msgCtx1 = new MessageContext();
+            msgCtx1.setAxisService(axisService1);
+            msgCtx1.setAxisServiceGroup(axisService1.getAxisServiceGroup());
+            ByteArrayOutputStream baos1 = serializeMessageContext(msgCtx1);
+            
+            MessageContext msgCtx2 = new MessageContext();
+            msgCtx2.setAxisService(axisService2);
+            msgCtx2.setAxisServiceGroup(axisService2.getAxisServiceGroup());
+            ByteArrayOutputStream baos2 = serializeMessageContext(msgCtx2);
+            
+            // Now cause the runtime objects to be recreated.  Do this by forcing a release
+            // of both Service instances, which will also release the runtime objects
+            // such as the AxisService underneath them.  Then recreate the ports
+            org.apache.axis2.jaxws.spi.ServiceDelegate.releaseService(svc1);
+            org.apache.axis2.jaxws.spi.ServiceDelegate.releaseService(svc2);
+        
+            Service svc1_redo = Service.create(svc1QN);
+            Service svc2_redo = Service.create(svc2QN);
+            
+            svc1_redo.addPort(portQN, bindingID, epr + "1");
+            Dispatch<String> port1_redo = svc1_redo.createDispatch(portQN, String.class, Service.Mode.PAYLOAD);
+            svc2_redo.addPort(portQN, bindingID, epr + "2");
+            Dispatch<String> port2_redo = svc2_redo.createDispatch(portQN, String.class, Service.Mode.PAYLOAD);
+
+            org.apache.axis2.jaxws.spi.BindingProvider bindingProvider1_redo = 
+                (org.apache.axis2.jaxws.spi.BindingProvider) port1_redo;
+            EndpointDescription endpointDesc1_redo = bindingProvider1_redo.getEndpointDescription();
+            AxisService axisService1_redo = endpointDesc1_redo.getAxisService();
+            assertNotNull(axisService1_redo);
+            assertEquals(baseName, axisService1_redo.getName());
+            
+            org.apache.axis2.jaxws.spi.BindingProvider bindingProvider2_redo = 
+                (org.apache.axis2.jaxws.spi.BindingProvider) port2_redo;
+            EndpointDescription endpointDesc2_redo = bindingProvider2_redo.getEndpointDescription();
+            AxisService axisService2_redo = endpointDesc2_redo.getAxisService();
+            assertNotNull(axisService2_redo);
+            assertNotSame(axisService1_redo, axisService2_redo);
+            Parameter svcQNParam1_redo = axisService1_redo.getParameter(WSDL11ToAllAxisServicesBuilder.WSDL_SERVICE_QNAME);
+            assertEquals(svc1QN, svcQNParam1_redo.getValue());
+            // The 2nd AxisService created gets a unique ID appended to the name
+            assertFalse(baseName.equals(axisService2_redo.getName()));
+            assertTrue(axisService2_redo.getName().startsWith(baseName));
+            Parameter svcQNParam2_redo = axisService2_redo.getParameter(WSDL11ToAllAxisServicesBuilder.WSDL_SERVICE_QNAME);
+            assertEquals(svc2QN, svcQNParam2_redo.getValue());
+
+            // Read in the message contexts and activate them, which is required by message
+            // context deserialization to connect the message context to existing runtime 
+            // objects such as AxisService
+            MessageContext mcRead1 = deserializeMessageContext(baos1);
+            ConfigurationContext configContext1 = endpointDesc1_redo.getServiceDescription().getAxisConfigContext();
+            assertNotNull(configContext1);
+            mcRead1.activate(configContext1);
+            AxisService asRead1 = mcRead1.getAxisService();
+            assertNotNull(asRead1);
+            assertEquals(axisService1_redo.getName(), asRead1.getName());
+            assertSame(axisService1_redo, asRead1);
+            AxisServiceGroup agRead1 = mcRead1.getAxisServiceGroup();
+            assertNotNull(agRead1);
+
+            
+            // Do the same for the second Message Context
+            MessageContext mcRead2 = deserializeMessageContext(baos2);
+            ConfigurationContext configContext2 = endpointDesc2_redo.getServiceDescription().getAxisConfigContext();
+            assertNotNull(configContext2);
+            assertSame(configContext1, configContext2);
+            mcRead2.activate(configContext2);
+            AxisService asRead2 = mcRead2.getAxisService();
+            assertNotNull("AxisService was not activated", asRead2);
+            assertEquals(axisService2_redo.getName(), asRead2.getName());
+            assertSame(axisService2_redo, asRead2);
+            AxisServiceGroup agRead2 = mcRead2.getAxisServiceGroup();
+            assertNotNull("AxisServiceGroup was not activated", agRead2);
+            
+            // These keep the ports from being GC'd before the test method completes and
+            // freeing up the AxisServices
+            assertNotNull(port1);
+            assertNotNull(port2);
+            assertNotNull(port1_redo);
+            assertNotNull(port2_redo);
+            
+        } catch (Exception t) {
+            t.printStackTrace();
+            fail("Caught throwable " + t);
+        } finally {
+            ClientMetadataTest.restoreOriginalFactory();
+        }
+    }
+
+
+    /**
+     * Deserialize a message context from the stream.  IMPORTANT NOTE!  After the 
+     * message context is deserialized, the activate(...) method must be called on it.
+     * @param baos
+     * @return
+     * @throws IOException
+     * @throws ClassNotFoundException
+     */
+    private MessageContext deserializeMessageContext(ByteArrayOutputStream baos)
+            throws IOException, ClassNotFoundException {
+        ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+        ObjectInputStream ois = new ObjectInputStream(bais);
+        
+        MessageContext mcRead = new MessageContext();
+        mcRead.readExternal(ois);
+        return mcRead;
+    }
+
+    private ByteArrayOutputStream serializeMessageContext(MessageContext msgCtx)
+            throws IOException {
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream oos = new ObjectOutputStream(baos);
+        msgCtx.writeExternal(oos);
+        oos.flush();
+        oos.close();
+        return baos;
+    }
+
+}

Modified: webservices/axis2/trunk/java/modules/kernel/pom.xml
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/pom.xml?rev=818641&r1=818640&r2=818641&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/pom.xml (original)
+++ webservices/axis2/trunk/java/modules/kernel/pom.xml Thu Sep 24 22:10:26 2009
@@ -162,7 +162,8 @@
                     <skip>false</skip>
                     <excludes>
                         <exclude>**/*Abstract*.java</exclude>
-                        <exclude>**/*Util*.java</exclude>
+                        <exclude>**/UtilsParseRequestTest.java</exclude> <!-- Was excluded by **/*Util*.java and currently fails -->
+                        <exclude>**/URLTemplatingUtilTest.java</exclude> <!-- Was excluded by **/*Util*.java -->
                         <exclude>**/*MessageContextChangeTest.java</exclude>
                         <exclude>**/MessageContextChangeTest.java</exclude> <!-- Removed because of problem on Java5. Needs reinstated -->
                     </excludes>

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/MessageContext.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/MessageContext.java?rev=818641&r1=818640&r2=818641&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/MessageContext.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/MessageContext.java Thu Sep 24 22:10:26 2009
@@ -2569,8 +2569,12 @@
         out.writeUTF("axisService");
         metaAxisService = null;
         if (axisService != null) {
-            metaAxisService = new MetaDataEntry(axisService.getClass().getName(),
-                                                axisService.getName());
+            String serviceAndPortNames = ActivateUtils.getAxisServiceExternalizeExtraName(axisService);
+            // If there is a service & port QName stored on the AxisService then write it out so 
+            // it can be used during deserialization to hook up the message context to the 
+            // correct AxisService.
+            metaAxisService = new MetaDataEntry(axisService.getClass().getName(), 
+                    axisService.getName(), serviceAndPortNames);
         }
         out.writeObject(metaAxisService);
 
@@ -3432,7 +3436,8 @@
         if (metaAxisService != null) {
             this.setAxisService(ActivateUtils.findService(axisConfig,
                                                 metaAxisService.getClassName(),
-                                                metaAxisService.getQNameAsString()));
+                                                metaAxisService.getQNameAsString(),
+                                                metaAxisService.getExtraName()));
         }
 
         // We previously saved metaAxisServiceGroup; restore it

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/OperationContext.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/OperationContext.java?rev=818641&r1=818640&r2=818641&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/OperationContext.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/OperationContext.java Thu Sep 24 22:10:26 2009
@@ -645,7 +645,8 @@
 
         if (metaAxisService != null) {
             axisService = ActivateUtils.findService(axisConfig, metaAxisService.getClassName(),
-                                                       metaAxisService.getQNameAsString());
+                                                       metaAxisService.getQNameAsString(),
+                                                       metaAxisService.getExtraName());
         }
 
         // We previously saved metaAxisOperation; restore it

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/ServiceContext.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/ServiceContext.java?rev=818641&r1=818640&r2=818641&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/ServiceContext.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/ServiceContext.java Thu Sep 24 22:10:26 2009
@@ -493,7 +493,8 @@
 
         if (metaAxisService != null) {
             axisService = ActivateUtils.findService(axisConfig, metaAxisService.getClassName(),
-                                                       metaAxisService.getQNameAsString());
+                                                       metaAxisService.getQNameAsString(),
+                                                       metaAxisService.getExtraName());
         }
 
         // the parent ServiceGroupContext object was saved

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/externalize/ActivateUtils.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/externalize/ActivateUtils.java?rev=818641&r1=818640&r2=818641&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/externalize/ActivateUtils.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/externalize/ActivateUtils.java Thu Sep 24 22:10:26 2009
@@ -29,11 +29,14 @@
 
 import javax.xml.namespace.QName;
 
+import org.apache.axis2.AxisFault;
 import org.apache.axis2.description.AxisMessage;
 import org.apache.axis2.description.AxisOperation;
 import org.apache.axis2.description.AxisService;
 import org.apache.axis2.description.AxisServiceGroup;
+import org.apache.axis2.description.Parameter;
 import org.apache.axis2.description.TransportInDescription;
+import org.apache.axis2.description.WSDL11ToAllAxisServicesBuilder;
 import org.apache.axis2.engine.AxisConfiguration;
 import org.apache.axis2.engine.Handler;
 import org.apache.axis2.transport.TransportListener;
@@ -79,10 +82,10 @@
         Iterator its = axisConfig.getServiceGroups();
 
         while (its.hasNext()) {
-            AxisServiceGroup serviceGroup = (AxisServiceGroup) its.next();
+            AxisServiceGroup checkServiceGroup = (AxisServiceGroup) its.next();
 
-            String tmpSGClassName = serviceGroup.getClass().getName();
-            String tmpSGName = serviceGroup.getServiceGroupName();
+            String tmpSGClassName = checkServiceGroup.getClass().getName();
+            String tmpSGName = checkServiceGroup.getServiceGroupName();
 
             if (tmpSGClassName.equals(serviceGrpClassName)) {
                 boolean found = false;
@@ -93,6 +96,8 @@
                     found = true;
                 } else if ((tmpSGName != null) && (tmpSGName.equals(serviceGrpName))) {
                     found = true;
+                } else if (containsExternalizedAxisServiceName(checkServiceGroup, serviceGrpName)) {
+                    found = true;
                 }
 
                 if (found) {
@@ -102,7 +107,7 @@
                                 + serviceGrpClassName + "]   [" + serviceGrpName + "]");
                     }
 
-                    return serviceGroup;
+                    return checkServiceGroup;
                 }
             }
         }
@@ -117,6 +122,36 @@
     }
     
     /**
+     * Answer if there are any AxisServices in the specified ServiceGroup that have an externalized
+     * name that matches the service group name.    
+     * 
+     * @param checkServiceGroup The AxisServiceGroup containing the AxisServies to check
+     * @param serviceGrpName The name to check as the externalized name of the AxisService
+     * @return true if the group contains an AxisService with that name; false otherwise.
+     */
+    private static boolean containsExternalizedAxisServiceName(
+            AxisServiceGroup checkServiceGroup, String serviceGrpName) {
+        boolean containsAxisService = false;
+        if (serviceGrpName != null && checkServiceGroup != null) {
+            // Get a list of AxisServices on the group
+            // Iterate over them to see if any have the Externalized Name Parameter
+            // If so and it mathces, then this service group name then use this service group
+            Iterator axisServicesInGroup = checkServiceGroup.getServices();
+            while (axisServicesInGroup.hasNext()) {
+                AxisService checkService = (AxisService) axisServicesInGroup.next();
+                String externalizedServiceName = 
+                    (String) checkService.getParameterValue(EXTERNALIZED_AXIS_SERVICE_NAME);
+                if (externalizedServiceName != null && 
+                        externalizedServiceName.equals(serviceGrpName)) {
+                    containsAxisService = true;
+                    break;
+                }
+            }
+        }
+        return containsAxisService;
+    }
+
+    /**
      * Find the AxisService object that matches the criteria
      * 
      * @param axisConfig The AxisConfiguration object
@@ -126,7 +161,18 @@
      * @return the AxisService object that matches the criteria
      */
     public static AxisService findService(AxisConfiguration axisConfig, String serviceClassName,
-                                          String serviceName) {
+            String serviceName) {
+        return findService(axisConfig, serviceClassName, serviceName, null);
+    }
+    private static final String EXTERNALIZED_AXIS_SERVICE_NAME 
+        = "org.apache.axis2.context.externalize.AxisServiceName";
+    public static AxisService findService(AxisConfiguration axisConfig, String serviceClassName,
+                                          String serviceName, String extraName) {
+        if (log.isDebugEnabled()) {
+            log.debug("ActivateUtils.findService serviceName: " + serviceName +", extraName: "
+                + extraName);
+        }
+
         HashMap services = axisConfig.getServices();
 
         Iterator its = services.values().iterator();
@@ -134,11 +180,19 @@
         while (its.hasNext()) {
             AxisService service = (AxisService) its.next();
 
-            String tmpServClassName = service.getClass().getName();
-            String tmpServName = service.getName();
-
-            if ((tmpServClassName.equals(serviceClassName)) && (tmpServName.equals(serviceName))) {
-                // trace point
+            if (checkAxisService(service, serviceClassName, serviceName, extraName)) {
+                // Store the original serviceName on the service for use in findServiceGroup
+                // This is the name from when the service was originally externalized.
+                try {
+                    service.addParameter(EXTERNALIZED_AXIS_SERVICE_NAME, serviceName);
+                } catch (AxisFault e) {
+                    // I don't think this can actually ever happen.  The exception occurs if the
+                    // parameter is locked, but this is the only code that references that parameter
+                    if (log.isDebugEnabled()) {
+                        log.debug("Got fault trying to add parameter " + EXTERNALIZED_AXIS_SERVICE_NAME +
+                                " for service name " + serviceName + " to AxisService " + service, e); 
+                    }
+                }
                 if (log.isTraceEnabled()) {
                     log.trace("ObjectStateUtils:findService(): returning  [" + serviceClassName
                             + "]   [" + serviceName + "]");
@@ -157,6 +211,79 @@
         return null;
     }
     
+    private static boolean checkAxisService(AxisService serviceToCheck,
+            String serviceClassName, String externalizedServiceName, String externalizedExtraName) {
+        boolean serviceIsSame = false;
+
+        String checkServiceClassName = serviceToCheck.getClass().getName();
+        String checkServiceName = serviceToCheck.getName();
+        String checkServiceExtraName = getAxisServiceExternalizeExtraName(serviceToCheck);
+
+        if (checkServiceClassName.equals(serviceClassName)) {
+            if ((externalizedExtraName == null || checkServiceExtraName == null)
+                    && checkServiceName.equals(externalizedServiceName)) {
+                // If we don't have an externalized extra name or there is no
+                // externalized extra name information in the current Axis Service, then 
+                // check the simple case where the AxisService names match
+                serviceIsSame = true;
+            } else if (externalizedExtraName != null && checkServiceExtraName != null
+                    && checkServiceExtraName.equals(externalizedExtraName)){
+                // If the ServiceQname and Port Name match, then this is the right service
+                serviceIsSame = true;
+            } else {
+                // This is not an error necessarily; just iterating through all of AxisServices
+                // and some won't match.
+                if (log.isDebugEnabled()) {
+                    log.debug("No match: checking Externalized AxisService name: " + externalizedServiceName 
+                            + " and extraName: " + externalizedServiceName 
+                            + " against existing AxisService name: " + checkServiceName
+                            + " and extrAname: " + checkServiceExtraName);
+                }
+            }
+        }
+        return serviceIsSame;
+        
+    }
+
+    // This String separates the ServiceQName and the Port LocalName in the extraName field
+    // It is not a valid value in a QName so it can not accidently appear in a valid QName.
+    private static String DELIMITER_SERVICE_PORT = " ";
+    /**
+     * Return a Sring that contains the service QName and port local name of an AxisService
+     * seperated by a delimiter.  This value can be used as part of externalizing an AxisService
+     * to provide additional information during deserialization in cases where the AxisService
+     * name is not unique or does not match for whatever reasons.  
+     * 
+     * @param axisService The AxisService to create the externalized name
+     * @return a String with the ServiceQName and port local name separated by DELIMITER_SERVICE_PORT
+     * if both values exist as parameters on the service; null otherwise.
+     */
+    public static String getAxisServiceExternalizeExtraName(AxisService axisService) {
+        String extraName = null;
+        String serviceQName = null;
+        String portName = null;
+        
+        Parameter serviceQNameParameter = 
+            axisService.getParameter(WSDL11ToAllAxisServicesBuilder.WSDL_SERVICE_QNAME);
+        if (serviceQNameParameter != null) {
+            serviceQName = serviceQNameParameter.getValue().toString();
+        }
+        
+        Parameter portNameParameter = 
+            axisService.getParameter(WSDL11ToAllAxisServicesBuilder.WSDL_PORT); 
+        if (portNameParameter != null) {
+            portName = (String) portNameParameter.getValue();
+        }
+        
+        if (serviceQName != null && portName != null) {
+            extraName = serviceQName + DELIMITER_SERVICE_PORT +  portName;
+        }
+        
+        return extraName;
+    }
+    
+
+
     /**
      * Find the AxisOperation object that matches the criteria
      * 

Added: webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/context/externalize/ActivateUtilsTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/context/externalize/ActivateUtilsTest.java?rev=818641&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/context/externalize/ActivateUtilsTest.java (added)
+++ webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/context/externalize/ActivateUtilsTest.java Thu Sep 24 22:10:26 2009
@@ -0,0 +1,151 @@
+/*
+ * 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.context.externalize;
+
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.description.AxisService;
+import org.apache.axis2.description.WSDL11ToAllAxisServicesBuilder;
+import org.apache.axis2.engine.AxisConfiguration;
+
+import javax.xml.namespace.QName;
+
+import junit.framework.TestCase;
+
+/**
+ * Validate the deserialization activation methods
+ */
+public class ActivateUtilsTest extends TestCase {
+    /**
+     * Try to find an AxisService in which the name matches and extraName is null.  This simulates
+     * deserializaing and activating an older version a MessageContext in which the extraName
+     * on the AxisService was not specified. 
+     * @throws AxisFault 
+     */
+    public void testFindServiceNoExtraNameFound() throws AxisFault {
+        AxisConfiguration axisCfg = new AxisConfiguration();
+
+        AxisService svc1 = new AxisService();
+        QName svc1QN = new QName("http://service.name/space/1", "service1");
+        String portName = "port1";
+        setupAxisService(svc1, svc1QN, portName);
+        axisCfg.addService(svc1);
+        
+        AxisService foundService = ActivateUtils.findService(axisCfg, AxisService.class.getName(), 
+                generateAxisServiceName(svc1QN, portName), null);
+        assertSame("Did not find expected AxisService using null extraName", svc1, foundService);
+        
+    }
+    
+    /**
+     * Test that with no extra name information, an axis service can not be found if the names
+     * don't match
+     * @throws AxisFault 
+     */
+    public void testFindServiceNoExtraNameNotFound() throws AxisFault {
+        AxisConfiguration axisCfg = new AxisConfiguration();
+
+        AxisService svc1 = new AxisService();
+        QName svc1QN = new QName("http://service.name/space/1", "service1");
+        String portName = "port1";
+        setupAxisService(svc1, svc1QN, portName);
+        axisCfg.addService(svc1);
+        
+        AxisService foundService = ActivateUtils.findService(axisCfg, AxisService.class.getName(), 
+                generateAxisServiceName(svc1QN, portName + "_NoMatch"), null);
+        assertNull("Should not have found a matching AxisService", foundService);
+        
+    }
+    
+    /**
+     * Test that with extra name information, an axis service can be found even if the 
+     * AxisService names don't match
+     * @throws AxisFault 
+     */
+    public void testFindServiceWithExtraName() throws AxisFault {
+        AxisConfiguration axisCfg = new AxisConfiguration();
+
+        AxisService svc1 = new AxisService();
+        QName svc1QN = new QName("http://service.name/space/1", "service1");
+        String portName = "port1";
+        setupAxisService(svc1, svc1QN, portName);
+        axisCfg.addService(svc1);
+        
+        String extraName = ActivateUtils.getAxisServiceExternalizeExtraName(svc1);
+        AxisService foundService = ActivateUtils.findService(axisCfg, AxisService.class.getName(), 
+                generateAxisServiceName(svc1QN, portName + "_NoMatch"), extraName);
+        assertSame("Did not find expected AxisService using null extraName", svc1, foundService);
+        
+    }
+    
+    /**
+     * Test that with extra name information that does not match the service, an axis service 
+     * is not found even if the service names DO match.  This test makes sure an AxisService that 
+     * happens to have the same name as a previously serialized one BUT is actually different since
+     * the Service QNames and Port Names are different is not found.
+     * @throws AxisFault 
+     */
+    public void testFindServiceWithExtraNameMistmatchNotFound() throws AxisFault {
+        AxisConfiguration axisCfg = new AxisConfiguration();
+
+        AxisService svc1 = new AxisService();
+        QName svc1QN = new QName("http://service.name/space/1", "service1");
+        String portName = "port1";
+        setupAxisService(svc1, svc1QN, portName);
+        axisCfg.addService(svc1);
+        
+        String extraName = ActivateUtils.getAxisServiceExternalizeExtraName(svc1) + "_NoMatch";
+        AxisService foundService = ActivateUtils.findService(axisCfg, AxisService.class.getName(), 
+                generateAxisServiceName(svc1QN, portName), extraName);
+        assertNull("Should not have found matching service without matching extraname", foundService);
+    }
+    
+    /**
+     * Test that with extra name information but no Parameters on the AxisService that the  
+     * service is found. 
+     * @throws AxisFault 
+     */
+    public void testFindServiceWithNoParametersFound() throws AxisFault {
+        AxisConfiguration axisCfg = new AxisConfiguration();
+
+        AxisService svc1 = new AxisService();
+        QName svc1QN = new QName("http://service.name/space/1", "service1");
+        String portName = "port1";
+        // We don't use the setup method since we do not want the parameters set on this
+        // service
+        // setupAxisService(svc1, svc1QN, portName);
+        svc1.setName(generateAxisServiceName(svc1QN, portName));
+        axisCfg.addService(svc1);
+        
+        String extraName = ActivateUtils.getAxisServiceExternalizeExtraName(svc1) + "_NoMatch";
+        AxisService foundService = ActivateUtils.findService(axisCfg, AxisService.class.getName(), 
+                generateAxisServiceName(svc1QN, portName), extraName);
+        assertSame("Should have found matching service without matching extraname", svc1, foundService);
+    }
+    
+
+    private void setupAxisService(AxisService axisService, QName serviceQN, String portName) throws AxisFault {
+        axisService.setName(generateAxisServiceName(serviceQN, portName));
+        axisService.addParameter(WSDL11ToAllAxisServicesBuilder.WSDL_SERVICE_QNAME, serviceQN);
+        axisService.addParameter(WSDL11ToAllAxisServicesBuilder.WSDL_PORT, portName);
+    }
+
+    private String generateAxisServiceName(QName serviceQN, String portName) {
+        return serviceQN.getLocalPart() + "." + portName;
+    }
+}