You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2011/12/05 19:28:20 UTC

svn commit: r1210560 - in /cxf/branches/2.4.x-fixes: ./ rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/ rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/ systests/jaxws/src/test/java/org/apache/cxf/systest/provider/

Author: dkulp
Date: Mon Dec  5 18:28:20 2011
New Revision: 1210560

URL: http://svn.apache.org/viewvc?rev=1210560&view=rev
Log:
Merged revisions 1205558 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1205558 | ay | 2011-11-23 15:04:12 -0500 (Wed, 23 Nov 2011) | 1 line
  
  [CXF-3926] supporting jaxws provider's null response handling
........

Added:
    cxf/branches/2.4.x-fixes/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/InterpretNullAsOnewayProviderTest.java
      - copied unchanged from r1205558, cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/InterpretNullAsOnewayProviderTest.java
Modified:
    cxf/branches/2.4.x-fixes/   (props changed)
    cxf/branches/2.4.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JAXWSMethodInvoker.java
    cxf/branches/2.4.x-fixes/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/JAXWSMethodInvokerTest.java

Propchange: cxf/branches/2.4.x-fixes/
            ('svn:mergeinfo' removed)

Propchange: cxf/branches/2.4.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.4.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JAXWSMethodInvoker.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JAXWSMethodInvoker.java?rev=1210560&r1=1210559&r2=1210560&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JAXWSMethodInvoker.java (original)
+++ cxf/branches/2.4.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JAXWSMethodInvoker.java Mon Dec  5 18:28:20 2011
@@ -59,6 +59,14 @@ public class JAXWSMethodInvoker extends 
                 params = Collections.singletonList(null);
             }
             res = CastUtils.cast((List)super.invoke(exchange, serviceObject, m, params));
+            if ((serviceObject instanceof Provider) 
+                && Boolean.TRUE.equals(exchange.getInMessage().
+                                       getContextualProperty("jaxws.provider.interpretNullAsOneway"))
+                && (res != null && !res.isEmpty() && res.get(0) == null)) {
+                // treat the non-oneway call as oneway when a provider returns null
+                res = null;
+                changeToOneway(exchange);
+            }
             //update the webservice response context
             updateWebServiceContext(exchange, ctx);
         } catch (Fault f) {
@@ -73,5 +81,15 @@ public class JAXWSMethodInvoker extends 
         }
         return res;
     }
+
+    private void changeToOneway(Exchange exchange) {
+        exchange.setOneWay(true);
+        javax.servlet.http.HttpServletResponse httpresp = 
+            (javax.servlet.http.HttpServletResponse)exchange.getInMessage().
+                get("HTTP.RESPONSE");
+        if (httpresp != null) {
+            httpresp.setStatus(202);
+        }
+    }
     
 }

Modified: cxf/branches/2.4.x-fixes/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/JAXWSMethodInvokerTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/JAXWSMethodInvokerTest.java?rev=1210560&r1=1210559&r2=1210560&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/JAXWSMethodInvokerTest.java (original)
+++ cxf/branches/2.4.x-fixes/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/JAXWSMethodInvokerTest.java Mon Dec  5 18:28:20 2011
@@ -19,10 +19,17 @@
 package org.apache.cxf.jaxws;
 
 
+import java.lang.reflect.Method;
+
+import javax.xml.transform.Source;
+import javax.xml.transform.stream.StreamSource;
+import javax.xml.ws.Provider;
+
 import org.apache.cxf.continuations.SuspendedInvocationException;
 import org.apache.cxf.frontend.MethodDispatcher;
 import org.apache.cxf.jaxws.service.Hello;
 import org.apache.cxf.message.Exchange;
+import org.apache.cxf.message.ExchangeImpl;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.message.MessageContentsList;
 import org.apache.cxf.message.MessageImpl;
