cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a.@apache.org
Subject svn commit: r1444251 - in /cxf/trunk: api/src/main/java/org/apache/cxf/interceptor/ rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/ systests/jaxws/src/test/java/org/apache/cxf/systest/provider/
Date Fri, 08 Feb 2013 21:52:55 GMT
Author: ay
Date: Fri Feb  8 21:52:55 2013
New Revision: 1444251

URL: http://svn.apache.org/r1444251
Log:
[CXF-4812] NPE on MessageModeInInterceptor when sending empty SOAPBody

Added:
    cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/NBProviderClientServerTest.java
    cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/NBSoapMessageDocProvider.java
Modified:
    cxf/trunk/api/src/main/java/org/apache/cxf/interceptor/DocLiteralInInterceptor.java
    cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/MessageModeInInterceptor.java

Modified: cxf/trunk/api/src/main/java/org/apache/cxf/interceptor/DocLiteralInInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/interceptor/DocLiteralInInterceptor.java?rev=1444251&r1=1444250&r2=1444251&view=diff
==============================================================================
--- cxf/trunk/api/src/main/java/org/apache/cxf/interceptor/DocLiteralInInterceptor.java (original)
+++ cxf/trunk/api/src/main/java/org/apache/cxf/interceptor/DocLiteralInInterceptor.java Fri
Feb  8 21:52:55 2013
@@ -30,6 +30,7 @@ import javax.xml.stream.XMLStreamConstan
 import javax.xml.stream.XMLStreamReader;
 
 import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.common.util.XMLSchemaQNames;
 import org.apache.cxf.databinding.DataReader;
 import org.apache.cxf.endpoint.Endpoint;
 import org.apache.cxf.message.Exchange;
@@ -148,17 +149,7 @@ public class DocLiteralInInterceptor ext
     
                 if (xmlReader == null || !StaxUtils.toNextElement(xmlReader)) {
                     // empty input
-    
-                    // TO DO : check duplicate operation with no input
-                    for (OperationInfo op : operations) {
-                        MessageInfo bmsg = op.getInput();
-                        if (bmsg.getMessageParts().size() == 0) {
-                            BindingOperationInfo boi = ep.getEndpointInfo().getBinding().getOperation(op);
-                            exchange.put(BindingOperationInfo.class, boi);
-                            exchange.put(OperationInfo.class, op);
-                            exchange.setOneWay(op.isOneWay());
-                        }
-                    }
+                    getBindingOperationForEmptyBody(operations, ep, exchange);
                     return;
                 }
 
@@ -220,6 +211,22 @@ public class DocLiteralInInterceptor ext
         }
     }
 
