servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r387995 - in /incubator/servicemix/trunk: etc/ servicemix-http/src/test/java/org/apache/servicemix/http/ servicemix-soap/src/main/java/org/apache/servicemix/soap/marshalers/ servicemix-soap/src/test/java/org/apache/servicemix/soap/marshalers/
Date Thu, 23 Mar 2006 01:34:41 GMT
Author: gnodet
Date: Wed Mar 22 17:34:39 2006
New Revision: 387995

URL: http://svn.apache.org/viewcvs?rev=387995&view=rev
Log:
SM-361: MIME attachments using multipart/form-data are not handled

Modified:
    incubator/servicemix/trunk/etc/project.properties
    incubator/servicemix/trunk/servicemix-http/src/test/java/org/apache/servicemix/http/HttpSpringTest.java
    incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/marshalers/SoapMarshaler.java
    incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/marshalers/SoapReader.java
    incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/marshalers/SoapWriter.java
    incubator/servicemix/trunk/servicemix-soap/src/test/java/org/apache/servicemix/soap/marshalers/SoapMessageMarshalerTest.java

Modified: incubator/servicemix/trunk/etc/project.properties
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/etc/project.properties?rev=387995&r1=387994&r2=387995&view=diff
==============================================================================
--- incubator/servicemix/trunk/etc/project.properties (original)
+++ incubator/servicemix/trunk/etc/project.properties Wed Mar 22 17:34:39 2006
@@ -182,7 +182,7 @@
 geronimo_spec_j2ee_jaxrpc_version=1.0
 geronimo_spec_j2ee_connector_version=1.0
 geronimo_spec_j2ee_version=1.0
-geronimo_spec_javamail_version=1.0
+geronimo_spec_javamail_version=1.1-20060323
 geronimo_spec_jms_version=1.0
 geronimo_spec_jta_version=1.0
 geronimo_spec_jsp_version=1.0

Modified: incubator/servicemix/trunk/servicemix-http/src/test/java/org/apache/servicemix/http/HttpSpringTest.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-http/src/test/java/org/apache/servicemix/http/HttpSpringTest.java?rev=387995&r1=387994&r2=387995&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-http/src/test/java/org/apache/servicemix/http/HttpSpringTest.java
(original)
+++ incubator/servicemix/trunk/servicemix-http/src/test/java/org/apache/servicemix/http/HttpSpringTest.java
Wed Mar 22 17:34:39 2006
@@ -15,18 +15,32 @@
  */
 package org.apache.servicemix.http;
 
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.OutputStream;
+
 import javax.jbi.messaging.ExchangeStatus;
 import javax.jbi.messaging.InOut;
 import javax.xml.namespace.QName;
 
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.methods.RequestEntity;
+import org.apache.commons.httpclient.methods.multipart.FilePart;
+import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity;
+import org.apache.commons.httpclient.methods.multipart.Part;
+import org.apache.commons.httpclient.methods.multipart.StringPart;
+import org.apache.commons.httpclient.util.EncodingUtil;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.servicemix.client.DefaultServiceMixClient;
 import org.apache.servicemix.jbi.jaxp.SourceTransformer;
 import org.apache.servicemix.jbi.jaxp.StringSource;
+import org.apache.servicemix.soap.marshalers.SoapMarshaler;
 import org.apache.servicemix.tck.SpringTestSupport;
-import org.springframework.context.support.AbstractXmlApplicationContext;
 import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
+import org.springframework.context.support.AbstractXmlApplicationContext;
 
 public class HttpSpringTest extends SpringTestSupport {
 
@@ -50,7 +64,24 @@
             logger.info(new SourceTransformer().toString(me.getOutMessage().getContent()));
         }
     }
-    
+
+    public void testMimeWithHttpClient() throws Exception {
+        File f = new File(getClass().getResource("servicemix.jpg").getFile());
+        PostMethod filePost = new PostMethod("http://localhost:8192/Service/");
+        Part[] parts = { 
+            new StringPart("request", "<dummy/>"),
+            new FilePart(f.getName(), f) };
+        RequestEntity entity = new MultipartRequestEntity(parts, filePost.getParams());
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        entity.writeRequest(baos);
+        System.err.println(baos);
+        filePost.setRequestEntity(entity);
+        HttpClient client = new HttpClient();
+        int status = client.executeMethod(filePost);
+        assertEquals(200, status);
+        filePost.releaseConnection();
+    }
+
     protected AbstractXmlApplicationContext createBeanFactory() {
         return new ClassPathXmlApplicationContext("org/apache/servicemix/http/spring.xml");
     }

