cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r532173 - in /incubator/cxf/trunk: rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/LogicalMessageImpl.java systests/src/test/java/org/apache/cxf/systest/handlers/SmallNumberHandler.java
Date Wed, 25 Apr 2007 02:29:22 GMT
Author: dkulp
Date: Tue Apr 24 19:29:21 2007
New Revision: 532173

URL: http://svn.apache.org/viewvc?view=rev&rev=532173
Log:
Implement a couple of the LogicalMessage methods

Modified:
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/LogicalMessageImpl.java
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/SmallNumberHandler.java

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/LogicalMessageImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/LogicalMessageImpl.java?view=diff&rev=532173&r1=532172&r2=532173
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/LogicalMessageImpl.java
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/LogicalMessageImpl.java
Tue Apr 24 19:29:21 2007
@@ -24,10 +24,21 @@
 import java.util.List;
 
 import javax.xml.bind.JAXBContext;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
 import javax.xml.transform.Source;
+import javax.xml.transform.dom.DOMSource;
 import javax.xml.ws.LogicalMessage;
+import javax.xml.ws.WebServiceException;
+import javax.xml.ws.soap.SOAPFaultException;
 
+
+import org.apache.cxf.interceptor.BareInInterceptor;
+import org.apache.cxf.interceptor.BareOutInterceptor;
 import org.apache.cxf.message.Message;
+import org.apache.cxf.staxutils.StaxUtils;
+import org.apache.cxf.staxutils.W3CDOMStreamWriter;
 
 
 public class LogicalMessageImpl implements LogicalMessage {
@@ -39,21 +50,58 @@
     }
 
     public Source getPayload() {
-        return msgContext.getWrappedMessage().getContent(Source.class);
+        Source source = msgContext.getWrappedMessage().getContent(Source.class);
+        if (source == null) {
+            //need to convert
+            Exception ex = msgContext.getWrappedMessage().getContent(Exception.class);
+            if (ex instanceof SOAPFaultException) {
+                List<Object> list = new ArrayList<Object>();
+                list.add(((SOAPFaultException)ex).getFault());
+                msgContext.getWrappedMessage().setContent(List.class, list);
+            }
+            
+            W3CDOMStreamWriter writer;
+            try {
+                writer = new W3CDOMStreamWriter();
+            } catch (ParserConfigurationException e) {
+                throw new WebServiceException(e);
+            }
+            XMLStreamWriter orig = msgContext.getWrappedMessage().getContent(XMLStreamWriter.class);
+            try {
+                msgContext.getWrappedMessage().setContent(XMLStreamWriter.class, writer);
+                BareOutInterceptor bi = new BareOutInterceptor();
+                bi.handleMessage(msgContext.getWrappedMessage());
+            } finally {
+                msgContext.getWrappedMessage().setContent(XMLStreamWriter.class, orig); 
+            }
+            
+            source = new DOMSource(writer.getDocument().getDocumentElement());
+            msgContext.getWrappedMessage().setContent(Source.class, source);
+        }
+        return source;
     }
 
     public void setPayload(Source s) {
-        msgContext.getWrappedMessage().setContent(Source.class, s);
+        msgContext.getWrappedMessage().setContent(Source.class, null);
+        XMLStreamReader orig = msgContext.getWrappedMessage().getContent(XMLStreamReader.class);
+        try {
+            XMLStreamReader reader = StaxUtils.createXMLStreamReader(s);
+            msgContext.getWrappedMessage().setContent(XMLStreamReader.class, reader);
+            BareInInterceptor bin = new BareInInterceptor();
+            bin.handleMessage(msgContext.getWrappedMessage());
+        } finally {
+            msgContext.getWrappedMessage().setContent(XMLStreamReader.class, orig);
+        }
     }
 
     public Object getPayload(JAXBContext arg0) {
-        // TODO - what to do with JAXB context?
         Message msg = msgContext.getWrappedMessage();
         if (msg.getContent(List.class) != null) {
             return msg.getContent(List.class).get(0);
         } else if (msg.getContent(Object.class) != null) {
             return msg.getContent(Object.class);
         }
+        // TODO - what to do with JAXB context?
         return null;
     }
 

Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/SmallNumberHandler.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/SmallNumberHandler.java?view=diff&rev=532173&r1=532172&r2=532173
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/SmallNumberHandler.java
(original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/SmallNumberHandler.java
Tue Apr 24 19:29:21 2007
@@ -24,8 +24,10 @@
 import javax.annotation.Resource;
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.JAXBException;
+import javax.xml.transform.Source;
 import javax.xml.ws.LogicalMessage;
 import javax.xml.ws.ProtocolException;
+import javax.xml.ws.WebServiceException;
 import javax.xml.ws.handler.LogicalHandler;
 import javax.xml.ws.handler.LogicalMessageContext;
 import javax.xml.ws.handler.MessageContext;
@@ -87,6 +89,13 @@
                         AddNumbersResponse resp = new AddNumbersResponse();
                         resp.setReturn(answer);
                         msg.setPayload(resp, jaxbContext);
+                        
+                        Source src = msg.getPayload();
+                        msg.setPayload(src);
+                        AddNumbersResponse resp2 = (AddNumbersResponse)msg.getPayload(jaxbContext);
+                        if (resp2 == resp) {
+                            throw new WebServiceException("Shouldn't be the same object");
+                        }
 
                         // finally, return false, indicating that request
                         // processing stops here and our answer will be



Mime
View raw message