You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by Wolfram Kaiser <mr...@gmx.de> on 2006/05/23 09:33:50 UTC

[Axis2] Returning a MTOM message causes IOException (closed stream)

Hello,
because of the MTOM support I want to switch from Axis1 to Axis2.
Unfortunately, I encountered some problems - most notably the following
exception in the client when processing the response of my echoImage web
service:

org.apache.axiom.om.OMException: javax.mail.MessagingException: Error in
input stream;
  nested exception is:
    java.io.IOException: Attempted read on closed stream.
    at
org.apache.axiom.attachments.Attachments.getPart(Attachments.java:462)
    at
org.apache.axiom.attachments.Attachments.getNextPart(Attachments.java:359)
    at
org.apache.axiom.attachments.Attachments.getPart(Attachments.java:324)
   
at
org.apache.axiom.attachments.Attachments.getDataHandler(Attachments.java:274)
   
at
org.apache.axiom.om.impl.mtom.MTOMStAXSOAPModelBuilder.getDataHandler(MTOMStAXSOAPModelBuilder.java:151)
    at
org.apache.axiom.om.impl.llom.OMTextImpl.getDataHandler(OMTextImpl.java:341)
   
at
com.endress.infoserve.test.wk.axis2.ws2client.MyServiceTest.testechoImage(MyServiceTest.java:134)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:324)
    at junit.framework.TestCase.runTest(TestCase.java:154)
    at junit.framework.TestCase.runBare(TestCase.java:127)
    at junit.framework.TestResult$1.protect(TestResult.java:106)
    at junit.framework.TestResult.runProtected(TestResult.java:124)
    at junit.framework.TestResult.run(TestResult.java:109)
    at junit.framework.TestCase.run(TestCase.java:118)
    at junit.framework.TestSuite.runTest(TestSuite.java:208)
    at junit.framework.TestSuite.run(TestSuite.java:203)
   
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
   
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
   
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: javax.mail.MessagingException: Error in input stream;
  nested exception is:
    java.io.IOException: Attempted read on closed stream.
    at javax.mail.internet.InternetHeaders.load(InternetHeaders.java:142)
    at javax.mail.internet.InternetHeaders.<init>(InternetHeaders.java:93)
    at javax.mail.internet.MimeBodyPart.<init>(MimeBodyPart.java:124)
    at
org.apache.axiom.attachments.PartOnMemory.<init>(PartOnMemory.java:31)
    at
org.apache.axiom.attachments.Attachments.getPart(Attachments.java:451)
    ... 21 more

The echoImage web service (server side) constructs its response the
following way:

public OMElement echoImage(OMElement requestElement) {
...
OMText binaryNode = (OMText) imageElement.getFirstOMChild();
DataHandler actualDH = (DataHandler) binaryNode.getDataHandler();

OMFactory factory = OMAbstractFactory.getOMFactory();
OMNamespace ns = factory.createOMNamespace("", null);
responseElement = factory.createOMElement("return", ns);
            
ImageDataSource dataSource = new ImageDataSource("test33.jpg", actualImage);
DataHandler dataHandler = new DataHandler(dataSource);
        
OMText textData = factory.createOMText(dataHandler, true);
responseElement.addChild(textData);
return responseElement
}

The client attempts to extract the image and the exception is thrown during
accessing the data handler / responseElement.toString():

OMElement responseElement = stub.echoImage(requestElement);
//System.out.println("echoImage (response): " + responseElement);

assertNotNull(responseElement);
        
OMText binaryNode = (OMText) responseElement.getFirstOMChild();
DataHandler actualDH = (DataHandler) binaryNode.getDataHandler();
Image actualImage = new
ImageIO().loadImage(actualDH.getDataSource().getInputStream());

Curiously, sending the image works and the transfer for the request/response
in the TCP/IP monitor looks good to me as well. Here is the request content:
--MIMEBoundaryurn_uuid_19E43A1912FEAF555111483041641261
content-type: application/xop+xml; charset=UTF-8; type="text/xml";
content-transfer-encoding: binary
content-id: <0....@apache.org>

