axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From barre...@apache.org
Subject svn commit: r818838 - in /webservices/axis2/trunk/java/modules: jaxws/test/org/apache/axis2/jaxws/client/PortDeserializationTests.java kernel/src/org/apache/axis2/context/externalize/ActivateUtils.java
Date Fri, 25 Sep 2009 12:40:54 GMT
Author: barrettj
Date: Fri Sep 25 12:40:53 2009
New Revision: 818838

URL: http://svn.apache.org/viewvc?rev=818838&view=rev
Log:
Fix the activation of a deserialized AxisService to look use an exact name match if one is
found and use the Service QName/Port local name match if an exact match can't be found.

Update the test to validate that.

Modified:
    webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/client/PortDeserializationTests.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/externalize/ActivateUtils.java

Modified: 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=818838&r1=818837&r2=818838&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/client/PortDeserializationTests.java
(original)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/client/PortDeserializationTests.java
Fri Sep 25 12:40:53 2009
@@ -178,8 +178,23 @@
             // 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
+            // Note that we do them in reverse order to make sure the logic is order-independent
+            
+            // Do the same for the second Message Context
+            MessageContext mcRead2 = deserializeMessageContext(baos2);
+            ConfigurationContext configContext2 = endpointDesc2.getServiceDescription().getAxisConfigContext();
+            assertNotNull(configContext2);
+            mcRead2.activate(configContext2);
+            AxisService asRead2 = mcRead2.getAxisService();
+            assertNotNull(asRead2);
+            assertEquals(axisService2.getName(), asRead2.getName());
+            assertSame(axisService2, asRead2);
+            AxisServiceGroup agRead2 = mcRead2.getAxisServiceGroup();
+            assertNotNull(agRead2);
+
             MessageContext mcRead1 = deserializeMessageContext(baos1);
             ConfigurationContext configContext1 = endpointDesc1.getServiceDescription().getAxisConfigContext();
+            assertSame(configContext1, configContext2);
             assertNotNull(configContext1);
             mcRead1.activate(configContext1);
             AxisService asRead1 = mcRead1.getAxisService();
@@ -190,11 +205,98 @@
             assertNotNull(agRead1);
 
             
+            // 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 not being recreated.  This is similar to a message
+     * being serialized and deserialized without the server being stopped.
+     * 
+     * This test uses two services with the same namespaces, each with a dynamic port of
the
+     * same name.
+     */
+    public void testDynamicPortMultipleServiceNoRecreateSameNS() {
+        try {
+            ClientMetadataTest.installCachingFactory();
+            QName svc1QN = new QName(namespaceURI + "?1", svcLocalPart);
+            QName svc2QN = new QName(namespaceURI + "?1", 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);
+            assertNotNull(configContext2);
             mcRead2.activate(configContext2);
             AxisService asRead2 = mcRead2.getAxisService();
             assertNotNull(asRead2);
@@ -202,7 +304,7 @@
             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);
@@ -215,6 +317,7 @@
             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


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=818838&r1=818837&r2=818838&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
Fri Sep 25 12:40:53 2009
@@ -172,34 +172,53 @@
             log.debug("ActivateUtils.findService serviceName: " + serviceName +", extraName:
"
                 + extraName);
         }
-
         HashMap services = axisConfig.getServices();
 
         Iterator its = services.values().iterator();
 
-        while (its.hasNext()) {
+        // We loop through all the axis services looking for an exact match of the name,
and if 
+        // it exists, the extra information of the fully qualified Service QName and the
port
+        // name.  If we find an exact match, including the name of the service, we stop looking.
+        // If no exact match is found after searching the entire list, then we use the first

+        // match of the extra information we found.  Note that picking the first one found
is arbitrary.
+        boolean exactServiceNameMatch = false;
+        AxisService foundService = null;
+        while (its.hasNext() && !exactServiceNameMatch) {
             AxisService service = (AxisService) its.next();
-
-            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 + "]");
+            switch(checkAxisService(service, serviceClassName, serviceName, extraName)) {
+            case NAME_MATCH:
+                foundService = service;
+                exactServiceNameMatch = true;
+                break;
+            case SERVICE_PORT_MATCH:
+                if (foundService == null) {
+                    foundService = service;
+                }
+                break;
+            case NONE:
+                break;
+            }
+        }
+        if (foundService != null) {
+            // Store the original serviceName on the service for use in findServiceGroup
+            // This is the name from when the service was originally externalized.
+            try {
+                foundService.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 " + foundService,
e); 
                 }
-
-                return service;
             }
+            if (log.isTraceEnabled()) {
+                log.trace("ObjectStateUtils:findService(): returning  [" + serviceClassName
+                        + "]   [" + serviceName + "] AxisService name [" + foundService.getName()
+                        + "]");
+            }
+
+            return foundService;
         }
 
         // trace point
@@ -207,40 +226,59 @@
             log.trace("ObjectStateUtils:findService(): [" + serviceClassName + "]   ["
                     + serviceName + "]  returning  [null]");
         }
-
         return null;
     }
+    // NONE means no match at all, NAME_MATCH means the service names match and the service
and
+    // port names match if they exist, and SERVICE_PORT_MATCH means only the service and
port names
+    // match (not the service names).
+    private enum MatchType {NONE, NAME_MATCH, SERVICE_PORT_MATCH};
     
-    private static boolean checkAxisService(AxisService serviceToCheck,
+    /**
+     * Determine if the AxisService passed in is a match for the name information passed
in.
+     * The type of match is returned as an enum.
+     * 
+     * @param serviceToCheck The AxisService to check against the other parameters
+     * @param serviceClassName The name of class to look for
+     * @param externalizedServiceName The name of the Service to look for.
+     * @param externalizedExtraName Additional information beyond the name of the service
to look 
+     *  for
+     * @return MatchType indication of the type of match for the passed in AxisService.
+     */
+    private static MatchType checkAxisService(AxisService serviceToCheck,
             String serviceClassName, String externalizedServiceName, String externalizedExtraName)
{
-        boolean serviceIsSame = false;
+        MatchType serviceIsSame = MatchType.NONE;
 
         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;
+                serviceIsSame = MatchType.NAME_MATCH;
             } else if (externalizedExtraName != null && checkServiceExtraName !=
null
                     && checkServiceExtraName.equals(externalizedExtraName)){
-                // If the ServiceQname and Port Name match, then this is the right service
-                serviceIsSame = true;
+                // If the service names also match each other, then consider this a name
match
+                // otherwise it is just a service & port match
+                if (checkServiceName.equals(externalizedServiceName)) {
+                    serviceIsSame = MatchType.NAME_MATCH;
+                } else {
+                    serviceIsSame = MatchType.SERVICE_PORT_MATCH;
+                }
             } 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 
+                            + " and extraName: " + externalizedExtraName 
                             + " against existing AxisService name: " + checkServiceName
-                            + " and extrAname: " + checkServiceExtraName);
+                            + " and extraName: " + checkServiceExtraName);
                 }
             }
         }
+
         return serviceIsSame;
         
     }



Mime
View raw message