+    private void getBindingOperationForEmptyBody(Collection<OperationInfo> operations,
Endpoint ep, Exchange exchange) {
+        // TO DO : check duplicate operation with no input and also check if the action matches

+        for (OperationInfo op : operations) {
+            MessageInfo bmsg = op.getInput();
+            List<MessagePartInfo> bparts = bmsg.getMessageParts();
+            if (bparts.size() == 0
+                || (bparts.size() == 1 
+                    && XMLSchemaQNames.XSD_ANY.equals(bparts.get(0).getTypeQName())))
{
+                BindingOperationInfo boi = ep.getEndpointInfo().getBinding().getOperation(op);
+                exchange.put(BindingOperationInfo.class, boi);
+                exchange.put(OperationInfo.class, op);
+                exchange.setOneWay(op.isOneWay());
+            }
+        }
+    }
+
     private BindingOperationInfo getBindingOperationInfo(DepthXMLStreamReader xmlReader,
Exchange exchange,
                                                          BindingOperationInfo bop, boolean
client) {
         //bop might be a unwrapped, wrap it back so that we can get correct info 

Modified: cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/MessageModeInInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/MessageModeInInterceptor.java?rev=1444251&r1=1444250&r2=1444251&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/MessageModeInInterceptor.java
(original)
+++ cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/MessageModeInInterceptor.java
Fri Feb  8 21:52:55 2013
@@ -68,8 +68,8 @@ public class MessageModeInInterceptor ex
     }
 
     public void handleMessage(Message message) throws Fault {
-        if (!bindingName.equals(message.getExchange().get(BindingOperationInfo.class)
-                               .getBinding().getName())) {
+        BindingOperationInfo bop = message.getExchange().get(BindingOperationInfo.class);

+        if (bop == null || !bindingName.equals(bop.getBinding().getName())) {
             return;
         }
         Object o = message.getContent(soapMsgClass);

Added: cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/NBProviderClientServerTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/NBProviderClientServerTest.java?rev=1444251&view=auto
==============================================================================
--- cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/NBProviderClientServerTest.java
(added)
+++ cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/NBProviderClientServerTest.java
Fri Feb  8 21:52:55 2013
@@ -0,0 +1,138 @@
+/**
+ * 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.systest.provider;
+
+import java.lang.reflect.UndeclaredThrowableException;
+
+import javax.xml.namespace.QName;
+import javax.xml.soap.MessageFactory;
+import javax.xml.soap.SOAPEnvelope;
+import javax.xml.soap.SOAPException;
+import javax.xml.soap.SOAPMessage;
+import javax.xml.ws.Dispatch;
+import javax.xml.ws.Endpoint;
+import javax.xml.ws.Service;
+import javax.xml.ws.soap.SOAPBinding;
+
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
+import org.apache.cxf.testutil.common.AbstractBusTestServerBase;
+import org.apache.cxf.testutil.common.TestUtil;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class NBProviderClientServerTest extends AbstractBusClientServerTestBase {
+    public static final String ADDRESS 
+        = "http://localhost:" + TestUtil.getPortNumber(Server.class)
+            + "/SoapContext/SoapProviderPort";
+
+    private static QName sayHi = new QName("http://apache.org/hello_world_soap_http/types",
"sayHi");
+
+    public static class Server extends AbstractBusTestServerBase {
+        Endpoint ep;
+        
+        protected void run() {
+            Object implementor = new NBSoapMessageDocProvider();
+            ep = Endpoint.publish(ADDRESS, implementor);                                

+        }
+
+        @Override
+        public void tearDown() {
+            ep.stop();
+        }
+
+        public static void main(String[] args) {
+            try {
+                Server s = new Server();
+                s.start();
+            } catch (Exception ex) {
+                ex.printStackTrace();
+                System.exit(-1);
+            } finally {
+                System.out.println("done!");
+            }
+        }
+    }
+
+    @BeforeClass
+    public static void startServers() throws Exception {
+        assertTrue("server did not launch correctly", launchServer(Server.class, true));
+    }
+    
+    @Test
+    public void testSOAPMessageModeDocLit() throws Exception {
+        QName serviceName = 
+            new QName("http://apache.org/hello_world_soap_http", "SOAPProviderService");
+        QName portName = 
+            new QName("http://apache.org/hello_world_soap_http", "SoapProviderPort");
+
+        Service service = Service.create(serviceName);
+        assertNotNull(service);
+        service.addPort(portName, SOAPBinding.SOAP11HTTP_BINDING, ADDRESS);
+
+        try {
+            Dispatch<SOAPMessage> dispatch = service.createDispatch(portName, SOAPMessage.class,
Service.Mode.MESSAGE);
+            
+            MessageFactory factory = MessageFactory.newInstance();
+            SOAPMessage request = encodeRequest(factory, "sayHi");
+            SOAPMessage response;
+            try {
+                response = dispatch.invoke(request);
+                fail("Should have thrown an exception");
+            } catch (Exception ex) {
+                //expected 
+                assertEquals("no body expected", ex.getMessage());
+            }
+            
+            request = encodeRequest(factory, null);
+            response = dispatch.invoke(request);
+            String resp = decodeResponse(response);
+            assertEquals("Bonjour", resp);
+            
+        } catch (UndeclaredThrowableException ex) {
+            throw (Exception)ex.getCause();
+        }
+        
+    }
+
+    private SOAPMessage encodeRequest(MessageFactory factory, String value) throws SOAPException
{
+        SOAPMessage request = factory.createMessage();
+        SOAPEnvelope envelope = request.getSOAPPart().getEnvelope();
+        request.setProperty("soapaction", "");
+        if (value != null) {
+            request.getSOAPBody().addBodyElement(envelope.createName(value, "ns1", sayHi.getNamespaceURI()));
+        }
+        
+        return request;
+    }
+
+    private String decodeResponse(SOAPMessage response) throws SOAPException {
+        NodeList nodelist = response.getSOAPBody().getElementsByTagNameNS(sayHi.getNamespaceURI(),
"responseType");
+        if (nodelist.getLength() == 1) {
+            Node node = nodelist.item(0).getFirstChild();
+            if (node != null) {
+                return node.getNodeValue();
+            }
+        }
+        return null;
+    }
+}

Added: cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/NBSoapMessageDocProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/NBSoapMessageDocProvider.java?rev=1444251&view=auto
==============================================================================
--- cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/NBSoapMessageDocProvider.java
(added)
+++ cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/NBSoapMessageDocProvider.java
Fri Feb  8 21:52:55 2013
@@ -0,0 +1,65 @@
+/**
+ * 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.systest.provider;
+
+import java.io.InputStream;
+
+import javax.xml.soap.MessageFactory;
+import javax.xml.soap.SOAPBody;
+import javax.xml.soap.SOAPException;
+import javax.xml.soap.SOAPMessage;
+import javax.xml.ws.Provider;
+import javax.xml.ws.Service;
+import javax.xml.ws.ServiceMode;
+import javax.xml.ws.WebServiceProvider;
+
+import org.apache.cxf.binding.soap.saaj.SAAJUtils;
+
+@WebServiceProvider(portName = "SoapProviderPort", serviceName = "SOAPProviderService",
+                    targetNamespace = "http://apache.org/hello_world_soap_http")
+@ServiceMode(value = Service.Mode.MESSAGE)            
+public class NBSoapMessageDocProvider implements Provider<SOAPMessage> {
+    private SOAPMessage sayHiResponse;
+    
+    public NBSoapMessageDocProvider() {
+       
+        try {
+            MessageFactory factory = MessageFactory.newInstance();            
+            InputStream is = getClass().getResourceAsStream("resources/sayHiDocLiteralResp.xml");
+            sayHiResponse =  factory.createMessage(null, is);
+            is.close();
+        } catch (Exception ex) {
+            ex.printStackTrace();
+        }
+    }
+    
+    public SOAPMessage invoke(SOAPMessage request) {
+        SOAPBody body = null;
+        try {
+            body = SAAJUtils.getBody(request);
+        } catch (SOAPException e) {
+            throw new RuntimeException("soap body expected");
+        }
+        if (body.getFirstChild() != null) {
+            throw new RuntimeException("no body expected");
+        }
+        return sayHiResponse;
+    }
+}



Mime
View raw message