Hello,

I have prepared patch  for using predefined const  ContentType,  similar to
patch was done to MimeType . I have traced MimeBodyPart.isMimeType
implementation...

Please find attached

Best regards,
Pavel

Index: Call.java
===================================================================
RCS file: /home/cvspublic/xml-soap/java/src/org/apache/soap/rpc/Call.java,v
retrieving revision 1.19
diff -u -r1.19 Call.java
--- Call.java   11 Nov 2002 14:34:47 -0000      1.19
+++ Call.java   11 Nov 2002 17:32:58 -0000
@@ -73,6 +73,8 @@
 import org.apache.soap.server.*;
 import javax.mail.MessagingException;
 import javax.mail.internet.MimeBodyPart;
+import javax.mail.internet.ContentType;
+import javax.mail.internet.ParseException;
 
 /**
  * A <code>Call</code> object represents an <em>RPC</em> call. Both the
@@ -269,7 +271,14 @@
     String payloadStr = null;
 
     MimeBodyPart rootPart = respCtx.getRootPart();
-    if (rootPart.isMimeType("text/*")) {
+    String ctype = rootPart.getContentType();
+    ContentType type = null;
+    try {
+        type = new ContentType(ctype);
+    }
+    catch (ParseException e) {}
+
+    if (type != null && Constants.CTYPE_TEXT_ALL.match(type)) {
       // Get the input stream to read the response envelope from.
       in = st.receive();
       payloadStr = IOUtils.getStringFromReader(in);
@@ -277,10 +286,10 @@
 
     // Check Content-Type of root part of response to see if it's
     // consistent with a SOAP envelope (text/xml).
-    if (!rootPart.isMimeType(Constants.HEADERVAL_CONTENT_TYPE)) {
+    if (type == null || !Constants.CTYPE_TEXT_XML.match(type)) {
       throw new SOAPException(Constants.FAULT_CODE_PROTOCOL,
         "Unsupported response content type \"" +
-        rootPart.getContentType() + "\", must be: \"" +
+        ctype + "\", must be: \"" +
         Constants.HEADERVAL_CONTENT_TYPE + "\"." +
         (payloadStr == null ? "" : " Response was:\n" + payloadStr));
     }
Index: Constants.java
===================================================================
RCS file: /home/cvspublic/xml-soap/java/src/org/apache/soap/Constants.java,v
retrieving revision 1.26
diff -u -r1.26 Constants.java
--- Constants.java      28 Jun 2002 03:07:36 -0000      1.26
+++ Constants.java      11 Nov 2002 17:34:10 -0000
@@ -58,6 +58,7 @@
 package org.apache.soap;
 
 import org.apache.soap.util.xml.QName;
+import javax.mail.internet.ContentType;
 
 /**
  * <em>SOAP</em> constants.
@@ -83,7 +84,7 @@
     "http://schemas.xmlsoap.org/soap/envelope/";;
   public static final String NS_URI_SOAP_ENC =
     "http://schemas.xmlsoap.org/soap/encoding/";;
-  
+
   public static final String NS_URI_1999_SCHEMA_XSI =
     "http://www.w3.org/1999/XMLSchema-instance";;
   public static final String NS_URI_1999_SCHEMA_XSD =
@@ -137,7 +138,7 @@
     HEADERVAL_MULTIPART_CONTENT_SUBTYPE;
 
   // XML Declaration string
-  public static final String XML_DECL = 
+  public static final String XML_DECL =
     "<?xml version='1.0' encoding='UTF-8'?>\r\n";
 
   // Element names.
@@ -301,4 +302,10 @@
     new QName(Constants.NS_URI_2001_SCHEMA_XSD, "dateTime");
   public static final QName object2001QName =
     new QName(Constants.NS_URI_2001_SCHEMA_XSD, "anyType");
+
+  public static final ContentType CTYPE_TEXT_ALL = new ContentType("text", "*", null);
+  public static final ContentType CTYPE_TEXT_XML = new ContentType("text", "xml", 
+null);
+  public static final ContentType CTYPE_MULTIPART =
+          new ContentType(HEADERVAL_CONTENT_TYPE_MULTIPART_PRIMARY, "*", null);
+
 }
Index: TransportMessage.java
===================================================================
RCS file: 
/home/cvspublic/xml-soap/java/src/org/apache/soap/transport/TransportMessage.java,v
retrieving revision 1.16
diff -u -r1.16 TransportMessage.java
--- TransportMessage.java       6 Sep 2002 17:02:58 -0000       1.16
+++ TransportMessage.java       11 Nov 2002 17:47:30 -0000
@@ -256,8 +256,7 @@
         MimeBodyPart rootPart;
         ContentType rootContentType;
         byte[] rootBytes;
-        if (cType.match(Constants.HEADERVAL_CONTENT_TYPE_MULTIPART_PRIMARY +
-                        "/*")) {
+        if (Constants.CTYPE_MULTIPART.match(cType))  {
             // Parse multipart request.
             ByteArrayDataSource ds = new ByteArrayDataSource(bytes,
                                                              contentType);
@@ -286,7 +285,7 @@
         // If the root part is text, extract it as a String.
         // Note that we could use JAF's help to do this (see getEnvelope())
         // but implementing it ourselves is safer and faster.
-        if (rootContentType.match("text/*")) {
+        if (Constants.CTYPE_TEXT_ALL.match( rootContentType)) {
             String charset = rootContentType.getParameter("charset");
             // Hmm, risky, the default charset is transport-specific...
             if (charset == null || charset.equals(""))
@@ -435,11 +434,19 @@
     public String getEnvelope() throws MessagingException, IOException {
         if (envelope == null) {
             MimeBodyPart rootPart = ctx.getRootPart();
-            if (rootPart != null)
-                if (rootPart.isMimeType("text/*")) {
+            if (rootPart != null) {
+                String ctype = rootPart.getContentType();
+                ContentType type = null;
+                try {
+                    type = new ContentType(ctype);
+                }
+                catch (ParseException e) {}
+
+                if (type != null && Constants.CTYPE_TEXT_ALL.match(type)) {
                     ByteArrayDataSource ds = new ByteArrayDataSource(
-                        rootPart.getInputStream(), rootPart.getContentType());
+                        rootPart.getInputStream(), ctype);
                     envelope = ds.getText();
+                }
             }
         }
         return envelope;

--
To unsubscribe, e-mail:   <mailto:soap-dev-unsubscribe@;xml.apache.org>
For additional commands, e-mail: <mailto:soap-dev-help@;xml.apache.org>

Reply via email to