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 vasu ts <va...@hotmail.com> on 2009/12/01 22:51:25 UTC

Attempted read on closed stream / unable to read second attachement

Hi all,

 Binding: XML beans
 Axis2 : 1.4.1 and 1.5.1
 
  My web service returns two attachments when an operation is executed. I am able to read the first attachment but when I try to read the second attachment its throwing "Attempted read on closed stream" exception. I looked at wireshark's logs and I see all the binary data for the attachments is being transferred correctly from the web service server to the client

I looked through the user list archives and also tried several ways of reading the attachments but every time I see the same issue. Below is the sample code

            stub._getServiceClient().getOptions().setProperty( Constants.Configuration.ENABLE_MTOM, Constants.VALUE_TRUE );

            MessageContext messageContext = stub._getServiceClient().getLastOperationContext().getMessageContext( WSDL2Constants.MESSAGE_LABEL_IN );

 Attachments attachments = messageContext.getAttachmentMap();
            if ( attachments != null )
            {
                String[] contentIds = attachments.getAllContentIDs();
                for ( int i = 0; i < contentIds.length; i++ )
                {
                    DataHandler dataHandler = messageContext.getAttachment( contentIds[i] );
                    String filePath = m_temp + contentIds[i];
                    try
                    {
                        FileOutputStream fos = new FileOutputStream( filePath );
                        dataHandler.writeTo( fos );
                        fos.flush();
                        fos.close();
                    }
                    catch ( IOException ioe )
                    {
                        ioe.printStackTrace();
                    }
                }
            }

any ideas on how I can resolve this issues?
 		 	   		  
_________________________________________________________________
Windows Live Hotmail gives you a free,exclusive  gift.
http://www.microsoft.com/windows/windowslive/hotmail_bl1/hotmail_bl1.aspx?ocid=PID23879::T:WLMTAGL:ON:WL:en-ww:WM_IMHM_7:092009

Re: Attempted read on closed stream / unable to read second attachement

Posted by robert lazarski <ro...@gmail.com>.
On Tue, Dec 1, 2009 at 9:57 PM, vasu ts <va...@hotmail.com> wrote:
> My WSDL contains some <s:extension/> elements and these had some issues when
> I used the default "ADB" bindings.
>
> When I read the below statement from axis2 documentation I started using
> "XML beans" binding. If the below API doesn't work with XMLBeans and MTOM,
> can someone point me to the correct API?. When I started debugging this
> issue I see that second attachment stream was being read to a certain extent
> and then suddenly i see the exception.
>
> http://ws.apache.org/axis2/1_0/adb/adb-howto.html
>
>
> "ADB is meant to be a 'Simple' databinding framework and was not meant to
> compile all types of schemas. The following limitations are the most
> highlighted.
>
> Complex Extensions and Restrictions, Simple Extensions and Restrictions are
> not supported.
>
> "
>

The most recent docs are here:

http://ws.apache.org/axis2/1_5_1/adb/adb-howto.html

You could try jaxb. AFAIK its comes very close, if not completely, to
the 100% xml schema support that xmlbeans claims. You could then use
jaxws / jaxb I suppose to get your mtom support - jaxws supports mtom
but I'm not sure if that support is in axis2, though it probably is
since IBM uses axis2 in their products and they have jaxws docs for
mtom.

- R

RE: Attempted read on closed stream / unable to read second attachement

Posted by vasu ts <va...@hotmail.com>.
My WSDL contains some <s:extension/> elements and these had some issues when I used the default "ADB" bindings. 

When I read the below statement from axis2 documentation I started using  "XML beans" binding. If the below API doesn't work with XMLBeans and MTOM, can someone point me to the correct API?. When I started debugging this issue I see that second attachment stream was being read to a certain extent and then suddenly i see the exception.

http://ws.apache.org/axis2/1_0/adb/adb-howto.html


"ADB is meant to be a 'Simple' databinding framework and was not meant to
compile all types of schemas. The following limitations are the most
highlighted.
Complex Extensions and Restrictions, Simple Extensions and Restrictions
    are not supported."


