MIME-attach in java SOAPMessage

773 views Asked by At

Before I asked about how to create MIME-atachment text/xml in Java and now, I have one simple question. If I have this MIME structure:

Content-Type: Multipart/Related; boundary=MIME_boundary; type=text/xml; start="<TEST>" 
--MIME_boundary 
Content-Type: text/xml; charset=UTF-8 
Content-Transfer-Encoding: 8bit Content-ID:<TEST> 

and in the end:

--MIME_boundary 
Content-Type: application/zip 
Content-Transfer-Encoding: binary 
Content-ID: <package1> 
<!-- attach --> 
--MIME_boundary

How can I do this structure with Java SOAP? Also, I try this code from my prev. question:

import javax.activation.*;

class BinaryDataSource implements DataSource {
    InputStream _is;

    public BinaryDataSource(InputStream is) {
        _is = is;
    }
    public String getContentType() { return "application/binary"; }
    public InputStream getInputStream() throws IOException { return _is; }
    public String getName() { return "some file"; }
    public OutputStream getOutputStream() throws IOException {
        throw new IOException("Cannot write to this file");
    }
}

And code example look this:

    InputStream data = ...
    SOAPMessage msg = ...
    DataHandler dh = new DataHandler(new BinaryDataSource(data));
    AttachmentPart attachment = msg.createAttachmentPart(dh);
    msg.addAttachmentPart(attachment);

It generate attach, but without needless struct. I'm new in SOAP. Thanks

0

There are 0 answers