<?xml version='1.0' encoding='UTF-8'?><soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Header
/><soapenv:Body><echoImage><image><xop:Include
href="cid:1.urn:uuid:19E43A1912FEAF555111483041641413@apache.org"
xmlns:xop="http://www.w3.org/2004/08/xop/include"
/></image></echoImage></soapenv:Body></soapenv:Envelope>
--MIMEBoundaryurn_uuid_19E43A1912FEAF555111483041641261
content-type: image/jpeg
content-transfer-encoding: binary
content-id: <1....@apache.org>

ÿØÿà

And the response is:
--MIMEBoundaryurn_uuid_DBA4AD39B425454FA811483041664545
content-type:application/xop+xml; charset=UTF-8; type="text/xml";
content-transfer-encoding:binary
content-id:<0....@apache.org>

<?xml version='1.0' encoding='UTF-8'?><soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Header
/><soapenv:Body><return><xop:Include
href="cid:1.urn:uuid:DBA4AD39B425454FA811483041664547@apache.org"
xmlns:xop="http://www.w3.org/2004/08/xop/include"
/></return></soapenv:Body></soapenv:Envelope>
--MIMEBoundaryurn_uuid_DBA4AD39B425454FA811483041664545
content-id:<1....@apache.org>
content-type:image/jpeg
content-transfer-encoding:binary

ÿØÿà

The WSDL contains the following parts:

</wsdl:message>
<wsdl:message name="echoImageMessage">
  <wsdl:part element="ns2:echoImage" name="part1" />
</wsdl:message>
<wsdl:message name="echoImageResponseMessage">
  <wsdl:part element="ns2:echoImageResponse" name="part1" />
</wsdl:message>

<wsdl:portType name="MyServicePortType">
  <wsdl:operation name="echoImage">
    <wsdl:input message="ns:echoImageMessage" />
    <wsdl:output message="ns:echoImageResponseMessage" />
  </wsdl:operation>
</wsdl:portType>

<wsdl:binding type="ns:MyServicePortType" name="MyServiceSOAP11Binding">
  <soap:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http" />
  <wsdl:operation name="echoImage">
    <soap:operation style="document" soapAction="urn:echoImage" />
    <wsdl:input>
      <soap:body
namespace="http://MyService.axis2.wk.test.infoserve.endress.com"
use="literal" />
    </wsdl:input>
    <wsdl:output>
      <soap:body
namespace="http://MyService.axis2.wk.test.infoserve.endress.com"
use="literal" />
    </wsdl:output>
  </wsdl:operation>
</wsdl:binding>
<wsdl:binding type="ns:MyServicePortType" name="MyServiceSOAP12Binding">
  <soap12:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http" />
  <wsdl:operation name="echoImage">
    <soap12:operation style="document" soapAction="urn:echoImage" />
    <wsdl:input>
      <soap12:body
namespace="http://MyService.axis2.wk.test.infoserve.endress.com"
use="literal" />
    </wsdl:input>
    <wsdl:output>
      <soap12:body
namespace="http://MyService.axis2.wk.test.infoserve.endress.com"
use="literal" />
    </wsdl:output>
  </wsdl:operation>
</wsdl:binding>

I further noticed in the debugger that the responseElement.toString()
returns a different base64 representation of the image than on the client
side though the first 200 characters are the same.

Any ideas what I am doing wrong here and what I could do/try to solve the
problem? Does anyone have a working example which returns a binary from a
web service call?

Thank you,

Wolfram

-- 
Mobile Internet - E-Mail und Internet immer und überall!
GMX zum Mitnehmen: http://www.gmx.net/de/go/pocketweb

---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


Re: [Axis2] Returning a MTOM message causes IOException (closed stream)

Posted by Thilina Gunarathne <cs...@gmail.com>.
>/></image></echoImage></soapenv:Body></soapenv:Envelope>
>--MIMEBoundaryurn_uuid_19E43A1912FEAF555111483041641261
>content-type: image/jpeg
>content-transfer-encoding: binary
>content-id: <1....@apache.org>

>ÿØÿà

Didn't you had a trailing boundary after this in your message...? Also try
using FileDataSource instead of ImageDataSource...

~Thilina