Ivan,

In my experience, you can use OMText.isOptimized() to detect whether MTOM is presented. If it is, it will return true.

By the way, in the senario you describe, it seems like you shouldn't need to worry about getting the handler and all that, if you simply want to retrieve the binary data being sent back. The AXIS2 API will automatically converted a MTOM soap back to standard SOAP so you client is not affected by this underline transport technlogy. You can simply get the OMText out and decoded with org.apache.axis2.util.Base64.decode() to get the binary data out...

Of course if you choose, if OMText.isOptimized() returns true, you can still get the hander to use the input stream to get the binary data out. However this approach makes the client depends on or be awared of the SOAP transport mechanism, which is not necessary...

Thanks.

Sunny *


On 7/5/06, Ivan Vasquez <[EMAIL PROTECTED]> wrote:

Thilina,

 

In line with your comments, the .Net service seems to have a threshold. For very small files (<700 bytes) it puts its base64 representation inside the soap envelope. For larger files I get several MIME sections as expected.

 

In Axis2/Axiom, is there a way to tell whether an MTOM attachment is present?

 

Thank you!

Ivan.

 


From: Thilina Gunarathne [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, July 05, 2006 1:43 PM
To: axis-user@ws.apache.org; commons-dev@ws.apache.org
Subject: [Axiom]Re: Axis2: "ContentID is null" using MTOM

 

Receiving binary can happen as either MTOM attachments or as Base64 encoded text. In the case of Base64 user has to explicitly specify that the content is binary, before calling getDataHandler(), getInputStream()....

 

As you can see in this message no MTOM attachments are present in the response, eventhough a MIME envelope is used. Binary file is in lined using base64 encoding.

         <fileData>TmFocmdpcw==</fileData>
 

You need to add the following before calling for getDataHandler.

             binaryNode.setOptimize(true);

 

Even though it works, IMHO above method is not the clean way to do this.. Because of that I'm going to introduce the setBinary(boolean value) method to OMText.. You will be able to get that method in SVN head in couple of hours. 

 

~Thilina
    

On 7/5/06, Ivan Vasquez < [EMAIL PROTECTED]> wrote:

Hi,

I'm using Axis2 to call a .Net service which returns a binary file. I've
read the documentation and followed the examples, and both parties are
using MTOM. But when my code runs:

OMElement elem = (OMElement)it.next();
...
OMText binaryNode = (OMText)elem.getFirstOMChild();
DataHandler actualDH = (DataHandler)binaryNode.getDataHandler();

The last instruction causes:

java.lang.RuntimeException: ContentID is null
       at
org.apache.axiom.om.impl.llom.OMTextImpl.getDataHandler(OMTextImpl.java:
339)
       at edu.uga.cviog.itos.ws.Client.foo (Client.java:87)
       at edu.uga.cviog.itos.ws.Client.main(Client.java:36)

>From what I see, the response message *does* have a "content-id" field
(below). Could you help me determine what's wrong? Here are the
exchanged messages:

AXIS2 Request (synchronous):

POST /Interop/BinaryDataMTOMService.asmx HTTP/1.1
User-Agent: Axis/2.0
Host: 127.0.0.1:8888
Transfer-Encoding: chunked
Content-Type: multipart/related;
boundary=MIMEBoundaryurn_uuid_D2233EEE05CE572BC211521075222491;
type="application/xop+xml";
start="< 0.urn:uuid:[EMAIL PROTECTED]>";
start-info="application/soap+xml";
charset=UTF-8;action="" href="http://stockservice.contoso.com/wse/samples/2005/1" target="_blank" > http://stockservice.contoso.com/wse/samples/2005/1
0/GetFile";

1d1
--MIMEBoundaryurn_uuid_D2233EEE05CE572BC211521075222491
content-type:application/xop+xml; charset=UTF-8;
type="application/soap+xml";
content-transfer-encoding:binary
content-id:<0.urn:uuid:[EMAIL PROTECTED] >
<?xml version='1.0' encoding='UTF-8'?>
        <soapenv:Envelope
xmlns:soapenv=" http://www.w3.org/2003/05/soap-envelope">
           <soapenv:Header />
           <soapenv:Body />
        </soapenv:Envelope>
--MIMEBoundaryurn_uuid_D2233EEE05CE572BC211521075222491--
0

.NET Response:

HTTP/1.1 100 Continue
Server: Microsoft-IIS/5.1
Date: Wed, 05 Jul 2006 13:52:02 GMT
X-Powered-By: ASP.NET

HTTP/1.1 200 OK
Server: Microsoft-IIS/5.1
Date: Wed, 05 Jul 2006 13:52:02 GMT
X-Powered-By: ASP.NET
X-AspNet-Version: 2.0.50727
Cache-Control: private, max-age=0
Content-Type: multipart/related; type="application/xop+xml";
boundary=--MIMEBoundary632876899223120893;
start="< [EMAIL PROTECTED] >";
start-info="application/soap+xml; charset=utf-8"
Content-Length: 1569

----MIMEBoundary632876899223120893
content-id: < [EMAIL PROTECTED] >
content-type: application/xop+xml; charset=utf-8;
type="application/soap+xml; charset=utf-8"
content-transfer-encoding: binary

<soap:Envelope xmlns:xop=" http://www.w3.org/2004/08/xop/include"
xmlns:soap=" http://www.w3.org/2003/05/soap-envelope"
xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance "
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:wsa=" http://schemas.xmlsoap.org/ws/2004/08/addressing"
xmlns:wsse=" http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wsse
curity-secext-1.0.xsd "
xmlns:wsu=" http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssec
urity-utility-1.0.xsd">
        <env:Header
xmlns:env=" http://www.w3.org/2003/05/soap-envelope">

<wsa:Action> http://stockservice.contoso.com/wse/samples/2005/10/GetFileR
esponse</wsa:Action>

<wsa:MessageID>urn:uuid:d4be97db-bdaa-428a-87cd-554aa2192a75</wsa:Messag
eID>

<wsa:RelatesTo>urn:uuid:850f1505-4dcb-475a-93b7-8bc5e274cea5</wsa:Relate
sTo>

<wsa:To>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous <
/wsa:To>
           <wsse:Security>
              <wsu:Timestamp
wsu:Id="Timestamp-39117870-658a-4e5a-b3aa-d149240a1cbb">
                 <wsu:Created>2006-07-05T14:04:45Z</wsu:Created>
                 <wsu:Expires>2006-07-05T14:09:45Z</wsu:Expires>
              </wsu:Timestamp>
           </wsse:Security>
        </env:Header>
        <soap:Body>
           <GetFileResponse
xmlns=" http://stockservice.contoso.com/wse/samples/2005/10 ">
              <getFileResponse>
                 <fileName>hola.txt</fileName>
                 <fileData>TmFocmdpcw==</fileData>
              </getFileResponse>
           </GetFileResponse>
        </soap:Body>
     </soap:Envelope>
----MIMEBoundary632876899223120893--


Thanks in advance,
Ivan

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




--
"May the SourcE be with u"            
http://people.apache.org/~thilina/
http://thilinag.blogspot.com/                 http://www.bloglines.com/blog/Thilina               


Reply via email to