You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by ri...@apache.org on 2002/01/18 16:29:44 UTC

cvs commit: xml-axis/java/src/org/apache/axis/attachments MultiPartRelatedInputStream.java

rineholt    02/01/18 07:29:44

  Modified:    java/src/org/apache/axis/attachments
                        MultiPartRelatedInputStream.java
  Log:
  Added support for receiving attachments with other transfer encodings than binary
  
  Revision  Changes    Path
  1.7       +24 -6     xml-axis/java/src/org/apache/axis/attachments/MultiPartRelatedInputStream.java
  
  Index: MultiPartRelatedInputStream.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/attachments/MultiPartRelatedInputStream.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- MultiPartRelatedInputStream.java	3 Dec 2001 22:49:23 -0000	1.6
  +++ MultiPartRelatedInputStream.java	18 Jan 2002 15:29:44 -0000	1.7
  @@ -58,6 +58,7 @@
   import org.apache.axis.attachments.ManagedMemoryDataSource;
   import javax.activation.DataHandler;
   import org.apache.axis.Part;
  +import javax.mail.internet.MimeUtility;
   
   
   /**
  @@ -140,9 +141,10 @@
               boundaryDelimitedStream = new org.apache.axis.attachments.BoundaryDelimitedStream( is, boundary, 1024);
   
               //Now read through all potential streams until we have found the root part.
  +            String contentTransferEncoding = null;
               do {
                   contentId = null;
  -                String contentTransferEncoding = null;
  +                contentTransferEncoding = null;
                   //Read this attachments headers from the stream.  
                   javax.mail.internet.InternetHeaders headers = new javax.mail.internet.InternetHeaders(boundaryDelimitedStream);
                   //Use java mail utility to read through the headers.
  @@ -152,6 +154,7 @@
                       contentId = contentId.trim();
                       if (contentId.startsWith("<")) contentId = contentId.substring(1);
                       if (contentId.endsWith(">")) contentId = contentId.substring(0, contentId.length() - 1);
  +                    contentId = contentId.trim();
                       if (!contentId.startsWith("cid:")) contentId = "cid:" + contentId; //make sure its identified as cid
                   }
   
  @@ -160,16 +163,22 @@
                       contentLocation = contentLocation.trim();
                       if (contentLocation.startsWith("<")) contentLocation = contentLocation.substring(1);
                       if (contentLocation.endsWith(">")) contentLocation = contentLocation.substring(0, contentLocation.length() - 1);
  +                    contentLocation = contentLocation.trim();
                   }
                   contentType = headers.getHeader(HTTPConstants.HEADER_CONTENT_TYPE, null);
                   if (contentType != null) contentType = contentType.trim();
   
                   contentTransferEncoding = headers.getHeader(HTTPConstants.HEADER_CONTENT_TRANSFER_ENCODING, null);
  -                if (contentTransferEncoding != null ) contentTransferEncoding = contentTransferEncoding.trim();
  -                //TODO still need to add support for bas64 and quoted printable.
  +                if(contentTransferEncoding != null ) contentTransferEncoding = contentTransferEncoding.trim();
  +
  +                java.io.InputStream decodedStream=  boundaryDelimitedStream;
  +                if(contentTransferEncoding != null && 0 != contentTransferEncoding.length()){
  +                    decodedStream= MimeUtility.decode(decodedStream, contentTransferEncoding);
  +                }
   
                   if (rootPartContentId != null && !rootPartContentId.equals( contentId)) { //This is a part that has come in prior to the root part. Need to buffer it up.
  -                    javax.activation.DataHandler dh = new javax.activation.DataHandler(new org.apache.axis.attachments.ManagedMemoryDataSource(boundaryDelimitedStream, 16 * 1024, contentType, true));
  +                    javax.activation.DataHandler dh = new javax.activation.DataHandler(new org.apache.axis.attachments.ManagedMemoryDataSource(decodedStream,
  +                   16 * 1024, contentType, true));
   
                       AttachmentPart ap= new AttachmentPart(dh);
                       if(contentId != null) 
  @@ -203,7 +212,10 @@
               if (boundaryDelimitedStream  == null ) {
                   throw new org.apache.axis.AxisFault( "Root part containing SOAP envelope not found.  contentId=" + rootPartContentId);
               }
  -            soapStream = boundaryDelimitedStream; //This should be the SOAP part
  +
  +            if(contentTransferEncoding != null && 0 != contentTransferEncoding.length()){
  +                    soapStream = MimeUtility.decode(boundaryDelimitedStream, contentTransferEncoding);
  +            }else soapStream = boundaryDelimitedStream; //This should be the SOAP part
   
           //Read from the input stream all attachments prior to the root part.
           }
  @@ -292,6 +304,7 @@
                       if (contentId.startsWith("<")) contentId = contentId.substring(1);
                       if (contentId.endsWith(">")) contentId = contentId.substring(0, contentId.length() - 1);
                       if (!contentId.startsWith("cid:")) contentId = "cid:" + contentId;
  +                    contentId = contentId.trim();
                   }
                   contentType = headers.getHeader(HTTPConstants.HEADER_CONTENT_TYPE, null);
                   if (contentType != null) contentType = contentType.trim();
  @@ -300,7 +313,12 @@
                   contentTransferEncoding = headers.getHeader(HTTPConstants.HEADER_CONTENT_TRANSFER_ENCODING , null);
                   if (contentTransferEncoding != null ) contentTransferEncoding = contentTransferEncoding.trim();
   
  -                DataHandler dh= new DataHandler(new ManagedMemoryDataSource(boundaryDelimitedStream, 1024, contentType, true));
  +                java.io.InputStream decodedStream=  boundaryDelimitedStream;
  +                if(contentTransferEncoding != null && 0 != contentTransferEncoding.length()){
  +                    decodedStream= MimeUtility.decode(decodedStream, contentTransferEncoding);
  +                }
  +
  +                DataHandler dh= new DataHandler(new ManagedMemoryDataSource(decodedStream, 1024, contentType, true));
   
                   AttachmentPart ap= new AttachmentPart(dh);
                   if(contentId != null)