cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ff...@apache.org
Subject svn commit: r551788 - in /incubator/cxf/trunk: rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/ systests/src/test/java/org/apache/cxf/systest/provider/datasource/ systests/src/test/resources/
Date Fri, 29 Jun 2007 03:53:40 GMT
Author: ffang
Date: Thu Jun 28 20:53:39 2007
New Revision: 551788

URL: http://svn.apache.org/viewvc?view=rev&rev=551788
Log:
[CXF-752] apply patch provided by Conrad

Modified:
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/ProviderOutDatabindingInterceptor.java
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/datasource/DataSourceProviderTest.java
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/datasource/TestProvider.java
    incubator/cxf/trunk/systests/src/test/resources/attachmentBinaryData

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/ProviderOutDatabindingInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/ProviderOutDatabindingInterceptor.java?view=diff&rev=551788&r1=551787&r2=551788
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/ProviderOutDatabindingInterceptor.java
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/ProviderOutDatabindingInterceptor.java
Thu Jun 28 20:53:39 2007
@@ -18,12 +18,16 @@
  */
 package org.apache.cxf.jaxws.interceptors;
 
+import java.io.IOException;
+import java.io.OutputStream;
 import java.util.List;
 
+import javax.activation.DataSource;
 import javax.xml.soap.SOAPMessage;
 import javax.xml.stream.XMLStreamWriter;
 
 import org.apache.cxf.databinding.DataWriter;
+import org.apache.cxf.helpers.IOUtils;
 import org.apache.cxf.interceptor.AbstractInDatabindingInterceptor;
 import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.message.Message;
@@ -52,6 +56,14 @@
             if (o != null) {
                 if (o instanceof SOAPMessage) {
                     message.setContent(SOAPMessage.class, o);
+                } else if (o instanceof DataSource) { 
+                    try { 
+                        message.removeContent(XMLStreamWriter.class);
+                        OutputStream out = message.getContent(OutputStream.class); 
+                        IOUtils.copy(((DataSource)o).getInputStream(), out);
+                    } catch (IOException ex) { 
+                        throw new Fault(ex);
+                    } 
                 } else {
                     writer.write(o, xsw);
                 }
@@ -59,4 +71,4 @@
         }
     }
 
-}
\ No newline at end of file
+}

Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/datasource/DataSourceProviderTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/datasource/DataSourceProviderTest.java?view=diff&rev=551788&r1=551787&r2=551788
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/datasource/DataSourceProviderTest.java
(original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/datasource/DataSourceProviderTest.java
Thu Jun 28 20:53:39 2007
@@ -20,6 +20,7 @@
 package org.apache.cxf.systest.provider.datasource;
 
 import java.io.ByteArrayOutputStream;
+import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.net.HttpURLConnection;
@@ -27,6 +28,10 @@
 import java.util.Properties;
 import java.util.logging.Logger;
 
+import javax.mail.MessagingException;
+import javax.mail.Session;
+import javax.mail.internet.MimeMessage;
+import javax.mail.internet.MimeMultipart;
 import javax.xml.transform.OutputKeys;
 import javax.xml.transform.Source;
 import javax.xml.transform.Transformer;
@@ -34,11 +39,7 @@
 import javax.xml.transform.stream.StreamResult;
 import javax.xml.transform.stream.StreamSource;
 
-import org.w3c.dom.Document;
-import org.w3c.dom.Node;
-
 import org.apache.cxf.helpers.IOUtils;
-import org.apache.cxf.helpers.XMLUtils;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
@@ -88,10 +89,11 @@
         IOUtils.copy(in, out);
         out.close();
 
-        Document d = (Document)XMLUtils.fromSource(new StreamSource(conn.getInputStream()));
-        Node n = d.getFirstChild();
-        assertEquals("bodyParts", n.getNodeName());
-        assertEquals("incorrect number of parts received by server", 2, Integer.parseInt(n.getTextContent()));
+        MimeMultipart mm = readAttachmentParts(conn.getRequestProperty("Content-Type"),
+                                                        conn.getInputStream());
+
+        assertEquals("incorrect number of parts received by server", 3, mm.getCount());
+
     }
 
     private void printSource(Source source) {
@@ -110,6 +112,13 @@
         }
     }
     
-    
+    public static MimeMultipart readAttachmentParts(String contentType, InputStream bais)
throws 
+        MessagingException, IOException {
+        Session session = Session.getDefaultInstance(new Properties());
+        MimeMessage mm = new MimeMessage(session, bais);
+        mm.addHeaderLine("Content-Type:" + contentType);
+        return (MimeMultipart) mm.getContent();
+    }
+
 
 }

Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/datasource/TestProvider.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/datasource/TestProvider.java?view=diff&rev=551788&r1=551787&r2=551788
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/datasource/TestProvider.java
(original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/datasource/TestProvider.java
Thu Jun 28 20:53:39 2007
@@ -20,15 +20,12 @@
 package org.apache.cxf.systest.provider.datasource;
 
 
-/*import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;*/
-import java.util.Properties;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
 import java.util.logging.Logger;
 
 import javax.activation.DataSource;
-import javax.mail.Session;
-import javax.mail.internet.MimeMessage;
 import javax.mail.internet.MimeMultipart;
 import javax.mail.util.ByteArrayDataSource;
 import javax.xml.ws.BindingType;
@@ -38,7 +35,8 @@
 import javax.xml.ws.WebServiceContext;
 import javax.xml.ws.WebServiceProvider;
 
-//import org.apache.cxf.helpers.IOUtils;
+import org.apache.cxf.helpers.IOUtils;
+
 
 
 
@@ -64,14 +62,15 @@
         try {
             LOG.info("content type: " + req.getContentType());
 
-            Session session = Session.getDefaultInstance(new Properties());
-            MimeMessage mm = new MimeMessage(session, req.getInputStream());
-                        
-            mm.addHeaderLine("Content-Type:" + req.getContentType());
-            MimeMultipart multipart = (MimeMultipart) mm.getContent();
-            msg = "<bodyParts>" + multipart.getCount() + "</bodyParts>";
-            
-            
+            ByteArrayOutputStream baos = new ByteArrayOutputStream();
+            IOUtils.copy(req.getInputStream(), baos);
+            LOG.info("body [" + new String(baos.toByteArray())  + "]");
+            ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+            msg = "<ok/>";
+
+            MimeMultipart multipart = DataSourceProviderTest.readAttachmentParts(req.getContentType(),
bais);
+            LOG.info("found " + multipart.getCount() + " parts");
+            return new ByteArrayDataSource(baos.toByteArray(), req.getContentType());
         } catch (Exception e) {
             e.printStackTrace();
             msg = "<fail/>";
@@ -85,4 +84,6 @@
         String msg = "<doc><response>Hello</response></doc>";
         return new ByteArrayDataSource(msg.getBytes(), "application/octet-stream");
     }
+    
+    
 }

Modified: incubator/cxf/trunk/systests/src/test/resources/attachmentBinaryData
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/resources/attachmentBinaryData?view=diff&rev=551788&r1=551787&r2=551788
==============================================================================
--- incubator/cxf/trunk/systests/src/test/resources/attachmentBinaryData (original)
+++ incubator/cxf/trunk/systests/src/test/resources/attachmentBinaryData Thu Jun 28 20:53:39
2007
@@ -17,3 +17,8 @@
 dWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRo
 ZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4=
 
+------=_Part_4_701508.1145579811786
+Content-Type: text/plain
+Content-ID: <hello>
+
+Hello Attachment
\ No newline at end of file



Mime
View raw message