cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ajaypai...@apache.org
Subject svn commit: r493047 - in /incubator/cxf/trunk: rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/interceptor/ systests/src/test/java/org/apache/cxf/systest/jaxws/ testutils/src/main/java/org/apache/headers/
Date Fri, 05 Jan 2007 15:20:57 GMT
Author: ajaypaibir
Date: Fri Jan  5 07:20:56 2007
New Revision: 493047

URL: http://svn.apache.org/viewvc?view=rev&rev=493047
Log:
Fix for bug CXF-293. Reading of xmlformatRootNode specifed for input or output message in
xml binding.Added systemtest for the use cases.

Modified:
    incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/interceptor/XMLMessageInInterceptor.java
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerXMLTest.java
    incubator/cxf/trunk/testutils/src/main/java/org/apache/headers/HeaderTesterImpl.java

Modified: incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/interceptor/XMLMessageInInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/interceptor/XMLMessageInInterceptor.java?view=diff&rev=493047&r1=493046&r2=493047
==============================================================================
--- incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/interceptor/XMLMessageInInterceptor.java
(original)
+++ incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/interceptor/XMLMessageInInterceptor.java
Fri Jan  5 07:20:56 2007
@@ -19,9 +19,7 @@
 
 package org.apache.cxf.binding.xml.interceptor;
 
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
+import java.util.Collection;
 import java.util.ResourceBundle;
 import java.util.logging.Logger;
 
@@ -43,10 +41,8 @@
 import org.apache.cxf.service.model.BindingInfo;
 import org.apache.cxf.service.model.BindingMessageInfo;
 import org.apache.cxf.service.model.BindingOperationInfo;
-import org.apache.cxf.service.model.MessageInfo;
 import org.apache.cxf.service.model.MessagePartInfo;
 import org.apache.cxf.service.model.OperationInfo;
-import org.apache.cxf.service.model.ServiceModelUtil;
 import org.apache.cxf.staxutils.DepthXMLStreamReader;
 import org.apache.cxf.staxutils.StaxUtils;
 
@@ -68,13 +64,10 @@
             LOG.info("XMLMessageInInterceptor skipped in HTTP GET method");
             return;
         }
-        XMLStreamReader xsr = message.getContent(XMLStreamReader.class);
-        
-        DepthXMLStreamReader reader = new DepthXMLStreamReader(xsr);
-        
         Endpoint ep = message.getExchange().get(Endpoint.class);
-        BindingInfo service = ep.getEndpointInfo().getBinding();
         
+        XMLStreamReader xsr = message.getContent(XMLStreamReader.class);        
+        DepthXMLStreamReader reader = new DepthXMLStreamReader(xsr);        
         if (!StaxUtils.toNextElement(reader)) {
             throw new Fault(new org.apache.cxf.common.i18n.Message("NO_OPERATION_ELEMENT",
BUNDLE));
         }
@@ -84,89 +77,87 @@
         // handling xml fault message
         if (startQName.getLocalPart().equals(XMLFault.XML_FAULT_ROOT)) {            
             message.getInterceptorChain().abort();
+            
             if (ep.getInFaultObserver() != null) {
                 ep.getInFaultObserver().onMessage(message);
                 return;
             }
         }
         // handling xml normal inbound message
