cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t..@apache.org
Subject svn commit: r448944 - in /incubator/cxf/trunk: api/src/main/java/org/apache/cxf/io/ rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/ rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/ rt/bindings/soap/src/test/java/org/a...
Date Fri, 22 Sep 2006 14:14:11 GMT
Author: tli
Date: Fri Sep 22 07:14:10 2006
New Revision: 448944

URL: http://svn.apache.org/viewvc?view=rev&rev=448944
Log:
CXF-74 add XML Binding Support, remove assumption of AbstractCachedOutputStream in AttachmentOutInterceptor,
change the test source from jpg to bmp in AttachmentTest because JDK Image has bug when handling
jpg with thumbnail

Added:
    incubator/cxf/trunk/rt/bindings/soap/src/test/resources/org/apache/cxf/binding/soap/attachments/me.bmp
  (with props)
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/ClientServerMtomXopTest.java
  (with props)
Removed:
    incubator/cxf/trunk/rt/bindings/soap/src/test/resources/org/apache/cxf/binding/soap/attachments/me.jpg
Modified:
    incubator/cxf/trunk/api/src/main/java/org/apache/cxf/io/AbstractCachedOutputStream.java
    incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/AttachmentOutInterceptor.java
    incubator/cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/TestUtil.java
    incubator/cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/attachments/AttachmentTest.java
    incubator/cxf/trunk/rt/bindings/soap/src/test/resources/org/apache/cxf/binding/soap/attachments/primarySoapPart.xml
    incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/attachment/AttachmentDeserializer.java
    incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/attachment/AttachmentSerializer.java
    incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/attachment/JAXBAttachmentMarshaller.java
    incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/MessageDataReader.java
    incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/MessageDataWriter.java
    incubator/cxf/trunk/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/io/XMLMessageDataReaderTest.java

Modified: incubator/cxf/trunk/api/src/main/java/org/apache/cxf/io/AbstractCachedOutputStream.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/api/src/main/java/org/apache/cxf/io/AbstractCachedOutputStream.java?view=diff&rev=448944&r1=448943&r2=448944
==============================================================================
--- incubator/cxf/trunk/api/src/main/java/org/apache/cxf/io/AbstractCachedOutputStream.java
(original)
+++ incubator/cxf/trunk/api/src/main/java/org/apache/cxf/io/AbstractCachedOutputStream.java
Fri Sep 22 07:14:10 2006
@@ -29,14 +29,17 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.io.OutputStreamWriter;
 import java.io.PipedInputStream;
 import java.io.PipedOutputStream;
 