> Date: Tue, 1 Dec 2009 19:05:12 -0300
> Subject: Re: Attempted read on closed stream / unable to read second 	attachement
> From: robertlazarski@gmail.com
> To: axis-user@ws.apache.org
> 
> On Tue, Dec 1, 2009 at 7:01 PM, robert lazarski
> <ro...@gmail.com> wrote:
> > On Tue, Dec 1, 2009 at 6:51 PM, vasu ts <va...@hotmail.com> wrote:
> >> Hi all,
> >>
> >>  Binding: XML beans
> >>  Axis2 : 1.4.1 and 1.5.1
> >>
> >>   My web service returns two attachments when an operation is executed. I am
> >> able to read the first attachment but when I try to read the second
> >> attachment its throwing "Attempted read on closed stream" exception. I
> >> looked at wireshark's logs and I see all the binary data for the attachments
> >> is being transferred correctly from the web service server to the client
> >>
> >> I looked through the user list archives and also tried several ways of
> >> reading the attachments but every time I see the same issue. Below is the
> >> sample code
> >>
> >>             stub._getServiceClient().getOptions().setProperty(
> >> Constants.Configuration.ENABLE_MTOM, Constants.VALUE_TRUE );
> >>
> >>             MessageContext messageContext =
> >> stub._getServiceClient().getLastOperationContext().getMessageContext(
> >> WSDL2Constants.MESSAGE_LABEL_IN );
> >>
> >>  Attachments attachments = messageContext.getAttachmentMap();
> >>             if ( attachments != null )
> >>             {
> >>                 String[] contentIds = attachments.getAllContentIDs();
> >>                 for ( int i = 0; i < contentIds.length; i++ )
> >>                 {
> >>                     DataHandler dataHandler = messageContext.getAttachment(
> >> contentIds[i] );
> >>                     String filePath = m_temp + contentIds[i];
> >>                     try
> >>                     {
> >>                         FileOutputStream fos = new FileOutputStream(
> >> filePath );
> >>                         dataHandler.writeTo( fos );
> >>                         fos.flush();
> >>                         fos.close();
> >>                     }
> >>                     catch ( IOException ioe )
> >>                     {
> >>                         ioe.printStackTrace();
> >>                     }
> >>                 }
> >>             }
> >>
> >> any ideas on how I can resolve this issues?
> >>
> >> _______________
> >
> > Just a quick thought that may be way off: Not sure if
> > messageContext.getAttachmentMap() works with xmlbeans. Might be ADB
> > only. In fact, looking at the docs and from previous experience, I'm
> > pretty sure SWA - you don't mention what you are using - is ADB only.
> > Not sure about the jaxws stuff.
> >
> > Anyways, if you control the client, I'd just send the attachment as a
> > String and accept the 30% bigger payload as unimportant if possible -
> > often its not worth worrying about. Or switch to ADB on the server
> > side. Or implement SWA or whatever for xmlbeans :-) .
> >
> > - R
> >
> 
> Ah, MTOM. I'm 99% sure its ADB only.
> 
> - R
 		 	   		  
_________________________________________________________________
Windows Live Hotmail gives you a free,exclusive  gift.
http://www.microsoft.com/windows/windowslive/hotmail_bl1/hotmail_bl1.aspx?ocid=PID23879::T:WLMTAGL:ON:WL:en-ww:WM_IMHM_7:092009

Re: Attempted read on closed stream / unable to read second attachement