Modified: incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/marshalers/SoapMarshaler.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/marshalers/SoapMarshaler.java?rev=387995&r1=387994&r2=387995&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/marshalers/SoapMarshaler.java
(original)
+++ incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/marshalers/SoapMarshaler.java
Wed Mar 22 17:34:39 2006
@@ -28,7 +28,7 @@
  */
 public class SoapMarshaler {
 
-	public static final String MULTIPART_CONTENT = "multipart/related";
+	public static final String MULTIPART_CONTENT = "multipart/";
 	public static final String SOAP_PART_ID = "soap-request";
 	public static final String SOAP_11_URI = "http://schemas.xmlsoap.org/soap/envelope/";
 	public static final String SOAP_12_URI = "http://www.w3.org/2003/05/soap-envelope";

Modified: incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/marshalers/SoapReader.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/marshalers/SoapReader.java?rev=387995&r1=387994&r2=387995&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/marshalers/SoapReader.java
(original)
+++ incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/marshalers/SoapReader.java
Wed Mar 22 17:34:39 2006
@@ -15,7 +15,9 @@
  */
 package org.apache.servicemix.soap.marshalers;
 
+import java.io.ByteArrayInputStream;
 import java.io.InputStream;
+import java.io.SequenceInputStream;
 import java.util.Properties;
 
 import javax.mail.Session;
@@ -51,8 +53,9 @@
 
 	public SoapMessage read(InputStream is, String contentType)
 			throws Exception {
-		if (contentType != null && contentType.toLowerCase().indexOf(SoapMarshaler.MULTIPART_CONTENT)
!= -1) {
+		if (contentType != null && contentType.toLowerCase().startsWith(SoapMarshaler.MULTIPART_CONTENT))
{
 			Session session = Session.getDefaultInstance(new Properties());
+            is = new SequenceInputStream(new ByteArrayInputStream(new byte[] { 13, 10 }),
is);
 			MimeMessage mime = new MimeMessage(session, is);
 			mime.setHeader("Content-Type", contentType);
 			return read(mime);
@@ -135,18 +138,22 @@
 			MimeMultipart multipart = (MimeMultipart) content;
 			ContentType type = new ContentType(mime.getContentType());
 			String contentId = type.getParameter("start");
-			if (contentId == null) {
-				contentId = ((MimeBodyPart) multipart.getBodyPart(0))
-						.getContentID();
-			}
 			// Get request
-			MimeBodyPart part = (MimeBodyPart) multipart.getBodyPart(contentId);
-			SoapMessage message = read(part.getInputStream());
+			MimeBodyPart contentPart;
+            if (contentId != null) {
+                contentPart = (MimeBodyPart) multipart.getBodyPart(contentId);
+            } else {
+                contentPart = (MimeBodyPart) multipart.getBodyPart(0);
+            }
+            SoapMessage message = read(contentPart.getInputStream());
+            // Get attachments
 			for (int i = 0; i < multipart.getCount(); i++) {
-				part = (MimeBodyPart) multipart.getBodyPart(i);
-				String id = part.getContentID();
-				if (id != null && !id.equals(contentId)) {
-					if (id.startsWith("<")) {
+                MimeBodyPart part = (MimeBodyPart) multipart.getBodyPart(i);
+                if (part != contentPart) {
+                    String id = part.getContentID();
+                    if (id == null) {
+                        id = "Part" + i;
+                    } else if (id.startsWith("<")) {
 						id = id.substring(1, id.length() - 1);
 					}
 					message.addAttachment(id, part.getDataHandler());

Modified: incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/marshalers/SoapWriter.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/marshalers/SoapWriter.java?rev=387995&r1=387994&r2=387995&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/marshalers/SoapWriter.java
(original)
+++ incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/marshalers/SoapWriter.java
Wed Mar 22 17:34:39 2006
@@ -16,12 +16,18 @@
 package org.apache.servicemix.soap.marshalers;
 
 import java.io.ByteArrayOutputStream;
+import java.io.FilterOutputStream;
+import java.io.IOException;
 import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.Enumeration;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 import java.util.Properties;
 
 import javax.activation.DataHandler;
+import javax.mail.Header;
 import javax.mail.Session;
 import javax.mail.internet.MimeBodyPart;
 import javax.mail.internet.MimeMessage;
@@ -130,7 +136,28 @@
             parts.addBodyPart(part);
         }
         mime.setContent(parts);
-        mime.writeTo(out);
+        mime.setHeader("Content-Type", getContentType());
+        // We do not want headers, so 
+        //  * retrieve all headers
+        //  * skip first 2 bytes (CRLF)
+        mime.saveChanges();
+        Enumeration headersEnum = mime.getAllHeaders();
+        List headersList = new ArrayList();
+        while (headersEnum.hasMoreElements()) {
+            headersList.add(((Header) headersEnum.nextElement()).getName().toLowerCase());
+        }
+        String[] headers = (String[]) headersList.toArray(new String[0]);
+        // Skip first 2 bytes
+        OutputStream os = new FilterOutputStream(out) {
+            private int nb = 0;
+            public void write(int b) throws IOException {
+                if (++nb > 2) {
+                    super.write(b);
+                }
+            }
+        };
+        // Write
+        mime.writeTo(os, headers);
     }
 
     private void writeSoapEnvelope(XMLStreamWriter writer) throws Exception {

Modified: incubator/servicemix/trunk/servicemix-soap/src/test/java/org/apache/servicemix/soap/marshalers/SoapMessageMarshalerTest.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-soap/src/test/java/org/apache/servicemix/soap/marshalers/SoapMessageMarshalerTest.java?rev=387995&r1=387994&r2=387995&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-soap/src/test/java/org/apache/servicemix/soap/marshalers/SoapMessageMarshalerTest.java
(original)
+++ incubator/servicemix/trunk/servicemix-soap/src/test/java/org/apache/servicemix/soap/marshalers/SoapMessageMarshalerTest.java
Wed Mar 22 17:34:39 2006
@@ -18,6 +18,7 @@
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.File;
+import java.io.InputStream;
 import java.net.URI;
 import java.util.Iterator;
 
@@ -34,8 +35,7 @@
 import org.apache.servicemix.jbi.jaxp.BytesSource;
 import org.apache.servicemix.jbi.jaxp.SourceTransformer;
 import org.apache.servicemix.jbi.util.DOMUtil;
-import org.apache.servicemix.soap.marshalers.SoapMarshaler;
-import org.apache.servicemix.soap.marshalers.SoapMessage;
+import org.apache.servicemix.jbi.util.FileUtil;
 import org.apache.xpath.CachedXPathAPI;
 import org.w3c.dom.Document;
 import org.w3c.dom.DocumentFragment;
@@ -98,8 +98,16 @@
 		assertNotNull(msg2);
 		assertTrue(msg2.hasAttachments());
 		assertEquals(1, msg2.getAttachments().size());
-		DataHandler handler = (DataHandler) msg2.getAttachments().get(msg2.getAttachments().keySet().iterator().next());
-		assertNotNull(handler);
+        DataHandler handler1 = (DataHandler) msg.getAttachments().get(msg.getAttachments().keySet().iterator().next());
+		DataHandler handler2 = (DataHandler) msg2.getAttachments().get(msg2.getAttachments().keySet().iterator().next());
+        assertNotNull(handler2);
+        InputStream is1 = handler1.getInputStream();
+        InputStream is2 = handler2.getInputStream();
+        ByteArrayOutputStream baos1 = new ByteArrayOutputStream();
+        ByteArrayOutputStream baos2 = new ByteArrayOutputStream();
+        FileUtil.copyInputStream(is1, baos1);
+        FileUtil.copyInputStream(is2, baos2);
+        assertEquals(baos1.toString(), baos2.toString());
 		assertFalse(msg2.hasHeaders());
 		assertNotNull(msg2.getSource());
 		Node node = sourceTransformer.toDOMNode(msg2.getSource());



Mime
View raw message