snichol 2002/11/12 06:34:56 Modified: java/src/org/apache/soap/rpc Call.java java/src/org/apache/soap/transport TransportMessage.java java/src/org/apache/soap Constants.java Log: Submitted by: Pavel Ausianik <[EMAIL PROTECTED]> I have prepared patch for using predefined const ContentType, similar to patch was done to MimeType. I have traced MimeBodyPart.isMimeType implementation... Revision Changes Path 1.20 +12 -3 xml-soap/java/src/org/apache/soap/rpc/Call.java Index: Call.java =================================================================== RCS file: /home/cvs/xml-soap/java/src/org/apache/soap/rpc/Call.java,v retrieving revision 1.19 retrieving revision 1.20 diff -u -r1.19 -r1.20 --- Call.java 11 Nov 2002 14:34:47 -0000 1.19 +++ Call.java 12 Nov 2002 14:34:56 -0000 1.20 @@ -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)); } 1.18 +12 -6 xml-soap/java/src/org/apache/soap/transport/TransportMessage.java Index: TransportMessage.java =================================================================== RCS file: /home/cvs/xml-soap/java/src/org/apache/soap/transport/TransportMessage.java,v retrieving revision 1.17 retrieving revision 1.18 diff -u -r1.17 -r1.18 --- TransportMessage.java 12 Nov 2002 14:15:38 -0000 1.17 +++ TransportMessage.java 12 Nov 2002 14:34:56 -0000 1.18 @@ -267,8 +267,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); @@ -297,7 +296,7 @@ // If the root part is text, extract it as a String. // Note that we could use JAF's help to do this (see save()) // 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("")) @@ -357,10 +356,17 @@ } else { MimeBodyPart rootPart = ctx.getRootPart(); if (rootPart != null) { - 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)) { ByteArrayDataSource ds = new ByteArrayDataSource( - rootPart.getInputStream(), rootPart.getContentType()); - envelope = ds.getText(); + rootPart.getInputStream(), ctype); + envelope = ds.getText(); } } } 1.27 +8 -0 xml-soap/java/src/org/apache/soap/Constants.java Index: Constants.java =================================================================== RCS file: /home/cvs/xml-soap/java/src/org/apache/soap/Constants.java,v retrieving revision 1.26 retrieving revision 1.27 diff -u -r1.26 -r1.27 --- Constants.java 28 Jun 2002 03:07:36 -0000 1.26 +++ Constants.java 12 Nov 2002 14:34:56 -0000 1.27 @@ -58,6 +58,7 @@ package org.apache.soap; import org.apache.soap.util.xml.QName; +import javax.mail.internet.ContentType; /** * <em>SOAP</em> constants. @@ -65,6 +66,7 @@ * @author Sanjiva Weerawarana ([EMAIL PROTECTED]) * @author Matthew J. Duftler ([EMAIL PROTECTED]) * @author Scott Nichol ([EMAIL PROTECTED]) + * @author Pavel Ausianik ([EMAIL PROTECTED]) */ public class Constants { @@ -301,4 +303,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); + }
-- To unsubscribe, e-mail: <mailto:soap-dev-unsubscribe@;xml.apache.org> For additional commands, e-mail: <mailto:soap-dev-help@;xml.apache.org>