You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by em...@apache.org on 2010/12/15 01:07:47 UTC

svn commit: r1049357 - in /cxf/branches/2.3.x-fixes: rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/ rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/ systests/jaxws/src/test/java/org/apache/cxf/systest/handlers/

Author: ema
Date: Wed Dec 15 00:07:47 2010
New Revision: 1049357

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

........
  r1049341 | ema | 2010-12-15 07:52:21 +0800 (Wed, 15 Dec 2010) | 1 line
  
  [CXF-3188]:Not return the soap mustUnderstand fault for an one way operation
........

Modified:
    cxf/branches/2.3.x-fixes/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/MustUnderstandInterceptor.java
    cxf/branches/2.3.x-fixes/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/MustUnderstandInterceptorTest.java
    cxf/branches/2.3.x-fixes/systests/jaxws/src/test/java/org/apache/cxf/systest/handlers/HandlerInvocationTest.java

Modified: cxf/branches/2.3.x-fixes/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/MustUnderstandInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/MustUnderstandInterceptor.java?rev=1049357&r1=1049356&r2=1049357&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/MustUnderstandInterceptor.java (original)
+++ cxf/branches/2.3.x-fixes/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/MustUnderstandInterceptor.java Wed Dec 15 00:07:47 2010
@@ -43,15 +43,18 @@ import org.apache.cxf.headers.Header;
 import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.interceptor.Interceptor;
+import org.apache.cxf.interceptor.OneWayProcessorInterceptor;
 import org.apache.cxf.phase.Phase;
 
 public class MustUnderstandInterceptor extends AbstractSoapInterceptor {
-
+    public static final String FAULT = "MustUnderstand.Fault";
 
     private static final Logger LOG = LogUtils.getL7dLogger(MustUnderstandInterceptor.class);
 
     private static final ResourceBundle BUNDLE = LOG.getResourceBundle();
-
+    
+    private MustUnderstandEndingInterceptor ending = new MustUnderstandEndingInterceptor();
+        
     public MustUnderstandInterceptor() {
         super(Phase.PRE_PROTOCOL);
     }
@@ -80,12 +83,18 @@ public class MustUnderstandInterceptor e
         checkUnderstand(mustUnderstandHeaders, mustUnderstandQNames, notUnderstandHeaders);
         
         if (!notUnderstandHeaders.isEmpty()) {
-            throw new SoapFault(new Message("MUST_UNDERSTAND", BUNDLE, notUnderstandHeaders),
-                            soapVersion.getMustUnderstand());
+            SoapFault soapFault = new SoapFault(new Message("MUST_UNDERSTAND", BUNDLE, notUnderstandHeaders),
+                                                soapVersion.getMustUnderstand());
+            if (!isRequestor(soapMessage)) {
+                soapMessage.put(MustUnderstandInterceptor.FAULT, soapFault);
+            } else {
+                throw soapFault;
+            }
         }
         if (!ultimateReceiverHeaders.isEmpty() && !isRequestor(soapMessage)) {
             checkUltimateReceiverHeaders(ultimateReceiverHeaders, mustUnderstandQNames, soapMessage);
         }
+        soapMessage.getInterceptorChain().add(ending);
     }
 
     private void checkUltimateReceiverHeaders(Set<Header> ultimateReceiverHeaders,
@@ -126,8 +135,11 @@ public class MustUnderstandInterceptor e
                 }
             }
             if (!notFound.isEmpty()) {
-                throw new SoapFault(new Message("MUST_UNDERSTAND", BUNDLE, notFound),
-                                soapMessage.getVersion().getMustUnderstand());
+                // Defer throwing soap fault exception in SOAPHeaderInterceptor once the isOneway can
+                // be detected
+                SoapFault soapFault = new SoapFault(new Message("MUST_UNDERSTAND", BUNDLE, notFound),
+                                                    soapMessage.getVersion().getMustUnderstand());
+                soapMessage.put(MustUnderstandInterceptor.FAULT, soapFault);
             }
         }
     }