Posted by robert lazarski <ro...@gmail.com>.
On Tue, Dec 1, 2009 at 7:01 PM, robert lazarski
<ro...@gmail.com> wrote:
> On Tue, Dec 1, 2009 at 6:51 PM, vasu ts <va...@hotmail.com> wrote:
>> Hi all,
>>
>>  Binding: XML beans
>>  Axis2 : 1.4.1 and 1.5.1
>>
>>   My web service returns two attachments when an operation is executed. I am
>> able to read the first attachment but when I try to read the second
>> attachment its throwing "Attempted read on closed stream" exception. I
>> looked at wireshark's logs and I see all the binary data for the attachments
>> is being transferred correctly from the web service server to the client
>>
>> I looked through the user list archives and also tried several ways of
>> reading the attachments but every time I see the same issue. Below is the
>> sample code
>>
>>             stub._getServiceClient().getOptions().setProperty(
>> Constants.Configuration.ENABLE_MTOM, Constants.VALUE_TRUE );
>>
>>             MessageContext messageContext =
>> stub._getServiceClient().getLastOperationContext().getMessageContext(
>> WSDL2Constants.MESSAGE_LABEL_IN );
>>
>>  Attachments attachments = messageContext.getAttachmentMap();
>>             if ( attachments != null )
>>             {
>>                 String[] contentIds = attachments.getAllContentIDs();
>>                 for ( int i = 0; i < contentIds.length; i++ )
>>                 {
>>                     DataHandler dataHandler = messageContext.getAttachment(
>> contentIds[i] );
>>                     String filePath = m_temp + contentIds[i];
>>                     try
>>                     {
>>                         FileOutputStream fos = new FileOutputStream(
>> filePath );
>>                         dataHandler.writeTo( fos );
>>                         fos.flush();
>>                         fos.close();
>>                     }
>>                     catch ( IOException ioe )
>>                     {
>>                         ioe.printStackTrace();
>>                     }
>>                 }
>>             }
>>
>> any ideas on how I can resolve this issues?
>>
>> _______________
>
> Just a quick thought that may be way off: Not sure if
> messageContext.getAttachmentMap() works with xmlbeans. Might be ADB
> only. In fact, looking at the docs and from previous experience, I'm
> pretty sure SWA - you don't mention what you are using - is ADB only.
> Not sure about the jaxws stuff.
>
> Anyways, if you control the client, I'd just send the attachment as a
> String and accept the 30% bigger payload as unimportant if possible -
> often its not worth worrying about. Or switch to ADB on the server
> side. Or implement SWA or whatever for xmlbeans :-) .
>
> - R
>

Ah, MTOM. I'm 99% sure its ADB only.

- R

Re: Attempted read on closed stream / unable to read second attachement

Posted by robert lazarski <ro...@gmail.com>.
On Tue, Dec 1, 2009 at 6:51 PM, vasu ts <va...@hotmail.com> wrote:
> Hi all,
>
>  Binding: XML beans
>  Axis2 : 1.4.1 and 1.5.1
>
>   My web service returns two attachments when an operation is executed. I am
> able to read the first attachment but when I try to read the second
> attachment its throwing "Attempted read on closed stream" exception. I
> looked at wireshark's logs and I see all the binary data for the attachments
> is being transferred correctly from the web service server to the client
>
> I looked through the user list archives and also tried several ways of
> reading the attachments but every time I see the same issue. Below is the
> sample code
>
>             stub._getServiceClient().getOptions().setProperty(
> Constants.Configuration.ENABLE_MTOM, Constants.VALUE_TRUE );
>
>             MessageContext messageContext =
> stub._getServiceClient().getLastOperationContext().getMessageContext(
> WSDL2Constants.MESSAGE_LABEL_IN );
>
>  Attachments attachments = messageContext.getAttachmentMap();
>             if ( attachments != null )
>             {
>                 String[] contentIds = attachments.getAllContentIDs();
>                 for ( int i = 0; i < contentIds.length; i++ )
>                 {
>                     DataHandler dataHandler = messageContext.getAttachment(
> contentIds[i] );
>                     String filePath = m_temp + contentIds[i];
>                     try
>                     {
>                         FileOutputStream fos = new FileOutputStream(
> filePath );
>                         dataHandler.writeTo( fos );
>                         fos.flush();
>                         fos.close();
>                     }
>                     catch ( IOException ioe )
>                     {
>                         ioe.printStackTrace();
>                     }
>                 }
>             }
>
> any ideas on how I can resolve this issues?
>
> _______________

Just a quick thought that may be way off: Not sure if
messageContext.getAttachmentMap() works with xmlbeans. Might be ADB
only. In fact, looking at the docs and from previous experience, I'm
pretty sure SWA - you don't mention what you are using - is ADB only.
Not sure about the jaxws stuff.

Anyways, if you control the client, I'd just send the attachment as a
String and accept the 30% bigger payload as unimportant if possible -
often its not worth worrying about. Or switch to ADB on the server
side. Or implement SWA or whatever for xmlbeans :-) .

- R