Client AXIS2 Extract Attachment MTOM Base64Binary response

J

javalike

I'm trying to call a webservice with WS-Security authentication (PlainText).. The authentication is successful and apparently also the method call thatinterests me. The method returns a "multipart":

------=_Part_7_416131402.1368626616541
Content-Type: application/xop+xml; charset=utf-8; type="text/xml"
Content-Transfer-Encoding: 8bit
Content-ID: <soapPart>

<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"><env:Header/><env:Body><m:recDocbyKey xmlns:m="http://xmlns.mysoc.com"><m:return><java:Stato xmlns:java="java:com.mysoc.myserv.ws.beans">0</java:Stato><java:description xmlns:java="java:com.mysoc.myserv.ws.beans">Operazione eseguita</java:description><java:StreamMyData xmlns:java="java:com.mysoc.myserv.ws.beans"><Include xmlns="http://www.w3.org/2004/08/xop/include" href="cid:StreamMyData=e5bf0d23-2cb7-4a24-9a8a-43cbb34a974e@java:com..mysoc.myserv.ws.beans"/></java:StreamMyData><java:NameFile xmlns:java="java:com.mysoc.myserv.ws.beans">XYZ 0003339455 1.pdf</java:NameFile><java:ContentType xmlns:java="java:com.mysoc.myserv.ws.beans">application/pdf</java:ContentType></m:return></m:recDocbyKey></env:Body></env:Envelope>
------=_Part_7_416131402.1368626616541
Content-Type: application/octet-stream
Content-Transfer-Encoding: binary
Content-ID: <StreamMyData=e5bf0d23-2cb7-4a24-9a8a-43cbb34a974e@java:com.mysoc.myserv.ws.beans>
[... following binary part ...]
From my axis2 standalone clients can not access the part of the non-binary response .. but I have no idea how to be able to save the attachment in theresponse. I did several tests but failed to solve the problem.

I also tried to do so:

//out is object response

DataHandler handler = out.getStreamData();

File tempFile = File.createTempFile("tempfile", ".pdf");
FileOutputStream fos = new FileOutputStream(tempFile);
handler.writeTo(fos);
fos.flush();
fos.close();

This the exception result:

Exception in thread "main" org.apache.axiom.om.OMException: org.apache.axiom.ext.io.StreamCopyException: Error reading from source
at org.apache.axiom.attachments.PartContentFactory.createPartContent(PartContentFactory.java:153)
at org.apache.axiom.attachments.PartImpl.fetch(PartImpl.java:176)
at org.apache.axiom.attachments.PartImpl.getContent(PartImpl.java:149)
at org.apache.axiom.attachments.PartImpl.writeTo(PartImpl.java:238)
at org.apache.axiom.attachments.PartDataHandler.writeTo(PartDataHandler..java:65)
at TestMyAxis2.main(TestMyAxis2.java:176)
Caused by: org.apache.axiom.ext.io.StreamCopyException: Error reading from source
at org.apache.axiom.attachments.utils.BAAOutputStream.readFrom(BAAOutputStream.java:114)
at org.apache.axiom.attachments.impl.BufferUtils.inputStream2OutputStream(BufferUtils.java:76)
at org.apache.axiom.attachments.PartContentFactory.createPartContent(PartContentFactory.java:119)
... 5 more
Caused by: java.io.IOException: Attempted read on closed stream.
at org.apache.commons.httpclient.AutoCloseInputStream.isReadAllowed(AutoCloseInputStream.java:183)
at org.apache.commons.httpclient.AutoCloseInputStream.read(AutoCloseInputStream.java:107)
at java.io.FilterInputStream.read(Unknown Source)
at org.apache.axiom.om.util.DetachableInputStream.read(DetachableInputStream.java:147)
at org.apache.james.mime4j.io.BufferedLineReaderInputStream.fillBuffer(BufferedLineReaderInputStream.java:111)
at org.apache.james.mime4j.io.MimeBoundaryInputStream.fillBuffer(MimeBoundaryInputStream.java:223)
at org.apache.james.mime4j.io.MimeBoundaryInputStream.read(MimeBoundaryInputStream.java:157)
at org.apache.james.mime4j.io.BufferedLineReaderInputStream.fillBuffer(BufferedLineReaderInputStream.java:111)
at org.apache.james.mime4j.io.BufferedLineReaderInputStream.read(BufferedLineReaderInputStream.java:158)
at org.apache.james.mime4j.io.LineReaderInputStreamAdaptor.read(LineReaderInputStreamAdaptor.java:67)
at org.apache.axiom.attachments.utils.BAAOutputStream.readFrom(BAAOutputStream.java:112)
... 7 more


Can anyone help me ... I'm really desperate and frustrated.

Best Regards.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top