-        BindingOperationInfo bop = ex.get(BindingOperationInfo.class);
-        MessagePartInfo part = null;
-        if (bop == null) {
-            part = getPartByRootNode(message, startQName, service, xsr);
-            if (part == null) {
-                List<OperationInfo> operations = new ArrayList<OperationInfo>();
-                operations.addAll(service.getInterface().getOperations());            
-                part = findMessagePart(ex, operations, startQName, false , 0);
+        BindingOperationInfo boi = ex.get(BindingOperationInfo.class);
+        boolean isRequestor = isRequestor(message);
+        if (boi == null) {
+            BindingInfo service = ep.getEndpointInfo().getBinding();
+            boi = getBindingOperationInfo(isRequestor, startQName, service, xsr);
+            if (boi != null) {
+                ex.put(BindingOperationInfo.class, boi);
+                ex.put(OperationInfo.class, boi.getOperationInfo());
+                ex.setOneWay(boi.getOperationInfo().isOneWay());
             }
         } else {
-            MessageInfo msgInfo = getMessageInfo(message, bop, ex);
-            if (msgInfo.getMessageParts().size() > 0) {
-                part = msgInfo.getMessageParts().get(0);
+            BindingMessageInfo bmi = isRequestor ? boi.getOutput()
+                                                 : boi.getInput();
+
+            if (hasRootNode(bmi, startQName)) { 
+                try {
+                    xsr.nextTag();
+                } catch (XMLStreamException xse) {
+                    throw new Fault(new org.apache.cxf.common.i18n.Message("STAX_READ_EXC",
BUNDLE));
+                }
             }
         }
 
-        if (part != null) {
-            OperationInfo o = part.getMessageInfo().getOperation();
-            // TODO: We already know the op, so we can optimize BareInInterceptor a bit yet
-            if (!o.isUnwrappedCapable()) {
+        if (boi != null) {
+            OperationInfo oi = boi.getOperationInfo();
+            if (!oi.isUnwrappedCapable()) {
                 bareInterceptor.handleMessage(message);
-                return;
             } else {
                 wrappedInterceptor.handleMessage(message);
-                return;
-            }
-        } else {
-            QName name = new QName(service.getInterface().getName().getNamespaceURI(), 
-                                   "multiParamRootReq");
-            if (reader.getName().equals(name)) {
-                StaxUtils.nextEvent(reader);
-                StaxUtils.toNextElement(reader);
-                bareInterceptor.handleMessage(message);
-                return;
-            } else {
-                // Do we have a bare request with no parts?
-                bop = ServiceModelUtil.getOperation(ex, reader.getName());
-                if (bop != null) {
-                    ex.put(BindingOperationInfo.class, bop);
-                    getMessageInfo(message, bop, ex);
-                    message.setContent(List.class, Collections.EMPTY_LIST);
-                    return;
-                }
             }
+        } else { 
+            throw new Fault(new org.apache.cxf.common.i18n.Message("REQ_NOT_UNDERSTOOD",

+                                                                   BUNDLE, 
+                                                                   startQName));
         }
-        
-        throw new Fault(new org.apache.cxf.common.i18n.Message("REQ_NOT_UNDERSTOOD", BUNDLE,
startQName));
     }
 
-    private MessagePartInfo getPartByRootNode(Message message, QName startQName, 
-            BindingInfo bi, XMLStreamReader xsr) {        
+    private BindingOperationInfo getBindingOperationInfo(boolean isRequestor, 
+                                                         QName startQName, 
+                                                         BindingInfo bi, 
+                                                         XMLStreamReader xsr) {
+
+        BindingOperationInfo match = null;
         for (BindingOperationInfo boi : bi.getOperations()) {
-            MessageInfo mi;
             BindingMessageInfo bmi;
-            if (!isRequestor(message)) {
-                mi = boi.getOperationInfo().getInput();
+            if (!isRequestor) {
                 bmi = boi.getInput();
             } else {
-                mi = boi.getOperationInfo().getOutput();
                 bmi = boi.getOutput();
             }
-            XMLBindingMessageFormat xmf = bmi.getExtensor(XMLBindingMessageFormat.class);
-            if (xmf != null && xmf.getRootNode().getLocalPart().equals(startQName.getLocalPart()))
{
-                message.getExchange().put(BindingOperationInfo.class, boi);
-                if (!boi.isUnwrappedCapable()) {
-                    try {
-                        xsr.nextTag();
-                    } catch (XMLStreamException xse) {
-                        throw new Fault(new org.apache.cxf.common.i18n.Message("STAX_READ_EXC",
BUNDLE));
-                    }
+            
+            if (hasRootNode(bmi, startQName)) {
+                match = boi;
+                //Consume The rootNode tag
+                try {
+                    xsr.nextTag();
+                } catch (XMLStreamException xse) {
+                    throw new Fault(new org.apache.cxf.common.i18n.Message("STAX_READ_EXC",
BUNDLE));
                 }
-                if (mi.getMessageParts().size() > 0) {
-                    return mi.getMessageParts().get(0);
+            } else {
+                Collection<MessagePartInfo> bodyParts = bmi.getMessageParts();
+                if (bodyParts.size() == 1) {
+                    MessagePartInfo p = bodyParts.iterator().next();
+                    if (p.getConcreteName().equals(startQName)) {
+                        match = boi;
+                    }
                 }
-                break;                
             }
         }
-        return null;
+        return match;
+    }
+
+    private boolean hasRootNode(BindingMessageInfo bmi, QName elName) {
+        XMLBindingMessageFormat xmf = bmi.getExtensor(XMLBindingMessageFormat.class);
+        return xmf != null && xmf.getRootNode().equals(elName);
     }
 }

Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerXMLTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerXMLTest.java?view=diff&rev=493047&r1=493046&r2=493047
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerXMLTest.java
(original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerXMLTest.java
Fri Jan  5 07:20:56 2007
@@ -27,6 +27,7 @@
 
 import javax.xml.namespace.QName;
 import javax.xml.ws.BindingProvider;
+import javax.xml.ws.Holder;
 import javax.xml.ws.Service;
 import javax.xml.xpath.XPathConstants;
 
@@ -44,6 +45,10 @@
 import org.apache.headers.XMLHeaderService;
 import org.apache.headers.types.InHeader;
 import org.apache.headers.types.InHeaderResponse;
+import org.apache.headers.types.InoutHeader;
+import org.apache.headers.types.InoutHeaderResponse;
+import org.apache.headers.types.OutHeader;
+import org.apache.headers.types.OutHeaderResponse;
 import org.apache.headers.types.SOAPHeaderData;
 import org.apache.hello_world_xml_http.bare.Greeter;
 import org.apache.hello_world_xml_http.bare.XMLService;
@@ -112,7 +117,7 @@
     }
 
     public void testBareGetGreetMe() throws Exception {
-        HttpURLConnection httpConnection = 
+        HttpURLConnection httpConnection =
             getHttpConnection("http://localhost:9031/XMLService/XMLPort/greetMe/requestType/cxf");
         httpConnection.connect();
 
@@ -136,7 +141,7 @@
 
     public void testWrapBasicConnection() throws Exception {
 
-        org.apache.hello_world_xml_http.wrapped.XMLService service = 
+        org.apache.hello_world_xml_http.wrapped.XMLService service =
             new org.apache.hello_world_xml_http.wrapped.XMLService(
                 this.getClass().getResource("/wsdl/hello_world_xml_wrapped.wsdl"), wrapServiceName);
         assertNotNull(service);
@@ -199,7 +204,7 @@
     }
 
     public void testXMLFault() throws Exception {
-        org.apache.hello_world_xml_http.wrapped.XMLService service = 
+        org.apache.hello_world_xml_http.wrapped.XMLService service =
             new org.apache.hello_world_xml_http.wrapped.XMLService(
                 this.getClass().getResource("/wsdl/hello_world_xml_wrapped.wsdl"), wrapServiceName);
         assertNotNull(service);
@@ -234,18 +239,70 @@
         XMLHeaderService service = new XMLHeaderService();
         HeaderTester port = service.getXMLPort9000();
         try {
-            InHeader me = new InHeader();
-            me.setRequestType("InHeaderRequest");
-            SOAPHeaderData headerInfo = new SOAPHeaderData();
-            headerInfo.setMessage("message");
-            headerInfo.setOriginator("originator");
-            InHeaderResponse resp = port.inHeader(me, headerInfo);
-            assertNotNull(resp);
-            assertEquals("check returned response type", "requestType=InHeaderRequest" 
-                    + "\nheaderData.message=message" + "\nheaderData.getOriginator=originator",

-                    resp.getResponseType());
+            verifyInHeader(port);
+            verifyInOutHeader(port);
+            verifyOutHeader(port);
         } catch (UndeclaredThrowableException ex) {
             throw (Exception) ex.getCause();
         }
     }
+
+    public void verifyInHeader(HeaderTester proxy) throws Exception {
+        InHeader me = new InHeader();
+        me.setRequestType("InHeaderRequest");
+        SOAPHeaderData headerInfo = new SOAPHeaderData();
+        headerInfo.setMessage("message");
+        headerInfo.setOriginator("originator");
+        InHeaderResponse resp = proxy.inHeader(me, headerInfo);
+        assertNotNull(resp);
+        assertEquals("check returned response type", "requestType=InHeaderRequest"
+                    + "\nheaderData.message=message" + "\nheaderData.getOriginator=originator",
+                    resp.getResponseType());
+    }
+
+    public void verifyInOutHeader(HeaderTester proxy) throws Exception {
+        InoutHeader me = new InoutHeader();
+        me.setRequestType("InoutHeaderRequest");
+        SOAPHeaderData headerInfo = new SOAPHeaderData();
+        headerInfo.setMessage("inoutMessage");
+        headerInfo.setOriginator("inoutOriginator");
+        Holder<SOAPHeaderData> holder = new Holder<SOAPHeaderData>();
+        holder.value = headerInfo;
+        InoutHeaderResponse resp = proxy.inoutHeader(me, holder);
+        assertNotNull(resp);
+        assertEquals("check return value",
+                     "requestType=InoutHeaderRequest",
+                     resp.getResponseType());
+        
+        assertEquals("check inout value",
+                     "message=inoutMessage",
+                     holder.value.getMessage());
+        assertEquals("check inout value",
+                     "orginator=inoutOriginator",
+                     holder.value.getOriginator());        
+    }
+
+    public void verifyOutHeader(HeaderTester proxy) throws Exception {
+        OutHeader me = new OutHeader();
+        me.setRequestType("OutHeaderRequest");
+        
+        Holder<OutHeaderResponse> outHeaderHolder = new Holder<OutHeaderResponse>();
+        Holder<SOAPHeaderData> soapHeaderHolder = new Holder<SOAPHeaderData>();
+        proxy.outHeader(me, outHeaderHolder, soapHeaderHolder);
+        assertNotNull(outHeaderHolder.value);
+        assertNotNull(soapHeaderHolder.value);
+        assertEquals("check out value",
+                     "requestType=OutHeaderRequest",
+                     outHeaderHolder.value.getResponseType());
+        
+        assertEquals("check out value",
+                     "message=outMessage",
+                     soapHeaderHolder.value.getMessage());
+
+        assertEquals("check out value",
+                     "orginator=outOriginator",
+                     soapHeaderHolder.value.getOriginator());
+        
+    }
+
 }

Modified: incubator/cxf/trunk/testutils/src/main/java/org/apache/headers/HeaderTesterImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/testutils/src/main/java/org/apache/headers/HeaderTesterImpl.java?view=diff&rev=493047&r1=493046&r2=493047
==============================================================================
--- incubator/cxf/trunk/testutils/src/main/java/org/apache/headers/HeaderTesterImpl.java (original)
+++ incubator/cxf/trunk/testutils/src/main/java/org/apache/headers/HeaderTesterImpl.java Fri
Jan  5 07:20:56 2007
@@ -58,13 +58,12 @@
 
     public void outHeader(OutHeader me, Holder<OutHeaderResponse> theResponse,
             Holder<SOAPHeaderData> headerInfo) {
-        if (theResponse.value != null) {
-            theResponse.value.setResponseType(me.getRequestType());
-        }
-        if (headerInfo.value != null) {
-            headerInfo.value.setMessage("message=" + headerInfo.value.getMessage());
-            headerInfo.value.setOriginator("orginator=" + headerInfo.value.getOriginator());
-        }
+        theResponse.value = new OutHeaderResponse();
+        theResponse.value.setResponseType("requestType=" + me.getRequestType());
+        
+        headerInfo.value = new SOAPHeaderData(); 
+        headerInfo.value.setMessage("message=outMessage");
+        headerInfo.value.setOriginator("orginator=outOriginator");
     }
 
 }



Mime
View raw message