Link to home
Create AccountLog in
Avatar of maskedavenger
maskedavenger

asked on

Multipart/Related Attachment using SAAJ

I want to create a multipart/related SOAP attachment.

I have 2 files:
- SMIL file
<?xml version="1.0"?>
<!DOCTYPE smil PUBLIC "-//W3C//DTD SMIL 2.0//EN"
                      "http://www.w3.org/2001/SMIL20/SMIL20.dtd">
<smil xmlns="http://www.w3.org/2001/SMIL20/Language">
...
<body>
<text src="textfile.txt"/>
</body>
</smil>

- The text file textfile.txt

Both these files have been added to the message using the SAAJ API.
message.addAttachmentPart(part);

But this results in a message with attachments as follows:
------=_Part_1_9856161.1191500782875
Content-Type: application/smil
Content-Location: test.smil
Content-ID: test.smil

<?xml version="1.0"?>
<!DOCTYPE smil PUBLIC "-//W3C//DTD SMIL 2.0//EN"
                      "http://www.w3.org/2001/SMIL20/SMIL20.dtd">
<smil xmlns="http://www.w3.org/2001/SMIL20/Language">
<head>
<layout>
<region id="Text" height="100%" width="100%" fit="scroll"/>
</layout>
</head>
<body>
<par dur="10s">
<text src="textfile.txt" region="Text"/>
</par>
</body>
</smil>
------=_Part_1_9856161.1191500782875
------=_Part_1_9856161.1191500782875
Content-Type: text/plain
Content-Location: textfile.txt
Content-ID: textfile.txt

Simple Text File
------=_Part_1_9856161.1191500782875--

What I need is a multipart/related attachment that will give me a request looking more like the following:
------=_Part_2_26795951.1128424414453
Content-Type: multipart/Related;Type="application/smil";Start="<SMIL>";
\x09
boundary="----=_Part_1_13100371.1128424413640"
Content-Id: SOAPContentID
------=_Part_1_13100371.1128424413640
Content-Type: application/smil
Content-Transfer-Encoding: 7bit
Content-ID: <SMIL>
<smil><head><layout><root-layout/><region id="Image" top="0" left="0" height="50%" width="100%"/><region id="Text" top="50%" left="0" height="50%" width="100%"/></layout></head>
<body>
<par dur="10s">
<text src="textfile.txt" region="Text"/>
</par>
</body>
</smil>
------=_Part_1_13100371.1128424413640
Content-Type: text/plain
Content-Location: textfile.txt
Content-ID: textfile.txt

Simple Text File
------=_Part_1_13100371.1128424413640--
------=_Part_2_26795951.1128424414453--

Please any advice or suggestions would be great.
ASKER CERTIFIED SOLUTION
Avatar of rama_krishna580
rama_krishna580
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of maskedavenger
maskedavenger

ASKER

Thanks for the links Rama,

"Attachments are available to Java developers through both JAX-RPC (the Java API for XML-based RPC) and SAAJ (SOAP with Attachments API for Java). Don't let the SAAJ acronym fool you: JAX-RPC supports attachments (see Resources  for an example). The difference between JAX-RPC and SAAJ is the level of abstraction, not the capabilities." - http://www.devx.com/ibm/Article/20254

I think what I am going to do is to play around with SAAJ some more, but if I can't get it working I'll create a similar client using JAX-RPC.  

Something caught my eye on this page,
(https://jax-rpc.dev.java.net/whitepaper/1.1.2/attachments.html):

MIME Type     Java Type
multipart/*         javax.mail.internet.MimeMultipart

Perhaps I could use this class to create a multipart message.

Regards, M.A

k
\)_()   j
(º Ë) j j
°\__)

PS.  I want to link this thread with https://www.experts-exchange.com/questions/22868937/SMIL-as-SOAP-Attachment-using-SAAJ.html?cid=239&anchorAnswerId=20015158#a20015158
since it is practically the same question.  Only better stated here I think :).
     
Alright here's the deal:

1) Create a javax.mail.internet.MimeMultipart object.
2) Add all your attachments to this object as MimeBodyParts.
3) Finally add this object as an AttachmentPart to the SOAPMessage.