servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r428124 - in /incubator/servicemix/trunk/servicemix-jsr181: ./ src/main/java/org/apache/servicemix/jsr181/ src/test/java/org/apache/servicemix/jsr181/
Date Wed, 02 Aug 2006 20:06:38 GMT
Author: gnodet
Date: Wed Aug  2 13:06:38 2006
New Revision: 428124

URL: http://svn.apache.org/viewvc?rev=428124&view=rev
Log:
SM-509: add mtom / attachments support 

Added:
    incubator/servicemix/trunk/servicemix-jsr181/src/test/java/org/apache/servicemix/jsr181/Jsr181MTOMTest.java
Modified:
    incubator/servicemix/trunk/servicemix-jsr181/pom.xml
    incubator/servicemix/trunk/servicemix-jsr181/src/main/java/org/apache/servicemix/jsr181/Jsr181Endpoint.java
    incubator/servicemix/trunk/servicemix-jsr181/src/main/java/org/apache/servicemix/jsr181/Jsr181ExchangeProcessor.java

Modified: incubator/servicemix/trunk/servicemix-jsr181/pom.xml
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-jsr181/pom.xml?rev=428124&r1=428123&r2=428124&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-jsr181/pom.xml (original)
+++ incubator/servicemix/trunk/servicemix-jsr181/pom.xml Wed Aug  2 13:06:38 2006
@@ -85,6 +85,11 @@
       <artifactId>commons-logging</artifactId>
       <scope>provided</scope>
     </dependency>
+    <dependency>
+      <groupId>org.apache.geronimo.specs</groupId>
+      <artifactId>geronimo-javamail_1.3.1_spec</artifactId>
+      <scope>provided</scope>
+    </dependency>
   </dependencies>
 
   <build>

Modified: incubator/servicemix/trunk/servicemix-jsr181/src/main/java/org/apache/servicemix/jsr181/Jsr181Endpoint.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-jsr181/src/main/java/org/apache/servicemix/jsr181/Jsr181Endpoint.java?rev=428124&r1=428123&r2=428124&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-jsr181/src/main/java/org/apache/servicemix/jsr181/Jsr181Endpoint.java
(original)
+++ incubator/servicemix/trunk/servicemix-jsr181/src/main/java/org/apache/servicemix/jsr181/Jsr181Endpoint.java
Wed Aug  2 13:06:38 2006
@@ -74,6 +74,7 @@
     protected Service xfireService;
     protected ExchangeProcessor processor;
     protected Resource wsdlResource;
