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 Andrew Yang <An...@Sun.COM> on 2002/08/23 20:31:56 UTC

How to get SOAP Envelope from SOAP with Attachment Message (MIME Type)??

I have used following code to get SOAP Envelope from HTTPServlet Request:

--------------------------------------------------
if(request.getContentLength() > 0)
{
   try
   {
      BufferedReader reader = req.getReader();

      javax.xml.parsers.DocumentBuilder xdb =
                   org.apache.soap.util.xml.XMLParserUtils.getXMLDocBuilder();
      org.w3c.dom.Document doc = xdb.parse(new
                                             org.xml.sax.InputSource(reader));
      org.apache.soap.Envelope env = org.apache.soap.Envelope.unmarshall(
                                             doc.getDocumentElement());
      ... ...
   }
   ... ...
}

.. ... // process the Envelope env
--------------------------------------------------

Now I need to process "SOAP With Attachment" message transmitted via HTTP. The message was sent as

--------------------------------------------------
org.apache.soap.messaging.Message msg = new
                       org.apache.soap.messaging.Message();
if( attachmentFlag ) 
{
   ... ... // get attachment, assume it is a text file.

   MimeBodyPart mbpAttach = new MimeBodyPart();
   mbpAttach.setText(sbu.toString());
   mbpAttach.setHeader("Content-ID", "the-attachment");
   msg.addBodyPart(mbpAttach);
}

msg.send(new java.net.URL(hostURL), URI, envelope);
-------------------------------------------------

If the attachmentFlag is off, I got the Envelope and the program runs fine.

However, if the attachmentFlag is on, the client does indeed sent the MIMI message over HTTP, but the server-side program does not get correct Envelope. The error message is:
SwaHttpReceiveServlet: Exception: 
   org.xml.sax.SAXParseException: Document root element is missing.

I guess I have to somehow disassemble the MIME Message, seperate the SOAP part and the attachment part.

Has anyone had similar problem? How did you solve it? What are possible solutions?

Thanks you in advance!

Andy