Author: ay
Date: Fri Feb 17 14:31:34 2012
New Revision: 1245572

URL: http://svn.apache.org/viewvc?rev=1245572&view=rev
Log:
[CXF-4023] invalid ProtocolVariant causes NullPointerException in 
RMSoapInterceptor

Added:
    
cxf/trunk/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/ProtocolVariationTest.java
   (with props)
Modified:
    
cxf/trunk/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/soap/RMSoapInterceptor.java
    
cxf/trunk/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/rm/ProtocolVariationsTest.java

Modified: 
cxf/trunk/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/soap/RMSoapInterceptor.java
URL: 
http://svn.apache.org/viewvc/cxf/trunk/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/soap/RMSoapInterceptor.java?rev=1245572&r1=1245571&r2=1245572&view=diff
==============================================================================
--- 
cxf/trunk/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/soap/RMSoapInterceptor.java
 (original)
+++ 
cxf/trunk/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/soap/RMSoapInterceptor.java
 Fri Feb 17 14:31:34 2012
@@ -282,11 +282,11 @@ public class RMSoapInterceptor extends A
                                 wsauri = maps.getNamespaceURI();
                             }
                             ProtocolVariation protocol = 
ProtocolVariation.findVariant(rmUri, wsauri);
-                            codec = protocol.getCodec();
-                            if (codec == null) {
+                            if (protocol == null) {
                                 LOG.log(Level.WARNING, "NAMESPACE_ERROR_MSG", 
wsauri); 
                                 break;
                             }
+                            codec = protocol.getCodec();
                         }
                         String localName = elem.getLocalName();
                         LOG.log(Level.FINE, "decoding RM header {0}", 
localName);

Added: 
cxf/trunk/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/ProtocolVariationTest.java
URL: 
http://svn.apache.org/viewvc/cxf/trunk/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/ProtocolVariationTest.java?rev=1245572&view=auto
==============================================================================
--- 
cxf/trunk/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/ProtocolVariationTest.java
 (added)
+++ 
cxf/trunk/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/ProtocolVariationTest.java
 Fri Feb 17 14:31:34 2012
@@ -0,0 +1,48 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.ws.rm;
+
+import junit.framework.Assert;
+
+import org.apache.cxf.ws.addressing.Names;
+import org.apache.cxf.ws.addressing.VersionTransformer.Names200408;
+
+import org.junit.Test;
+
+/**
+ * 
+ */
+public class ProtocolVariationTest extends Assert {
+
+    @Test
+    public void testFindVariant() {
+        // valid combinations
+        assertNotNull(ProtocolVariation.findVariant(
+                          RM10Constants.NAMESPACE_URI, 
Names200408.WSA_NAMESPACE_NAME));
+        assertNotNull(ProtocolVariation.findVariant(
+                          RM10Constants.NAMESPACE_URI, 
Names.WSA_NAMESPACE_NAME));
+        assertNotNull(ProtocolVariation.findVariant(
+                          RM11Constants.NAMESPACE_URI, 
Names.WSA_NAMESPACE_NAME));
+        
+        // invalid combinations 
+        assertNull(ProtocolVariation.findVariant(
+                          RM11Constants.NAMESPACE_URI, 
Names200408.WSA_NAMESPACE_NAME));
+    }
+}

Propchange: 
cxf/trunk/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/ProtocolVariationTest.java
------------------------------------------------------------------------------
    svn:executable = *

Modified: 
cxf/trunk/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/rm/ProtocolVariationsTest.java
URL: 
http://svn.apache.org/viewvc/cxf/trunk/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/rm/ProtocolVariationsTest.java?rev=1245572&r1=1245571&r2=1245572&view=diff
==============================================================================
--- 
cxf/trunk/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/rm/ProtocolVariationsTest.java
 (original)
+++ 
cxf/trunk/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/rm/ProtocolVariationsTest.java
 Fri Feb 17 14:31:34 2012
@@ -50,6 +50,7 @@ import org.apache.cxf.ws.addressing.Vers
 import org.apache.cxf.ws.rm.RM10Constants;
 import org.apache.cxf.ws.rm.RM11Constants;
 import org.apache.cxf.ws.rm.RMConstants;
+import org.apache.cxf.ws.rm.RMException;
 import org.apache.cxf.ws.rm.RMManager;
 
 import org.junit.After;
@@ -162,6 +163,29 @@ public class ProtocolVariationsTest exte
     }
     
     @Test
+    public void testInvalidRM11WSA200408() throws Exception {
+        init("org/apache/cxf/systest/ws/rm/rminterceptors.xml", false);
+        
+        // WS-RM 1.1, but using the WS-A 1.0 namespace
+        Client client = ClientProxy.getClient(greeter);
+        client.getRequestContext().put(RMManager.WSRM_VERSION_PROPERTY, 
RM11Constants.NAMESPACE_URI);
+        client.getRequestContext().put(RMManager.WSRM_WSA_VERSION_PROPERTY, 
Names200408.WSA_NAMESPACE_NAME);
+
+        try {
+            greeter.greetMe("one");
+            fail("invalid namespace combination");
+        } catch (Exception e) {
+            assertTrue(e.getCause() instanceof RMException);
+            // verify a partial error text match to exclude an unexpected 
exception
+            // (see UNSUPPORTED_NAMESPACE in Messages.properties)
+            final String text = Names200408.WSA_NAMESPACE_NAME + " is not 
supported";
+            assertTrue(e.getCause().getMessage() != null 
+                       && e.getCause().getMessage().indexOf(text) > 0);
+        }
+        
+    }
+    
+    @Test
     public void testDefaultDecoupled() throws Exception {
         init("org/apache/cxf/systest/ws/rm/rminterceptors.xml", true);
 


Reply via email to