+    protected boolean mtomEnabled = false;
     
     public Jsr181Endpoint() {
         processor = new Jsr181ExchangeProcessor(this);
@@ -108,6 +109,20 @@
     }
 
     /**
+     * @return the mtomEnabled
+     */
+    public boolean isMtomEnabled() {
+        return mtomEnabled;
+    }
+
+    /**
+     * @param mtomEnabled the mtomEnabled to set
+     */
+    public void setMtomEnabled(boolean mtomEnabled) {
+        this.mtomEnabled = mtomEnabled;
+    }
+
+    /**
      * @return Returns the xfireService.
      */
     public Service getXFireService() {
@@ -221,6 +236,7 @@
         xfireService = factory.create(serviceClass, svcLocalName, svcNamespace, props);
         xfireService.setInvoker(new BeanInvoker(getPojo()));
         xfireService.setFaultSerializer(new JbiFaultSerializer(getConfiguration()));
+        xfireService.setProperty(SoapConstants.MTOM_ENABLED, Boolean.toString(mtomEnabled));
         xfire.getServiceRegistry().register(xfireService);
         
         // If the wsdl has not been provided,

Modified: incubator/servicemix/trunk/servicemix-jsr181/src/main/java/org/apache/servicemix/jsr181/Jsr181ExchangeProcessor.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-jsr181/src/main/java/org/apache/servicemix/jsr181/Jsr181ExchangeProcessor.java?rev=428124&r1=428123&r2=428124&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-jsr181/src/main/java/org/apache/servicemix/jsr181/Jsr181ExchangeProcessor.java
(original)
+++ incubator/servicemix/trunk/servicemix-jsr181/src/main/java/org/apache/servicemix/jsr181/Jsr181ExchangeProcessor.java
Wed Aug  2 13:06:38 2006
@@ -18,7 +18,9 @@
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
+import java.util.Iterator;
 
+import javax.activation.DataHandler;
 import javax.jbi.messaging.DeliveryChannel;
 import javax.jbi.messaging.ExchangeStatus;
 import javax.jbi.messaging.Fault;
@@ -39,6 +41,8 @@
 import org.apache.servicemix.jsr181.xfire.JbiTransport;
 import org.codehaus.xfire.MessageContext;
 import org.codehaus.xfire.XFire;
+import org.codehaus.xfire.attachments.JavaMailAttachments;
+import org.codehaus.xfire.attachments.SimpleAttachment;
 import org.codehaus.xfire.exchange.InMessage;
 import org.codehaus.xfire.service.OperationInfo;
 import org.codehaus.xfire.service.Service;
@@ -84,6 +88,15 @@
         ctx.setCurrentMessage(msg);
         NormalizedMessage in = exchange.getMessage("in");
         msg.setXMLStreamReader(getXMLStreamReader(in.getContent()));
+        if (in.getAttachmentNames() != null && in.getAttachmentNames().size() >
0) {
+            JavaMailAttachments attachments = new JavaMailAttachments();
+            for (Iterator it = in.getAttachmentNames().iterator(); it.hasNext();) {
+                String name = (String) it.next();
+                DataHandler dh = in.getAttachment(name);
+                attachments.addPart(new SimpleAttachment(name, dh));
+            }
+            msg.setAttachments(attachments);
+        }
         c.receive(ctx, msg);
         c.close();
         

Added: incubator/servicemix/trunk/servicemix-jsr181/src/test/java/org/apache/servicemix/jsr181/Jsr181MTOMTest.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-jsr181/src/test/java/org/apache/servicemix/jsr181/Jsr181MTOMTest.java?rev=428124&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-jsr181/src/test/java/org/apache/servicemix/jsr181/Jsr181MTOMTest.java
(added)
+++ incubator/servicemix/trunk/servicemix-jsr181/src/test/java/org/apache/servicemix/jsr181/Jsr181MTOMTest.java
Wed Aug  2 13:06:38 2006
@@ -0,0 +1,101 @@
+/*
+ * 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.servicemix.jsr181;
+
+import javax.activation.DataHandler;
+import javax.jbi.messaging.InOut;
+import javax.jbi.servicedesc.ServiceEndpoint;
+import javax.naming.InitialContext;
+import javax.xml.namespace.QName;
+
+import junit.framework.TestCase;
+
+import org.apache.servicemix.client.DefaultServiceMixClient;
+import org.apache.servicemix.client.Destination;
+import org.apache.servicemix.jbi.container.JBIContainer;
+import org.apache.servicemix.jbi.jaxp.SourceTransformer;
+import org.apache.servicemix.jbi.jaxp.StringSource;
+import org.apache.servicemix.jbi.util.ByteArrayDataSource;
+import org.w3c.dom.Document;
+
+public class Jsr181MTOMTest extends TestCase {
+
+    protected JBIContainer container;
+    
+    protected void setUp() throws Exception {
+        container = new JBIContainer();
+        container.setUseMBeanServer(false);
+        container.setCreateMBeanServer(false);
+        container.setMonitorInstallationDirectory(false);
+        container.setNamingContext(new InitialContext());
+        container.setEmbedded(true);
+        container.init();
+    }
+    
+    protected void tearDown() throws Exception {
+        if (container != null) {
+            container.shutDown();
+        }
+    }
+
+    public void testMtom() throws Exception {
+        Jsr181SpringComponent jsr181 = new Jsr181SpringComponent();
+        Jsr181Endpoint ep = new Jsr181Endpoint();
+        ep.setPojo(new EchoWithAttachment());
+        ep.setMtomEnabled(true);
+        jsr181.setEndpoints(new Jsr181Endpoint[] { ep });
+        
+        container.activateComponent(jsr181, "jsr181");
+        container.start();
+        
+        QName service = new QName("http://jsr181.servicemix.apache.org", "EchoWithAttachment");
+        ServiceEndpoint se = container.getRegistry().getEndpointsForService(service)[0];
+        Document doc = container.getRegistry().getEndpointDescriptor(se);
+        String wsdl = new SourceTransformer().toString(doc);
+        System.err.println(wsdl);
+        
+        DefaultServiceMixClient client = new DefaultServiceMixClient(container);
+        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")));
+        
+        client.sendSync(me);
+        
+    }
+    
+    public static class EchoWithAttachment {
+        
+        /*
+         * Do not use byte[] until xfire-1.2
+        public String 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;
+        }
+    }
+    
+}



Mime
View raw message