You are viewing a plain text version of this content. The canonical link for it is here.
Posted to soap-user@xml.apache.org by Yasir Khalil Al Masri <ya...@next.jo> on 2001/07/15 13:07:44 UTC

SOAP Envelope with Mime Part

Hi,

I'm developing a messaging implementation that carries mime parts.  
There is a method on the server that look like this:
1. public void getContent(Envelope env, SOAPContext reqCtx, SOAPContext 
2.                                                            retCtx) {
3.    ...
4.    SOAPMappingRegistry registry = new SOAPMappingRegistry();
5.    StringWriter st = new StringWriter();
6.    //env: is an Envelope object that has simple XML document with 
7.    //"http://schemas.xmlsoap.org/soap/envelope:Envelope" being the 
8.    //root element, and without any attachments inside the header.
9.    env.marshall( st, registry, reqCtx );
10.   retCtx.setRootPart( st.toString(),
11.                                  Constants.HEADERVAL_CONTENT_TYPE );
12.}

At the client side, getting this envelope is simple:

13. //msg: is the Message object that has been used to send an Envelope 
14. //request to the server.
15. DataHandler dh = msg.receive()
16. DataSource ds = dh.getDataSource();
17. ByteArrayDataSource bds = new ByteArrayDataSource(
18.                          ds.getInputStream(), dh.getContentType() );
19. bds.writeTo( new FileOutputStream( "file.xml" ) );

Now suppose at the server that I wanted to send a ".gif" file, then 
lines 10 & 11 should've been looked like this:

10'. //mbp: is a MimeBodyPart object of the ".gif" file.
11'. retCtx.setRootPart( mbp );

Again, at the client side the code from line 13 to 19 should not 
change.  Now, if I want to send the client back an envelope with 
attachment(s) I can't use both (10-11) and (10'-11') because one of 
them will take effect at the client side (it's the one that comes last 
in your program).  I thought that I could send an envelope back to the 
client with attachment in the "Head" part, but I was blocked with the 
fact that I can't get the attachment from within the envelope, and 
that's simply because using "receive()" at the client will supply me 
with BufferedReader if used on the SOAPTransport object, or DataHandler 
if used on the Message object.  Now for the BufferedReader no way to 
get the attachment out of it; as you can only send it to standard 
output or create a DOM object, etc. While for the DataHandler I didn't 
find any method that enables me to get MimeBodyPart(s) out of it, or 
even from the DataSource object that you can get it out of it!
Will you please guys help in this, I'm stuck!
Your input is much appreciated.