On Tue, Dec 1, 2009 at 7:01 PM, robert lazarski <robertlazar...@gmail.com> wrote: > On Tue, Dec 1, 2009 at 6:51 PM, vasu ts <vasu_...@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