@@ -230,4 +242,25 @@ public class MustUnderstandInterceptor e
         }
 
     }
+    
+    public class MustUnderstandEndingInterceptor extends AbstractSoapInterceptor {
+        public MustUnderstandEndingInterceptor() {
+            super(Phase.PRE_LOGICAL);
+            addAfter(OneWayProcessorInterceptor.class.getName());
+        }
+
+        public MustUnderstandEndingInterceptor(String phase) {
+            super(phase);
+        }
+
+        @Override
+        public void handleMessage(SoapMessage message) throws Fault {
+            // throws soapFault after the response code 202 is set in OneWayProcessorInterceptor
+            if (message.get(MustUnderstandInterceptor.FAULT) != null) {
+                SoapFault soapFault = (SoapFault)message.get(MustUnderstandInterceptor.FAULT);
+                throw soapFault;
+            }
+        }
+    }
+
 }

Modified: cxf/branches/2.3.x-fixes/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/MustUnderstandInterceptorTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/MustUnderstandInterceptorTest.java?rev=1049357&r1=1049356&r2=1049357&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/MustUnderstandInterceptorTest.java (original)
+++ cxf/branches/2.3.x-fixes/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/MustUnderstandInterceptorTest.java Wed Dec 15 00:07:47 2010
@@ -99,7 +99,7 @@ public class MustUnderstandInterceptorTe
         assertEquals("DummaySoapInterceptor getUnderstood has been called!", true, dsi
             .isCalledGetUnderstood());
 
-        SoapFault ie = (SoapFault)soapMessage.getContent(Exception.class);
+        SoapFault ie = (SoapFault)soapMessage.get(MustUnderstandInterceptor.FAULT);
         if (ie == null) {
             fail("InBound Exception Missing! Exception should be Can't understands QNames: " + PASSENGER);
         } else {

Modified: cxf/branches/2.3.x-fixes/systests/jaxws/src/test/java/org/apache/cxf/systest/handlers/HandlerInvocationTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/systests/jaxws/src/test/java/org/apache/cxf/systest/handlers/HandlerInvocationTest.java?rev=1049357&r1=1049356&r2=1049357&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/systests/jaxws/src/test/java/org/apache/cxf/systest/handlers/HandlerInvocationTest.java (original)
+++ cxf/branches/2.3.x-fixes/systests/jaxws/src/test/java/org/apache/cxf/systest/handlers/HandlerInvocationTest.java Wed Dec 15 00:07:47 2010
@@ -1186,6 +1186,20 @@ public class HandlerInvocationTest exten
             assertEquals(expected, iter.next());
         }
     }
