servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r397492 - in /incubator/servicemix/trunk/servicemix-soap/src: main/java/org/apache/servicemix/soap/marshalers/SoapReader.java test/java/org/apache/servicemix/soap/marshalers/SoapMessageMarshalerTest.java
Date Thu, 27 Apr 2006 09:43:08 GMT
Author: gnodet
Date: Thu Apr 27 02:43:07 2006
New Revision: 397492

URL: http://svn.apache.org/viewcvs?rev=397492&view=rev
Log:
SM-409: Do not assume that first part of multi mime message is xml
Patch provided by Stefan Klinger, thx !

Modified:
    incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/marshalers/SoapReader.java
    incubator/servicemix/trunk/servicemix-soap/src/test/java/org/apache/servicemix/soap/marshalers/SoapMessageMarshalerTest.java

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=397492&r1=397491&r2=397492&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
Thu Apr 27 02:43:07 2006
@@ -28,11 +28,13 @@
 import javax.xml.namespace.QName;
 import javax.xml.stream.XMLStreamConstants;
 import javax.xml.stream.XMLStreamReader;
+import javax.xml.transform.Source;
 import javax.xml.transform.stream.StreamSource;
 
 import org.apache.servicemix.jbi.jaxp.ExtendedXMLStreamReader;
 import org.apache.servicemix.jbi.jaxp.FragmentStreamReader;
 import org.apache.servicemix.jbi.jaxp.StaxSource;
+import org.apache.servicemix.jbi.jaxp.StringSource;
 import org.apache.servicemix.soap.SoapFault;
 import org.w3c.dom.Document;
 import org.w3c.dom.DocumentFragment;
@@ -46,6 +48,8 @@
 public class SoapReader {
 
 	private SoapMarshaler marshaler;
+  
+  protected static final Source EMPTY_CONTENT = new StringSource("<payload/>");
 
 	public SoapReader(SoapMarshaler marshaler) {
 		this.marshaler = marshaler;
@@ -139,13 +143,29 @@
 			ContentType type = new ContentType(mime.getContentType());
 			String contentId = type.getParameter("start");
 			// Get request
-			MimeBodyPart contentPart;
+			MimeBodyPart contentPart = null;
             if (contentId != null) {
                 contentPart = (MimeBodyPart) multipart.getBodyPart(contentId);
             } else {
-                contentPart = (MimeBodyPart) multipart.getBodyPart(0);
+                for (int i = 0; i < multipart.getCount(); i++) {
+                  MimeBodyPart contentPart2 = (MimeBodyPart) multipart.getBodyPart(i);
+                  String contentType = contentPart2.getContentType();
+                  
+                  if (contentType.indexOf("xml") >= 0) {
+                    contentPart = contentPart2;
+                    break;
+                  }
+                }
             }
-            SoapMessage message = read(contentPart.getInputStream());
+            
+            SoapMessage message = null;
+            if (contentPart != null) {
+              message = read(contentPart.getInputStream());  
+            } else {
+              message = new SoapMessage();
+              message.setSource(EMPTY_CONTENT);
+            }
+            
             // Get attachments
 			for (int i = 0; i < multipart.getCount(); i++) {
                 MimeBodyPart part = (MimeBodyPart) multipart.getBodyPart(i);

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=397492&r1=397491&r2=397492&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
Thu Apr 27 02:43:07 2006
@@ -21,9 +21,14 @@
 import java.io.InputStream;
 import java.net.URI;
 import java.util.Iterator;
+import java.util.Properties;
 
 import javax.activation.DataHandler;
 import javax.activation.FileDataSource;
+import javax.mail.Session;
+import javax.mail.internet.MimeBodyPart;
+import javax.mail.internet.MimeMessage;
+import javax.mail.internet.MimeMultipart;
 import javax.xml.namespace.QName;
 import javax.xml.transform.dom.DOMSource;
 import javax.xml.transform.stream.StreamSource;
@@ -197,7 +202,35 @@
         checkServiceNameNamespace((DocumentFragment) headers.next());
 		assertFalse(headers.hasNext());
 	}
-	
+
+    public void testReadNonSoapMessageWithAttachmentsAndNoSource()  throws Exception {
+        Session session = Session.getDefaultInstance(new Properties(), null);
+        MimeMessage message = new MimeMessage(session);
+        MimeMultipart multipart = new MimeMultipart();
+        MimeBodyPart mimePart = new MimeBodyPart();
+        mimePart.setText("This is a dummy text");
+        mimePart.setContentID("<bla1>");
+        multipart.addBodyPart(mimePart);
+        mimePart = new MimeBodyPart();
+        mimePart.setContentID("<bla2>");
+        mimePart.setContent("<html>dummy</html>", "text/html");
+        multipart.addBodyPart(mimePart);
+        message.setContent(multipart);
+        message.setHeader("Content-Type", multipart.getContentType());
+        message.saveChanges();
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        message.writeTo(baos);
+        log.info(baos.toString());
+        
+        SoapMarshaler marshaler = new SoapMarshaler(true);
+        SoapMessage msg = marshaler.createReader().read(new ByteArrayInputStream(baos.toByteArray()),
multipart.getContentType());
+        assertTrue(msg.getSource().equals(SoapReader.EMPTY_CONTENT));
+        SoapWriter writer = marshaler.createWriter(msg);
+        baos = new ByteArrayOutputStream();
+        writer.write(baos);
+        log.info(baos.toString());
+    }
+  
 	protected void checkUserIdNamespace(Node node) throws Exception {
         CachedXPathAPI cachedXPathAPI = new CachedXPathAPI(); 
         NodeIterator iterator = cachedXPathAPI.selectNodeIterator(node, "//*[local-name()
= 'userId']"); 



Mime
View raw message