+import org.apache.cxf.common.util.Base64Utility;
+
 public abstract class AbstractCachedOutputStream extends OutputStream {
 
     protected OutputStream currentStream;
 
-    private long threshold = 8 * 1024;
+    private long threshold = 64 * 1024;
 
     private int totalLength;
 
@@ -80,46 +83,53 @@
     public boolean equals(Object obj) {
         return currentStream.equals(obj);
     }
-    
+
     /**
      * Replace the original stream with the new one, when with Attachment, needs
      * to replace the xml writer stream with the stream used by
      * AttachmentSerializer Or Copy the cached output stream to the "real"
      * output stream, i.e. onto the wire.
      * 
-     * @param realOS the real output stream
+     * @param realOS
+     *            the real output stream
      * @throws IOException
      */
-    public void resetOut(OutputStream out, boolean copyOldContent) throws IOException {
-        ByteArrayOutputStream byteOut = null;
+    public void resetOut(OutputStream out, boolean copyOldContent) throws IOException { 
      
         if (currentStream instanceof AbstractCachedOutputStream) {
             AbstractCachedOutputStream ac = (AbstractCachedOutputStream) currentStream;
             InputStream in = ac.getInputStream();
-            copyStream(in, out);
+            copyStream(in, out, (int) threshold);
         } else {
             if (inmem) {
-                byteOut = (ByteArrayOutputStream) currentStream;
-                if (copyOldContent && byteOut.size() > 0) {
-                    byteOut.writeTo(out);
+                if (currentStream instanceof ByteArrayOutputStream) {
+                    ByteArrayOutputStream byteOut = (ByteArrayOutputStream) currentStream;
+                    if (copyOldContent && byteOut.size() > 0) {
+                        byteOut.writeTo(out);
+                    }
+                } else if (currentStream instanceof PipedOutputStream) {
+                    PipedOutputStream pipeOut = (PipedOutputStream) currentStream;
+                    copyStream(new PipedInputStream(pipeOut), out, (int) threshold);
+                } else {
+                    throw new IOException("Unknown format of currentStream");
                 }
             } else {
                 // read the file
                 currentStream.close();
                 FileInputStream fin = new FileInputStream(tempFile);
                 if (copyOldContent) {
-                    copyStream(fin, out);
+                    copyStream(fin, out, (int) threshold);
                 }
             }
         }
         currentStream = out;
     }
 
-    private void copyStream(InputStream in, OutputStream out) throws IOException {
-        byte[] buffer = new byte[4096];
+    public static void copyStream(InputStream in, OutputStream out, int bufferSize) throws
IOException {
+        byte[] buffer = new byte[bufferSize];
         int len = 0;
         int pos = 0;
         while (true) {
-            len = in.read(buffer, 0, 4096);
+            len = in.read(buffer, 0, bufferSize);
             if (len != -1) {
                 out.write(buffer, 0, len);
                 pos += len;
@@ -129,6 +139,23 @@
         }
     }
 
+    public static void copyStreamWithBase64Encoding(InputStream in, OutputStream out, 
+                    int bufferSize) throws Exception {
+        OutputStreamWriter osw = new OutputStreamWriter(out);
+        byte[] buffer = new byte[bufferSize];
+        int len = 0;
+        int pos = 0;
+        while (true) {
+            len = in.read(buffer, 0, bufferSize);
+            if (len != -1) {
+                Base64Utility.encode(buffer, pos, len, osw);
+                pos += len;
+            } else {
+                break;
+            }
+        }
+    }
+
     /**
      * @return the underlying output stream
      */
@@ -149,7 +176,7 @@
     public void write(byte[] b, int off, int len) throws IOException {
         onWrite();
         this.totalLength += len;
-        if (inmem && totalLength > threshold) {
+        if (inmem && totalLength > threshold && currentStream instanceof
ByteArrayOutputStream) {
             createFileOutputStream();
         }
         currentStream.write(b, off, len);
@@ -158,7 +185,7 @@
     public void write(byte[] b) throws IOException {
         onWrite();
         this.totalLength += b.length;
-        if (inmem && totalLength > threshold) {
+        if (inmem && totalLength > threshold && currentStream instanceof
ByteArrayOutputStream) {
             createFileOutputStream();
         }
         currentStream.write(b);
@@ -167,14 +194,14 @@
     public void write(int b) throws IOException {
         onWrite();
         this.totalLength++;
-        if (inmem && totalLength > threshold) {
+        if (inmem && totalLength > threshold && currentStream instanceof
ByteArrayOutputStream) {
             createFileOutputStream();
         }
         currentStream.write(b);
     }
 
     private void createFileOutputStream() throws IOException {
-        byte[] bytes = ((ByteArrayOutputStream)currentStream).toByteArray();
+        byte[] bytes = ((ByteArrayOutputStream) currentStream).toByteArray();
         if (outputDir == null) {
             tempFile = File.createTempFile("att", "tmp");
         } else {
@@ -192,9 +219,9 @@
     public InputStream getInputStream() throws IOException {
         if (inmem) {
             if (currentStream instanceof ByteArrayOutputStream) {
-                return new ByteArrayInputStream(((ByteArrayOutputStream)currentStream).toByteArray());
+                return new ByteArrayInputStream(((ByteArrayOutputStream) currentStream).toByteArray());
             } else if (currentStream instanceof PipedOutputStream) {
-                return new PipedInputStream((PipedOutputStream)currentStream);
+                return new PipedInputStream((PipedOutputStream) currentStream);
             } else {
                 return null;
             }

Modified: incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/AttachmentOutInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/AttachmentOutInterceptor.java?view=diff&rev=448944&r1=448943&r2=448944
==============================================================================
--- incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/AttachmentOutInterceptor.java
(original)
+++ incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/AttachmentOutInterceptor.java
Fri Sep 22 07:14:10 2006
@@ -24,7 +24,6 @@
 import java.util.Collection;
 import java.util.ResourceBundle;
 
-import org.apache.cxf.binding.attachment.CachedOutputStream;
 import org.apache.cxf.binding.soap.SoapFault;
 import org.apache.cxf.binding.soap.SoapMessage;
 import org.apache.cxf.common.i18n.BundleUtils;
@@ -35,7 +34,6 @@
 import org.apache.cxf.message.Attachment;
 import org.apache.cxf.phase.Phase;
 
-
 public class AttachmentOutInterceptor extends AbstractSoapInterceptor {
 
     private static final ResourceBundle BUNDLE = BundleUtils.getBundle(SoapOutInterceptor.class);
@@ -46,28 +44,41 @@
     }
 
     public void handleMessage(SoapMessage message) throws Fault {
-        // Calling for soap out interceptor        
-        message.getInterceptorChain().doIntercept(message);
-        OutputStream os = message.getContent(OutputStream.class);
         
-        if (!(os instanceof AbstractCachedOutputStream)) {
-            return;
-        }
+        OutputStream os = message.getContent(OutputStream.class);
+        CachedStream cs = new CachedStream();
+        message.setContent(OutputStream.class, cs);
         
-        AbstractCachedOutputStream ops = (AbstractCachedOutputStream) os;
+        // Calling for soap out interceptor
+        message.getInterceptorChain().doIntercept(message);
+        // Set back the output stream
+        message.setContent(OutputStream.class, os);        
         try {
-            ops.getOut().flush();
             Collection<Attachment> attachments = message.getAttachments();
+            cs.flush();
             if (attachments.size() > 0) {
-                CachedOutputStream cos = new CachedOutputStream();
-                AttachmentSerializer as = new AttachmentSerializer(message, ops.getInputStream(),
cos);
+                AttachmentSerializer as = new AttachmentSerializer(message, cs.getInputStream(),
os);
                 as.serializeMultipartMessage();
-                ops.resetOut(cos, false);
-            }           
-            ops.flush();       
+            } else {
+                // get wire connection, and copy xml infoset directly into it
+                os.flush();
+                AbstractCachedOutputStream.copyStream(cs.getInputStream(), os, 64 * 1024);
               
+            }
         } catch (IOException ioe) {
             throw new SoapFault(new Message("ATTACHMENT_IO", BUNDLE, ioe.toString()), 
-                                SoapFault.ATTACHMENT_IO);
+                            SoapFault.ATTACHMENT_IO);
+        }
+    }
+
+    private class CachedStream extends AbstractCachedOutputStream {
+        protected void doFlush() throws IOException {
+            currentStream.flush();
+        }
+
+        protected void doClose() throws IOException {
+        }
+
+        protected void onWrite() throws IOException {
         }
     }
 }

Modified: incubator/cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/TestUtil.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/TestUtil.java?view=diff&rev=448944&r1=448943&r2=448944
==============================================================================
--- incubator/cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/TestUtil.java
(original)
+++ incubator/cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/TestUtil.java
Fri Sep 22 07:14:10 2006
@@ -51,7 +51,7 @@
         detailObj.setSName("hello world");        
                 
         URL url1 = clazz.getResource("my.wav");
-        URL url2 = clazz.getResource("me.jpg");
+        URL url2 = clazz.getResource("me.bmp");
         Image image = ImageIO.read(new File(url2.getFile()));
         detailObj.setPhoto(image);
         File file = new File(url1.getFile());
@@ -76,8 +76,8 @@
 
         // setup the message attachments
         Collection<Attachment> attachments = soapMessage.getAttachments();
-        String cidAtt1 = "cid:http://cxf.apache.org/me.jpg";
-        bads = new ByteArrayDataSource(clazz.getResourceAsStream("me.jpg"), "image/jpg");
+        String cidAtt1 = "cid:http://cxf.apache.org/me.bmp";
+        bads = new ByteArrayDataSource(clazz.getResourceAsStream("me.bmp"), "image/bmp");
         AttachmentImpl att1 = new AttachmentImpl(cidAtt1, new DataHandler(bads));
         att1.setXOP(true);
         attachments.add(att1);

Modified: incubator/cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/attachments/AttachmentTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/attachments/AttachmentTest.java?view=diff&rev=448944&r1=448943&r2=448944
==============================================================================
--- incubator/cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/attachments/AttachmentTest.java
(original)
+++ incubator/cxf/trunk/rt/bindings/soap/src/test/java/org/apache/cxf/binding/soap/attachments/AttachmentTest.java
Fri Sep 22 07:14:10 2006
@@ -19,14 +19,17 @@
 
 package org.apache.cxf.binding.soap.attachments;
 
+import java.awt.Image;
 import java.io.IOException;
 import java.io.InputStream;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.StringTokenizer;
 
 import javax.mail.MessagingException;
 import javax.xml.bind.JAXBContext;
@@ -104,7 +107,7 @@
 
             JAXBAttachmentUnmarshaller jau = new JAXBAttachmentUnmarshaller(soapMessage);
             u.setAttachmentUnmarshaller(jau);
-
+            System.out.println(jau.isXOPPackage());
             XMLStreamReader r = (XMLStreamReader) soapMessage.getContent(XMLStreamReader.class);
             while (r.hasNext()) {
                 r.nextTag();
@@ -136,8 +139,8 @@
         assertTrue(obj instanceof DetailType);
         DetailType detailType = (DetailType) obj;
         assertTrue(detailType.getSName().equals("hello world"));
-        // needs futhur investigation
-        // assertTrue(detailType.getPhoto() instanceof Image);
+        //needs futhur investigation
+        assertTrue(detailType.getPhoto() instanceof Image);
         assertTrue(detailType.getSound().length > 0);
     }
 
@@ -200,7 +203,12 @@
 
             Map<String, List<String>> mimeHttpHeaders = new HashMap<String,
List<String>>();
             soapMessage.put(Message.PROTOCOL_HEADERS, mimeHttpHeaders);
-            mimeHttpHeaders.put("Content-Type", Arrays.asList(contentType));
+            StringTokenizer stk = new StringTokenizer(contentType, ";");
+            List<String> headers = new ArrayList<String>(); 
+            while (stk.hasMoreTokens()) {
+                headers.add(stk.nextToken().trim());
+            }
+            mimeHttpHeaders.put("Content-Type", headers);
             mimeHttpHeaders.put("Content-Description", Arrays.asList("XML document Multi-Media
attachment"));
 
             soapMessage.getInterceptorChain().doIntercept(soapMessage);

Added: incubator/cxf/trunk/rt/bindings/soap/src/test/resources/org/apache/cxf/binding/soap/attachments/me.bmp
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/soap/src/test/resources/org/apache/cxf/binding/soap/attachments/me.bmp?view=auto&rev=448944
==============================================================================
Binary file - no diff available.

Propchange: incubator/cxf/trunk/rt/bindings/soap/src/test/resources/org/apache/cxf/binding/soap/attachments/me.bmp
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Modified: incubator/cxf/trunk/rt/bindings/soap/src/test/resources/org/apache/cxf/binding/soap/attachments/primarySoapPart.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/soap/src/test/resources/org/apache/cxf/binding/soap/attachments/primarySoapPart.xml?view=diff&rev=448944&r1=448943&r2=448944
==============================================================================
--- incubator/cxf/trunk/rt/bindings/soap/src/test/resources/org/apache/cxf/binding/soap/attachments/primarySoapPart.xml
(original)
+++ incubator/cxf/trunk/rt/bindings/soap/src/test/resources/org/apache/cxf/binding/soap/attachments/primarySoapPart.xml
Fri Sep 22 07:14:10 2006
@@ -22,9 +22,9 @@
 	<soap:Body>
 		<Detail xmlns:m='http://example.org/stuff'>
 			<sName>hello world</sName>
-			<photo xmlmime:contentType='image/png'>
+			<photo xmlmime:contentType='image/bmp'>
 				<xop:Include xmlns:xop='http://www.w3.org/2004/08/xop/include'
-					href='cid:http://cxf.apache.org/me.jpg'/>
+					href='cid:http://cxf.apache.org/me.bmp'/>
 			</photo>
 			<sound xmlmime:contentType='audio/x-wav'>
 				<xop:Include xmlns:xop='http://www.w3.org/2004/08/xop/include'

Modified: incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/attachment/AttachmentDeserializer.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/attachment/AttachmentDeserializer.java?view=diff&rev=448944&r1=448943&r2=448944
==============================================================================
--- incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/attachment/AttachmentDeserializer.java
(original)
+++ incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/attachment/AttachmentDeserializer.java
Fri Sep 22 07:14:10 2006
@@ -68,7 +68,7 @@
         Map httpHeaders;
         // processing message if its multi-part/form-related
         try {
-            httpHeaders = (Map)message.get(Message.PROTOCOL_HEADERS);
+            httpHeaders = (Map) message.get(Message.PROTOCOL_HEADERS);
             if (httpHeaders == null) {
                 return false;
             } else {
@@ -87,6 +87,7 @@
                     return false;
                 }
             }
+            //printStream(input);
             if (contentType.toLowerCase().indexOf("multipart/related") != -1) {
                 int i = contentType.indexOf("boundary=\"");
                 int end;
@@ -143,8 +144,7 @@
     public void processSoapBody() throws MessagingException, IOException {
 
         Attachment soapMimePart = readMimePart();
-        message.setContent(Attachment.class, soapMimePart);
-
+        message.setContent(Attachment.class, soapMimePart);        
         InputStream in = soapMimePart.getDataHandler().getInputStream();
         message.setContent(InputStream.class, in);
     }
@@ -237,11 +237,12 @@
         AttachmentImpl att = new AttachmentImpl(id, dh);
         for (Enumeration<?> e = headers.getAllHeaders(); e.hasMoreElements();) {
             Header header = (Header) e.nextElement();
+            if (header.getName().equalsIgnoreCase("Content-Transfer-Encoding")
+                            && header.getValue().equalsIgnoreCase("binary")) {
+                att.setXOP(true);
+            }
             att.setHeader(header.getName(), header.getValue());
         }
-        if (ct.indexOf("xop+xml") > 0) {
-            att.setXOP(true);
-        }
         return att;
     }
 
@@ -330,10 +331,10 @@
         }
     }
 
-//    private static void printStream(InputStream in) throws IOException {
-//        for (int i = in.read(); i != -1; i = in.read()) {
-//            System.out.write(i);
-//        }
-//        System.out.println("print stream");
-//    }
+    protected static void printStream(InputStream in) throws IOException {
+        for (int i = in.read(); i != -1; i = in.read()) {
+            System.out.write(i);
+        }
+        System.out.println("print stream");
+    }
 }

Modified: incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/attachment/AttachmentSerializer.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/attachment/AttachmentSerializer.java?view=diff&rev=448944&r1=448943&r2=448944
==============================================================================
--- incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/attachment/AttachmentSerializer.java
(original)
+++ incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/attachment/AttachmentSerializer.java
Fri Sep 22 07:14:10 2006
@@ -19,27 +19,25 @@
 
 package org.apache.cxf.jaxb.attachment;
 
-import java.io.IOException;
 import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.LineNumberReader;
 import java.io.ObjectOutputStream;
 import java.io.OutputStream;
-import java.io.PrintWriter;
 import java.io.UnsupportedEncodingException;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
 import org.apache.cxf.binding.attachment.AttachmentUtil;
-import org.apache.cxf.common.util.Base64Exception;
-import org.apache.cxf.common.util.Base64Utility;
+import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.interceptor.Fault;
+import org.apache.cxf.io.AbstractCachedOutputStream;
 import org.apache.cxf.message.Attachment;
 import org.apache.cxf.message.Message;
 
 public class AttachmentSerializer {
 
+    private static final String LINE_SEP = System.getProperty("line.separator");
+    
     private Message message;
 
     private InputStream in;
@@ -72,9 +70,8 @@
             throw new Fault(e);
         }
         try {
-            PrintWriter pw = new PrintWriter(out);
-            Map<String, List<String>> headers = (Map<String, List<String>>)
message
-                            .get(Message.PROTOCOL_HEADERS);
+            Map<String, List<String>> headers = CastUtils.cast((Map<?, ?>)
message
+                            .get(Message.PROTOCOL_HEADERS));
             if (headers == null) {
                 // this is the case of server out (response)
                 headers = new HashMap<String, List<String>>();
@@ -82,53 +79,50 @@
             }
             AttachmentUtil.setMimeRequestHeader(headers, message, soapPartId,
                             "soap message with attachments", boundary);
-
+            //finish prepare header, call flush to flush headers and resetOut to get wire
stream
+            out.flush();
+            
             String soapHeader = AttachmentUtil.getSoapPartHeader(message, soapPartId, "");
-            pw.println("--" + boundary);
-            pw.println(soapHeader);
-            LineNumberReader lnr = new LineNumberReader(new InputStreamReader(in));
-            for (String s = lnr.readLine(); s != null; s = lnr.readLine()) {
-                pw.println(s);
-            }
-            pw.println();
+            out.write(("--" + boundary + LINE_SEP).getBytes());
+            out.write(soapHeader.getBytes());            
+            out.write(LINE_SEP.getBytes());            
+            AbstractCachedOutputStream.copyStream(in, out, 64 * 1024);
+            if (!System.getProperty("file.separator").equals("/")) {
+                out.write(LINE_SEP.getBytes());
+            }            
             for (Attachment att : message.getAttachments()) {
                 soapHeader = AttachmentUtil.getAttchmentPartHeader(att);
-                pw.println("--" + boundary);
-                pw.println(soapHeader);
+                out.write(("--" + boundary + LINE_SEP).getBytes());
+                out.write(soapHeader.getBytes());                
+                out.write(LINE_SEP.getBytes());                
                 Object content = att.getDataHandler().getContent();
                 if (content instanceof InputStream) {
-                    InputStream ins = (InputStream) content;
+                    InputStream insAtt = (InputStream) content;
                     if (!att.isXOP()) {
-                        byte[] buffer = new byte[4096];
-                        int pos = 0;
-                        for (int len = ins.read(buffer); len != -1; len = ins.read(buffer))
{
-                            Base64Utility.encode(buffer, pos, len, pw);
-                            pos = pos + len;
-                        }
+                        AbstractCachedOutputStream.copyStreamWithBase64Encoding(insAtt, out,
64 * 1024);
                     } else {
-                        for (int i = ins.read(); i != -1; i = ins.read()) {
-                            pw.write(i);
-                        }
+                        AbstractCachedOutputStream.copyStream(insAtt, out, 64 * 1024);
                     }
-                } else {
-                    pw.flush();
+                } else {                    
                     ObjectOutputStream oos = new ObjectOutputStream(out);
                     oos.writeObject(content);
                 }
-                pw.println();
+                if (!System.getProperty("file.separator").equals("/")) {
+                    out.write(LINE_SEP.getBytes());
+                }
             }
-            pw.println("--" + boundary);
-            pw.flush();
+            out.write(("--" + boundary).getBytes());
+            out.write(LINE_SEP.getBytes());
+            out.flush();            
+            // build contentType string for return
             List<String> contentType = (List<String>) headers.get("Content-Type");
             StringBuffer sb = new StringBuffer(120);
             for (String s : contentType) {
                 sb.append(s);
             }
             return sb.toString();
-        } catch (IOException ioe) {
-            throw new Fault(ioe);
-        } catch (Base64Exception be) {
-            throw new Fault(be);
+        } catch (Exception e) {
+            throw new Fault(e);
         }
 
     }

Modified: incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/attachment/JAXBAttachmentMarshaller.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/attachment/JAXBAttachmentMarshaller.java?view=diff&rev=448944&r1=448943&r2=448944
==============================================================================
--- incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/attachment/JAXBAttachmentMarshaller.java
(original)
+++ incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/attachment/JAXBAttachmentMarshaller.java
Fri Sep 22 07:14:10 2006
@@ -37,7 +37,7 @@
 
     private Message message;
     private Collection<Attachment> atts;
-    private boolean isXop = true;
+    private boolean isXop;
 
     public JAXBAttachmentMarshaller(Message messageParam) {
         super();
@@ -57,7 +57,8 @@
         } catch (UnsupportedEncodingException e) {
             throw new Fault(e);
         }
-        Attachment att = new AttachmentImpl(id, handler);
+        AttachmentImpl att = new AttachmentImpl(id, handler);
+        att.setXOP(this.isXop);
         atts.add(att);
 
         return "cid:" + id;
@@ -72,7 +73,7 @@
             throw new Fault(e);
         }
         AttachmentImpl att = new AttachmentImpl(id, handler);
-        att.setXOP(true);
+        att.setXOP(this.isXop);
         atts.add(att);
 
         return "cid:" + id;
@@ -82,7 +83,7 @@
     public String addSwaRefAttachment(DataHandler handler) {
         String id = UUID.randomUUID() + "@apache.org";
         AttachmentImpl att = new AttachmentImpl(id, handler);
-        att.setXOP(true);
+        att.setXOP(this.isXop);
         atts.add(att);
         return id;
     }

Modified: incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/MessageDataReader.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/MessageDataReader.java?view=diff&rev=448944&r1=448943&r2=448944
==============================================================================
--- incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/MessageDataReader.java
(original)
+++ incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/MessageDataReader.java
Fri Sep 22 07:14:10 2006
@@ -51,7 +51,7 @@
     public Object read(QName name, Message input, Class cls) {
         JAXBAttachmentUnmarshaller au = null;        
         if (input.get(AttachmentDeserializer.class) != null) {
-            au = new JAXBAttachmentUnmarshaller(input); 
+            au = new JAXBAttachmentUnmarshaller(input);            
         }
         Object source = null;
         XMLStreamReader xsr = (XMLStreamReader)input.getContent(XMLStreamReader.class);

Modified: incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/MessageDataWriter.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/MessageDataWriter.java?view=diff&rev=448944&r1=448943&r2=448944
==============================================================================
--- incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/MessageDataWriter.java
(original)
+++ incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/MessageDataWriter.java
Fri Sep 22 07:14:10 2006
@@ -49,6 +49,7 @@
         JAXBAttachmentMarshaller am = null;
         // if (output.containsKey(Message.MTOM_ENABLED)) {
         am = new JAXBAttachmentMarshaller(output);
+        am.setXOPPackage(true);
         // }
         Object source = null;
         XMLStreamWriter xsw = (XMLStreamWriter) output.getContent(XMLStreamWriter.class);

Modified: incubator/cxf/trunk/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/io/XMLMessageDataReaderTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/io/XMLMessageDataReaderTest.java?view=diff&rev=448944&r1=448943&r2=448944
==============================================================================
--- incubator/cxf/trunk/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/io/XMLMessageDataReaderTest.java
(original)
+++ incubator/cxf/trunk/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/io/XMLMessageDataReaderTest.java
Fri Sep 22 07:14:10 2006
@@ -54,7 +54,6 @@
 
         Object source = reader.read(null, xmlMsg, DOMSource.class);
         assertNotNull(source);
-        System.out.println(XMLUtils.toString((Source)source));
         assertTrue(XMLUtils.toString((Source)source).contains(expected));
     }
 

Added: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/ClientServerMtomXopTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/ClientServerMtomXopTest.java?view=auto&rev=448944
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/ClientServerMtomXopTest.java
(added)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/ClientServerMtomXopTest.java
Fri Sep 22 07:14:10 2006
@@ -0,0 +1,91 @@
+/**
+ * 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.mtom;
+
+import java.io.InputStream;
+import java.lang.reflect.UndeclaredThrowableException;
+
+import javax.activation.DataHandler;
+import javax.activation.DataSource;
+import javax.mail.util.ByteArrayDataSource;
+import javax.xml.ws.Endpoint;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.cxf.mime.Hello;
+import org.apache.cxf.mime.HelloService;
+import org.apache.cxf.mtom_xop.HelloImpl;
+import org.apache.cxf.systest.common.ClientServerSetupBase;
+import org.apache.cxf.systest.common.ClientServerTestBase;
+import org.apache.cxf.systest.common.TestServerBase;
+
+public class ClientServerMtomXopTest extends ClientServerTestBase {
+
+    public static class Server extends TestServerBase {
+
+        protected void run() {
+            Object implementor = new HelloImpl();
+            String address = "http://localhost:9036/mime-test";
+            Endpoint.publish(address, implementor);
+        }
+
+        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!");
+            }
+        }
+    }
+
+    public static Test suite() throws Exception {
+        TestSuite suite = new TestSuite(ClientServerMtomXopTest.class);
+        return new ClientServerSetupBase(suite) {
+            public void startServers() throws Exception {
+                assertTrue("server did not launch correctly", launchServer(Server.class));
+            }
+        };
+    }
+
+    public void testMtomBasic() throws Exception {
+        HelloService hs = new HelloService();
+        Hello hello = hs.getPort(Hello.class);
+        try {
+            ByteArrayDataSource bads = new ByteArrayDataSource(this.getClass().getResourceAsStream(
+                            "/wsdl/mtom_xop.wsdl"), "application/oct-stream");
+            DataHandler dh = new DataHandler(bads);
+            DataHandler dhResp = hello.claimForm(dh);
+            DataSource ds = dhResp.getDataSource();
+            InputStream in = ds.getInputStream();
+            long count = 0;
+            for (int i = in.read(); i != -1; i = in.read()) {
+                count++;
+            }
+            assertEquals("attachemnt length different", 5531, count);
+        } catch (UndeclaredThrowableException ex) {
+            throw (Exception) ex.getCause();
+        }
+    }
+
+}

Propchange: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/ClientServerMtomXopTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message