@@ -53,55 +60,107 @@ public class JAXWSMethodInvokerTest exte
 
     @Test
     public void testSuspendedException() throws Throwable {
-        Exchange ex = EasyMock.createNiceMock(Exchange.class);               
-        
         Exception originalException = new RuntimeException();
         ContinuationService serviceObject = 
             new ContinuationService(originalException);
+        Method serviceMethod = ContinuationService.class.getMethod("invoke", new Class[]{});
+        
+        Exchange ex = new ExchangeImpl();
+        Message inMessage = new MessageImpl();
+        ex.setInMessage(inMessage);
+        inMessage.setExchange(ex);
+        inMessage.put(Message.REQUESTOR_ROLE, Boolean.TRUE);
+
+        JAXWSMethodInvoker jaxwsMethodInvoker = prepareJAXWSMethodInvoker(ex, serviceObject, serviceMethod);
+        try {
+            jaxwsMethodInvoker.invoke(ex, new MessageContentsList(new Object[]{}));
+            fail("Suspended invocation swallowed");
+        } catch (SuspendedInvocationException suspendedEx) {
+            assertSame(suspendedEx, serviceObject.getSuspendedException());
+            assertSame(originalException, suspendedEx.getRuntimeException());
+        }
+    }
+    
+    @Test
+    public void testProviderInterpretNullAsOneway() throws Throwable {
+        NullableProviderService serviceObject = new NullableProviderService();
+        Method serviceMethod = NullableProviderService.class.getMethod("invoke", new Class[]{Source.class});
+        
+        Exchange ex = new ExchangeImpl();
+        Message inMessage = new MessageImpl();
+        ex.setInMessage(inMessage);
+        inMessage.setExchange(ex);
+        inMessage.put(Message.REQUESTOR_ROLE, Boolean.TRUE);
+        
+        JAXWSMethodInvoker jaxwsMethodInvoker = prepareJAXWSMethodInvoker(ex, serviceObject, serviceMethod);
+        
+        // request-response with non-null response
+        ex.setOneWay(false);
+        MessageContentsList obj = (MessageContentsList)jaxwsMethodInvoker.invoke(
+            ex, new MessageContentsList(new Object[]{new StreamSource()}));
+        assertEquals(1, obj.size());
+        assertNotNull(obj.get(0));
+        assertFalse(ex.isOneWay());
+
+        // oneway with non-null response
+        ex.setOneWay(true);
+        obj = (MessageContentsList)jaxwsMethodInvoker.invoke(
+            ex, new MessageContentsList(new Object[]{new StreamSource()}));
+        assertNull(obj);
+        assertTrue(ex.isOneWay());
+
+        // request-response with null response, interpretNullAsOneway disabled
+        ex.setOneWay(false);
+        serviceObject.setNullable(true);
+        obj = (MessageContentsList)jaxwsMethodInvoker.invoke(
+            ex, new MessageContentsList(new Object[]{new StreamSource()}));
+        assertEquals(1, obj.size());
+        assertNull(obj.get(0));
+        assertFalse(ex.isOneWay());
+
+        // request-response with null response, interpretNullAsOneway enabled
+        ex.setOneWay(false);
+        serviceObject.setNullable(true);
+        inMessage.setContextualProperty("jaxws.provider.interpretNullAsOneway", Boolean.TRUE);
+        obj = (MessageContentsList)jaxwsMethodInvoker.invoke(
+            ex, new MessageContentsList(new Object[]{new StreamSource()}));
+        assertNull(obj);
+        assertTrue(ex.isOneWay());
+    }
+
+    private JAXWSMethodInvoker prepareJAXWSMethodInvoker(Exchange ex, Object serviceObject,
+                                                         Method serviceMethod) throws Throwable {
         EasyMock.reset(factory);
         factory.create(ex);
-        EasyMock.expectLastCall().andReturn(serviceObject);
+        EasyMock.expectLastCall().andReturn(serviceObject).anyTimes();
         factory.release(ex, serviceObject);
-        EasyMock.expectLastCall();
+        EasyMock.expectLastCall().anyTimes();
         EasyMock.replay(factory);
-                        
-        Message inMessage = new MessageImpl();
-        ex.getInMessage();
-        EasyMock.expectLastCall().andReturn(inMessage);
-        inMessage.setExchange(ex);
-        inMessage.put(Message.REQUESTOR_ROLE, Boolean.TRUE);
-                
-        BindingOperationInfo boi = EasyMock.createMock(BindingOperationInfo.class);
-        ex.get(BindingOperationInfo.class);
-        EasyMock.expectLastCall().andReturn(boi);
+        
+        BindingOperationInfo boi = new BindingOperationInfo();
+        ex.put(BindingOperationInfo.class, boi);
         
         Service serviceClass = EasyMock.createMock(Service.class);
-        ex.get(Service.class);
-        EasyMock.expectLastCall().andReturn(serviceClass);
+        serviceClass.size();
+        EasyMock.expectLastCall().andReturn(0).anyTimes();
+        ex.put(Service.class, serviceClass);
         
         MethodDispatcher md = EasyMock.createMock(MethodDispatcher.class);
         serviceClass.get(MethodDispatcher.class.getName());
-        EasyMock.expectLastCall().andReturn(md);
+        EasyMock.expectLastCall().andReturn(md).anyTimes();
         
         md.getMethod(boi);
-        EasyMock.expectLastCall().andReturn(
-            ContinuationService.class.getMethod("invoke", new Class[]{}));
+        EasyMock.expectLastCall().andReturn(serviceMethod).anyTimes();
         
-        EasyMock.replay(ex);
         EasyMock.replay(md);
         EasyMock.replay(serviceClass);
-        
-        JAXWSMethodInvoker jaxwsMethodInvoker = new JAXWSMethodInvoker(factory);
-        try {
-            jaxwsMethodInvoker.invoke(ex, new MessageContentsList(new Object[]{}));
-            fail("Suspended invocation swallowed");
-        } catch (SuspendedInvocationException suspendedEx) {
-            assertSame(suspendedEx, serviceObject.getSuspendedException());
-            assertSame(originalException, suspendedEx.getRuntimeException());
-        }
-        
+
+        // initialize the contextCache
+        ex.getInMessage().getContextualProperty("dummy");
+
+        return new JAXWSMethodInvoker(factory);
     }
-    
+
     public static class ContinuationService {
         private RuntimeException ex;
         
@@ -117,4 +176,16 @@ public class JAXWSMethodInvokerTest exte
             return ex;
         }
     }
+    
+    public static class NullableProviderService implements Provider<Source> {
+        private boolean nullable;
+        
+        public void setNullable(boolean nullable) {
+            this.nullable = nullable;
+        }
+        
+        public Source invoke(Source request) {
+            return nullable ? null : request;
+        }
+    }
 }