You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by ay...@apache.org on 2012/10/25 12:29:56 UTC

svn commit: r1402084 - in /cxf/trunk/rt/ws/rm/src: main/java/org/apache/cxf/ws/rm/RMInInterceptor.java test/java/org/apache/cxf/ws/rm/RMInInterceptorTest.java

Author: ay
Date: Thu Oct 25 10:29:56 2012
New Revision: 1402084

URL: http://svn.apache.org/viewvc?rev=1402084&view=rev
Log:
[CXF-4601] invlaid WS-RM messages to a robust WS-RM endpoint may lead to NPE

Modified:
    cxf/trunk/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/RMInInterceptor.java
    cxf/trunk/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/RMInInterceptorTest.java

Modified: cxf/trunk/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/RMInInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/RMInInterceptor.java?rev=1402084&r1=1402083&r2=1402084&view=diff
==============================================================================
--- cxf/trunk/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/RMInInterceptor.java (original)
+++ cxf/trunk/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/RMInInterceptor.java Thu Oct 25 10:29:56 2012
@@ -47,6 +47,9 @@ public class RMInInterceptor extends Abs
     @Override
     public void handleFault(Message message) {
         message.put(MAPAggregator.class.getName(), true);
+        if (null == RMContextUtils.getProtocolVariation(message)) {
+            return;
+        }
         if (MessageUtils.isTrue(message.get(RMMessageConstants.DELIVERING_ROBUST_ONEWAY))) {
             // revert the delivering entry from the destination sequence
             try {

Modified: cxf/trunk/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/RMInInterceptorTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/RMInInterceptorTest.java?rev=1402084&r1=1402083&r2=1402084&view=diff
==============================================================================
--- cxf/trunk/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/RMInInterceptorTest.java (original)
+++ cxf/trunk/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/RMInInterceptorTest.java Thu Oct 25 10:29:56 2012
@@ -282,7 +282,89 @@ public class RMInInterceptorTest extends
         control.replay(); 
         // TODO
     }
+
+    @Test
+    public void testProcessInvalidMessage() throws SequenceFault, RMException {
+        interceptor = new RMInInterceptor();
+        
+        Message message = control.createMock(Message.class);
+        Exchange exchange = control.createMock(Exchange.class);
+        org.apache.cxf.transport.Destination destination = 
+            control.createMock(org.apache.cxf.transport.Destination.class);
+        EasyMock.expect(message.getExchange()).andReturn(exchange).anyTimes();
+        EasyMock.expect(exchange.getDestination()).andReturn(destination).anyTimes();
+        EasyMock.expect(exchange.getOutMessage()).andReturn(null).anyTimes();
+        EasyMock.expect(exchange.getOutFaultMessage()).andReturn(null).anyTimes();
+        control.replay();
+
+        try {
+            interceptor.handle(message);
+            fail("must reject the invalid rm message");
+        } catch (Exception e) {
+            assertTrue(e instanceof RMException);
+            // verify a partial error text match to exclude an unexpected exception
+            // (see WSA_REQUIRED_EXC in Messages.properties)
+            final String text = "WS-Addressing is required";
+            assertTrue(e.getMessage() != null 
+                && e.getMessage().indexOf(text) >= 0);
+        }
+        
+        control.reset();
+        EasyMock.expect(message.getExchange()).andReturn(exchange).anyTimes();
+        AddressingPropertiesImpl maps = control.createMock(AddressingPropertiesImpl.class);
+        EasyMock.expect(maps.getNamespaceURI()).andReturn(Names200408.WSA_NAMESPACE_NAME).anyTimes();
+        EasyMock.expect(message.get(JAXWSAConstants.SERVER_ADDRESSING_PROPERTIES_INBOUND)).andReturn(maps);
+        AttributedURIType actionURI = control.createMock(AttributedURIType.class);
+        EasyMock.expect(maps.getAction()).andReturn(actionURI).times(2);
+        EasyMock.expect(actionURI.getValue()).andReturn("foo");
+        EasyMock.expect(message.get(RMMessageConstants.RM_PROPERTIES_INBOUND)).andReturn(rmps);
+        EasyMock.expect(exchange.getDestination()).andReturn(destination).anyTimes();
+        EasyMock.expect(exchange.getOutMessage()).andReturn(null).anyTimes();
+        EasyMock.expect(exchange.getOutFaultMessage()).andReturn(null).anyTimes();
+
+        control.replay();
+        
+        try {
+            interceptor.handle(message);
+            fail("must reject the invalid rm message");
+        } catch (Exception e) {
+            System.out.println(e);
+            assertTrue(e instanceof RMException);
+            // verify a partial error text match to exclude an unexpected exception
+            // (see WSRM_REQUIRED_EXC in Messages.properties)
+            final String text = "WS-ReliableMessaging is required";
+            assertTrue(e.getMessage() != null 
+                && e.getMessage().indexOf(text) >= 0);
+        }
+    }
     
+    @Test
+    public void testProcessInvalidMessageOnFault() throws SequenceFault, RMException {
+        interceptor = new RMInInterceptor();
+        
+        Message message = control.createMock(Message.class);
+        Exchange exchange = control.createMock(Exchange.class);
+        EasyMock.expect(message.getExchange()).andReturn(exchange).anyTimes();
+        control.replay();
+        
+        try {
+            interceptor.handleFault(message);
+        } catch (Exception e) {
+            fail("unexpected exception thrown from handleFault: " + e);
+        }
+        
+        control.reset();
+        EasyMock.expect(message.getExchange()).andReturn(exchange).anyTimes();
+        EasyMock.expect(message.get(RMMessageConstants.DELIVERING_ROBUST_ONEWAY)).andReturn(true).anyTimes();
+        control.replay();
+        
+        try {
+            interceptor.handleFault(message);
+        } catch (Exception e) {
+            fail("unexpected exception thrown from handleFault: " + e);
+        }
+    }
+
     private Message setupInboundMessage(String action, boolean serverSide) throws RMException {
         Message message = control.createMock(Message.class);
         Exchange exchange = control.createMock(Exchange.class);