You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by gn...@apache.org on 2006/09/26 13:16:12 UTC

svn commit: r449980 - in /incubator/servicemix/branches/servicemix-3.0/servicemix-jsr181/src: main/java/org/apache/servicemix/jsr181/Jsr181ExchangeProcessor.java test/java/org/apache/servicemix/jsr181/Jsr181MTOMTest.java

Author: gnodet
Date: Tue Sep 26 04:16:12 2006
New Revision: 449980

URL: http://svn.apache.org/viewvc?view=rev&rev=449980
Log:
SM-598: MTOM attachments are not output by the jsr181 component

Modified:
    incubator/servicemix/branches/servicemix-3.0/servicemix-jsr181/src/main/java/org/apache/servicemix/jsr181/Jsr181ExchangeProcessor.java
    incubator/servicemix/branches/servicemix-3.0/servicemix-jsr181/src/test/java/org/apache/servicemix/jsr181/Jsr181MTOMTest.java

Modified: incubator/servicemix/branches/servicemix-3.0/servicemix-jsr181/src/main/java/org/apache/servicemix/jsr181/Jsr181ExchangeProcessor.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/branches/servicemix-3.0/servicemix-jsr181/src/main/java/org/apache/servicemix/jsr181/Jsr181ExchangeProcessor.java?view=diff&rev=449980&r1=449979&r2=449980
==============================================================================
--- incubator/servicemix/branches/servicemix-3.0/servicemix-jsr181/src/main/java/org/apache/servicemix/jsr181/Jsr181ExchangeProcessor.java (original)
+++ incubator/servicemix/branches/servicemix-3.0/servicemix-jsr181/src/main/java/org/apache/servicemix/jsr181/Jsr181ExchangeProcessor.java Tue Sep 26 04:16:12 2006
@@ -39,6 +39,8 @@
 import org.apache.servicemix.jsr181.xfire.JbiTransport;
 import org.codehaus.xfire.MessageContext;
 import org.codehaus.xfire.XFire;
+import org.codehaus.xfire.attachments.Attachment;
+import org.codehaus.xfire.attachments.Attachments;
 import org.codehaus.xfire.attachments.JavaMailAttachments;
 import org.codehaus.xfire.attachments.SimpleAttachment;
 import org.codehaus.xfire.exchange.InMessage;
@@ -119,6 +121,13 @@
                 exchange.setFault(fault);
             } else {
                 NormalizedMessage outMsg = exchange.createMessage();
+                Attachments attachments = ctx.getCurrentMessage().getAttachments();
+                if (attachments != null) {
+                    for (Iterator it = attachments.getParts(); it.hasNext();) {
+                        Attachment att = (Attachment) it.next();
+                        outMsg.addAttachment(att.getId(), att.getDataHandler());
+                    }
+                }
                 outMsg.setContent(new StringSource(out.toString()));
                 exchange.setMessage(outMsg, "out");
             }

Modified: incubator/servicemix/branches/servicemix-3.0/servicemix-jsr181/src/test/java/org/apache/servicemix/jsr181/Jsr181MTOMTest.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/branches/servicemix-3.0/servicemix-jsr181/src/test/java/org/apache/servicemix/jsr181/Jsr181MTOMTest.java?view=diff&rev=449980&r1=449979&r2=449980
==============================================================================
--- incubator/servicemix/branches/servicemix-3.0/servicemix-jsr181/src/test/java/org/apache/servicemix/jsr181/Jsr181MTOMTest.java (original)
+++ incubator/servicemix/branches/servicemix-3.0/servicemix-jsr181/src/test/java/org/apache/servicemix/jsr181/Jsr181MTOMTest.java Tue Sep 26 04:16:12 2006
@@ -16,6 +16,8 @@
  */
 package org.apache.servicemix.jsr181;
 
+import java.io.ByteArrayOutputStream;
+
 import javax.activation.DataHandler;
 import javax.jbi.messaging.InOut;
 import javax.jbi.servicedesc.ServiceEndpoint;
@@ -30,6 +32,7 @@
 import org.apache.servicemix.jbi.jaxp.SourceTransformer;
 import org.apache.servicemix.jbi.jaxp.StringSource;
 import org.apache.servicemix.jbi.util.ByteArrayDataSource;
+import org.apache.servicemix.jbi.util.FileUtil;
 import org.w3c.dom.Document;
 
 public class Jsr181MTOMTest extends TestCase {
@@ -72,29 +75,25 @@
         Destination dest = client.createDestination("service:http://jsr181.servicemix.apache.org/EchoWithAttachment");
         InOut me = dest.createInOutExchange();
         me.getInMessage().setContent(new StringSource("<echo xmlns:xop='http://www.w3.org/2004/08/xop/include'><msg>hello world</msg><binary><xop:Include href='binary'/></binary></echo>"));
-        me.getInMessage().addAttachment("binary", new DataHandler(new ByteArrayDataSource(new byte[] { 0, 1 , 2}, "image/jpg")));
-        
+        me.getInMessage().addAttachment("binary", new DataHandler(new ByteArrayDataSource(new byte[] { 0, 1, 2}, "image/jpg")));
         client.sendSync(me);
-        
+        assertNotNull(me.getOutMessage());
+        assertEquals(1, me.getOutMessage().getAttachmentNames().size());
+        DataHandler dh = me.getOutMessage().getAttachment((String) me.getOutMessage().getAttachmentNames().iterator().next());
+        assertNotNull(dh);
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        FileUtil.copyInputStream(dh.getInputStream(), baos);
+        assertEquals(3, baos.toByteArray().length);
+        client.done(me);
     }
     
     public static class EchoWithAttachment {
         
-        /*
-         * Do not use byte[] until xfire-1.2
-        public String echo(String msg, byte[] binary) {
+        public byte[] echo(String msg, byte[] binary) {
             if (binary == null || binary.length == 0) {
                 throw new NullPointerException("binary is null");
             }
-            return "Echo: " + msg;
-        }
-        */
-        
-        public String echo(String msg, DataHandler binary) {
-            if (binary == null || binary.getDataSource() == null) {
-                throw new NullPointerException("binary is null");
-            }
-            return "Echo: " + msg;
+            return binary;
         }
     }