+    
+    @Test
+    public void testMustUnderstandSoapFaultOneWay() {
+        TestMustUnderstandHandler<SOAPMessageContext> handler = 
+            new TestMustUnderstandHandler<SOAPMessageContext>();
+        addHandlersToChain((BindingProvider)handlerTest, handler);
+        try {
+            handlerTest.pingOneWay();
+        } catch (Exception e) {
+            fail("Catch unexpected exception: soap faule message " 
+                 + "should not be returned for one way operation");
+        }
+
+    }
 
     void addHandlersToChain(BindingProvider bp, Handler... handlers) {
         List<Handler> handlerChain = bp.getBinding().getHandlerChain();



Re: svn commit: r1049357 - in /cxf/branches/2.3.x-fixes: rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/ rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/ systests/jaxws/src/test/java/org/apache/cxf/systest/handlers/

Posted by Jim Ma <ma...@gmail.com>.
Right , Dan. No need to add this interceptor in the client side.
Thanks for the review and committed the optimized code in revision 1049415.

On Wed, Dec 15, 2010 at 8:18 AM, Daniel Kulp <dk...@apache.org> wrote:
>
> Jim,
>
>
> On Tuesday 14 December 2010 7:07:47 pm ema@apache.org wrote:
>> MustUnderstandEndingInterceptor(); +
>>      public MustUnderstandInterceptor() {
>>          super(Phase.PRE_PROTOCOL);
>>      }
>> @@ -80,12 +83,18 @@ public class MustUnderstandInterceptor e
>>          checkUnderstand(mustUnderstandHeaders, mustUnderstandQNames,
>> notUnderstandHeaders);
>>
>>          if (!notUnderstandHeaders.isEmpty()) {
>> -            throw new SoapFault(new Message("MUST_UNDERSTAND", BUNDLE,
>> notUnderstandHeaders), -
>> soapVersion.getMustUnderstand());
>> +            SoapFault soapFault = new SoapFault(new
>> Message("MUST_UNDERSTAND", BUNDLE, notUnderstandHeaders), +
>>                                 soapVersion.getMustUnderstand()); +
>>     if (!isRequestor(soapMessage)) {
>> +                soapMessage.put(MustUnderstandInterceptor.FAULT,
>> soapFault); +            } else {
>> +                throw soapFault;
>> +            }
>>          }
>>          if (!ultimateReceiverHeaders.isEmpty() &&
>> !isRequestor(soapMessage)) {
>> checkUltimateReceiverHeaders(ultimateReceiverHeaders,
>> mustUnderstandQNames, soapMessage); }
>> +        soapMessage.getInterceptorChain().add(ending);
>>      }
>
>
> Can this be optimized a bit?   Basically, could the call to:
>
> soapMessage.getInterceptorChain().add(ending);
>
> be placed into the
>  if (!isRequestor(soapMessage)) {
>
> block?   Since the interceptor only does anything if that block is called, we
> don't need to add it for every invokation.   Right?
>
> --
> Daniel Kulp
> dkulp@apache.org
> http://dankulp.com/blog
>

Re: svn commit: r1049357 - in /cxf/branches/2.3.x-fixes: rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/ rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/ systests/jaxws/src/test/java/org/apache/cxf/systest/handlers/

Posted by Daniel Kulp <dk...@apache.org>.
Jim,


On Tuesday 14 December 2010 7:07:47 pm ema@apache.org wrote:
> MustUnderstandEndingInterceptor(); +
>      public MustUnderstandInterceptor() {
>          super(Phase.PRE_PROTOCOL);
>      }
> @@ -80,12 +83,18 @@ public class MustUnderstandInterceptor e
>          checkUnderstand(mustUnderstandHeaders, mustUnderstandQNames,
> notUnderstandHeaders);
> 
>          if (!notUnderstandHeaders.isEmpty()) {
> -            throw new SoapFault(new Message("MUST_UNDERSTAND", BUNDLE,
> notUnderstandHeaders), -                           
> soapVersion.getMustUnderstand());
> +            SoapFault soapFault = new SoapFault(new
> Message("MUST_UNDERSTAND", BUNDLE, notUnderstandHeaders), +               
>                                 soapVersion.getMustUnderstand()); +       
>     if (!isRequestor(soapMessage)) {
> +                soapMessage.put(MustUnderstandInterceptor.FAULT,
> soapFault); +            } else {
> +                throw soapFault;
> +            }
>          }
>          if (!ultimateReceiverHeaders.isEmpty() &&
> !isRequestor(soapMessage)) {
> checkUltimateReceiverHeaders(ultimateReceiverHeaders,
> mustUnderstandQNames, soapMessage); }
> +        soapMessage.getInterceptorChain().add(ending);
>      }


Can this be optimized a bit?   Basically, could the call to:

soapMessage.getInterceptorChain().add(ending);

be placed into the 
 if (!isRequestor(soapMessage)) {

block?   Since the interceptor only does anything if that block is called, we 
don't need to add it for every invokation.   Right?

-- 
Daniel Kulp
dkulp@apache.org
http://dankulp.com/blog