You are viewing a plain text version of this content. The canonical link for it is here.
Posted to soap-user@ws.apache.org by Larry Reeder <lr...@freevoice.org> on 2002/07/09 01:31:09 UTC

MIME Header problem in SOAPContext

Hi SOAP users,

I'm trying to create a message-based SOAP service that returns a report as
a set of text and image files (for the example below, I got rid of the
image files in favor of plain text).  I add my files to the SOAP response
context as MimeBodyParts, and set their Content-Type.  For some
reason, the MIME headers are being placed at the end of the attachments,
instead of at the top.


I have the following code in my SOAP service class to add MimeBodyParts to
the response SOAPContext:

  public void getReport(Envelope requestEnvelope, SOAPContext
requestContext, SOAPContext responseContext) throws Exception {

    MimeBodyPart bazzAttachment = getAttachment("/tmp/report/bazz.xml");
    bazzAttachment.setHeader("Content-Type", "text/xml");
    responseContext.setRootPart(bazzAttachment);

    MimeBodyPart fooAttachment = getAttachment("/tmp/report/foo.txt");
    fooAttachment.setHeader("Content-Type", "text/plain");
    responseContext.addBodyPart(fooAttachment);

    MimeBodyPart barAttachment = getAttachment("/tmp/report/bar.txt");
    barAttachment.setHeader("Content-Type", "text/plain");
    responseContext.addBodyPart(barAttachment);

    responseContext.writeTo(new FileOutputStream("/tmp/soapcontext"));
  }

  private MimeBodyPart getAttachment(String fileName) throws Exception {

    File attachmentFile = new File(fileName);

    InputStream is = new FileInputStream(attachmentFile);
    MimeBodyPart attachment = new MimeBodyPart(is);

    return attachment;
  }


This is what TCP Tunnel shows the server sending back to the client:

---------------------8<-------------------------
HTTP/1.0 200 OK
Content-Type: multipart/related;
boundary="----=_Part_1_2544607.1026169243260"; type="text/xml";
start="3923254.1026169245356.apache-soap.tycho.xxx.com"
Content-Length: 455
Set-Cookie2: JSESSIONID=y1zdb36mk1;Version=1;Discard;Path="/soap"
Set-Cookie: JSESSIONID=y1zdb36mk1;Path=/soap
Servlet-Engine: Tomcat Web Server/3.2.1 (JSP 1.1; Servlet 2.2; Java
1.3.1_03; Linux 2.4.7-10custom i386; java.vendor=Sun Microsystems Inc.)

------=_Part_1_2544607.1026169243260
Content-Type: text/xml
Content-Transfer-Encoding: 8bit
Content-ID: <3923254.1026169245356.apache-soap.tycho.xxx.com>
Content-Length: 0


------=_Part_1_2544607.1026169243260
This is foo!
Content-Type: text/plain
Content-Transfer-Encoding: 7bit


------=_Part_1_2544607.1026169243260
This is bar!
Content-Type: text/plain
Content-Transfer-Encoding: 7bit


------=_Part_1_2544607.1026169243260--


-----------------------8<---------------

The proper file content is there, but the MIME headers are in the wrong
place.  According to RFC 2387, the headers should be above the content
of the attachment.  Is this a bug, or am I doing something wrong?

I'm also doing a SOAPContext.writeTo on the server side, which shows
pretty much the same content as above, except for some reason the server
isn't returning the Root body part.

I'm using SOAP 2.3.1, JavaMail 1.3, and JAF 1.0.2

This is causing problems on the client side because the DataHandlers
appear to only write out the content after the MIME headers, so, as a
result I don't get any content at al.


Thanks..............           Larry