cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject svn commit: r563760 - in /incubator/cxf/trunk: systests/src/test/java/org/apache/cxf/systest/versioning/ testutils/src/main/java/org/apache/hello_world_mixedstyle/
Date Wed, 08 Aug 2007 06:08:54 GMT
Author: ningjiang
Date: Tue Aug  7 23:08:54 2007
New Revision: 563760

URL: http://svn.apache.org/viewvc?view=rev&rev=563760
Log:
Fixed the MediatorInInterceptor's test case

Modified:
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/versioning/ClientServerVersioningTest.java
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/versioning/MediatorInInterceptor.java
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/versioning/Server.java
    incubator/cxf/trunk/testutils/src/main/java/org/apache/hello_world_mixedstyle/GreeterImplMixedStyle.java

Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/versioning/ClientServerVersioningTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/versioning/ClientServerVersioningTest.java?view=diff&rev=563760&r1=563759&r2=563760
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/versioning/ClientServerVersioningTest.java
(original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/versioning/ClientServerVersioningTest.java
Tue Aug  7 23:08:54 2007
@@ -24,7 +24,6 @@
 import javax.xml.namespace.QName;
 
 
-import org.apache.cxf.systest.jaxws.ServerMixedStyle;
 import org.apache.cxf.testutil.common.AbstractClientServerTestBase;
 import org.apache.hello_world_mixedstyle.Greeter;
 import org.apache.hello_world_mixedstyle.SOAPService;
@@ -39,7 +38,7 @@
 
     @BeforeClass
     public static void startServers() throws Exception {
-        assertTrue("server did not launch correctly", launchServer(ServerMixedStyle.class));
+        assertTrue("server did not launch correctly", launchServer(Server.class));
     }
     
     @Test
@@ -55,11 +54,11 @@
             request.setRequestType("Bonjour");
             GreetMeResponse greeting = greeter.greetMe(request);
             assertNotNull("no response received from service", greeting);
-            assertEquals("Hello Bonjour", greeting.getResponseType());
+            assertEquals("Hello Bonjour version1", greeting.getResponseType());
 
             String reply = greeter.sayHi();
             assertNotNull("no response received from service", reply);
-            assertEquals("Bonjour", reply);
+            assertEquals("Bonjour version2", reply);
         } catch (UndeclaredThrowableException ex) {
             throw (Exception)ex.getCause();
         }

Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/versioning/MediatorInInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/versioning/MediatorInInterceptor.java?view=diff&rev=563760&r1=563759&r2=563760
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/versioning/MediatorInInterceptor.java
(original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/versioning/MediatorInInterceptor.java
Tue Aug  7 23:08:54 2007
@@ -19,15 +19,20 @@
 
 package org.apache.cxf.systest.versioning;
 
+
+import java.io.InputStream;
 import java.util.Set;
 
-import javax.xml.stream.XMLStreamException;
+
+
 import javax.xml.stream.XMLStreamReader;
 
 import org.apache.cxf.endpoint.Endpoint;
+import org.apache.cxf.helpers.IOUtils;
 import org.apache.cxf.interceptor.AbstractEndpointSelectionInterceptor;
 import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.interceptor.StaxInInterceptor;
+import org.apache.cxf.io.CachedOutputStream;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.phase.Phase;
 
@@ -41,33 +46,54 @@
 
     @Override
     protected Endpoint selectEndpoint(Message message, Set<Endpoint> eps) {
-        XMLStreamReader xsr = message.getContent(XMLStreamReader.class);
-        if (!xsr.isStartElement()) {
-            try {
-                xsr.nextTag();
-            } catch (XMLStreamException e) {
-                throw new Fault(e);
-            }
-        }
         
-        if (!xsr.isStartElement()) {
+        InputStream is = message.getContent(InputStream.class);        
+        if (is == null) {
             return null;
         }
+        //cache the input stream
+        CachedOutputStream bos = new CachedOutputStream();
+        try {
+            IOUtils.copy(is, bos);
+            is.close();
+            bos.close();
+            
+            message.setContent(InputStream.class, bos.getInputStream());
         
-        String schemaNamespace = xsr.getNamespaceURI();
-        
-        //if the incoming message has a namespace contained "2007/03/21", we redirect the
message
-        //to the new version of service on endpoint "local://localhost:9027/SoapContext/version2/SoapPort"
-        for (Endpoint ep : eps) {
-            if (schemaNamespace.indexOf("2007/03/21") != -1) {
-                if ("2".equals(ep.get("version"))) {
+            String encoding = (String)message.get(Message.ENCODING);
+
+            XMLStreamReader xsr;
+            xsr = StaxInInterceptor.getXMLInputFactory(message).
+                createXMLStreamReader(bos.getInputStream(), encoding);
+            // move to the soap body            
+            while (true) {                
+                xsr.nextTag();              
+                
+                if ("Body".equals(xsr.getName().getLocalPart())) {
+                    break;
+                }
+            }
+            
+            xsr.nextTag();
+            if (!xsr.isStartElement()) {
+                return null;
+            }
+            
+            String methodName = xsr.getName().getLocalPart();
+            //if the incoming message has a element containes "SayHi", we redirect the message
+            //to the new version of service on endpoint "local://localhost:9027/SoapContext/version2/SoapPort"
+            for (Endpoint ep : eps) {               
+                if (methodName.indexOf("sayHi") != -1) {
+                    if ("2".equals(ep.get("version"))) {
+                        return ep;
+                    }
+                } else if ("1".equals(ep.get("version"))) {
                     return ep;
                 }
-            } else if ("1".equals(ep.get("version"))) {
-                return ep;
             }
-        }
-
+        } catch (Exception e) {
+            throw new Fault(e);
+        }    
         return null;
     }
 

Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/versioning/Server.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/versioning/Server.java?view=diff&rev=563760&r1=563759&r2=563760
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/versioning/Server.java
(original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/versioning/Server.java
Tue Aug  7 23:08:54 2007
@@ -32,12 +32,12 @@
     protected void run() {
         String address = "http://localhost:9027/SoapContext/SoapPort";
 
-        Object implementor1 = new GreeterImplMixedStyle();
+        Object implementor1 = new GreeterImplMixedStyle(" version1");
         EndpointImpl ep1 = (EndpointImpl) Endpoint.publish(address, implementor1);
 
         ep1.getServer().getEndpoint().put("version", "1");
         
-        Object implementor2 = new GreeterImplMixedStyle();
+        Object implementor2 = new GreeterImplMixedStyle(" version2");
         EndpointImpl ep2 = (EndpointImpl) Endpoint.publish(address, implementor2);
         ep2.getServer().getEndpoint().put("version", "2");
         

Modified: incubator/cxf/trunk/testutils/src/main/java/org/apache/hello_world_mixedstyle/GreeterImplMixedStyle.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/testutils/src/main/java/org/apache/hello_world_mixedstyle/GreeterImplMixedStyle.java?view=diff&rev=563760&r1=563759&r2=563760
==============================================================================
--- incubator/cxf/trunk/testutils/src/main/java/org/apache/hello_world_mixedstyle/GreeterImplMixedStyle.java
(original)
+++ incubator/cxf/trunk/testutils/src/main/java/org/apache/hello_world_mixedstyle/GreeterImplMixedStyle.java
Tue Aug  7 23:08:54 2007
@@ -31,16 +31,25 @@
             targetNamespace = "http://apache.org/hello_world_mixedstyle",
             wsdlLocation = "testutils/hello_world_mixedstyle.wsdl")
 public class GreeterImplMixedStyle implements Greeter {
+    private String version;
+    
+    public GreeterImplMixedStyle() {
+        version = "";
+    }
+    
+    public GreeterImplMixedStyle(String v) {
+        version = v;
+    }
 
     public String sayHi() {
         System.out.println("Call sayHi here ");
-        return "Bonjour";
+        return "Bonjour" + version;
     }
 
     public GreetMeResponse greetMe(GreetMe1 requestType) {
         System.out.println("Call greetMe here: " + requestType.getRequestType());
         GreetMeResponse response = new GreetMeResponse();
-        response.setResponseType("Hello " + requestType.getRequestType());
+        response.setResponseType("Hello " + requestType.getRequestType() + version);
         return response;
     }
 



Mime
View raw message