Hi Thilina,

Thanks for such a detailed response.

Yes I got the sample in 
http://thilinag.blogspot.com/2008/04/download-file-from-axis2-web-service.html 
working and was able to retrieve the content on the server side. I used MTOM to 
get the contents of attachment from client to server. There was only one file 
in this case and also I was using wsdl generated client. Rather now I would 
like to use my own client by using ServiceClient /OperationClient to get the 
contents of the multiple attachments to the server side. The thing is I am 
using a service that is prewritten and I am not using the wsdl to generate 
either the client or the service.

My service goes something like this, and I am using MTOM

String MyServiceMethod(String s1, String s2, String s3), where String s1,s2 and 
s3 - neither has got anything to do with the attachments. I have to use 
datahandlers on the client side to send the attachment to the service. 
Something like messageContext.addAttachment(datahandler[i]) where 'i' 
represents the ith attachment.

Now on the service side when I do

MessageContext msgContext = MessageContext.getCurrentMessageContext()

msgContext.getAttachmentMap and retrieve contextIDs on the AttachmentMap, I 
don't see the content of attachment I passed in when I write the dataHandler 
into a file. Even the contextType doesn't match. Rather it has the s3 that I 
sent in the parameter of the MyServiceMethod.

I will need to use tcpmon to see what exactly is happening to my messages.

Thanks for your help,

Asmita


________________________________
From: Thilina Gunarathne [mailto:[EMAIL PROTECTED]
Sent: Wednesday, September 24, 2008 12:57 AM
To: [email protected]
Subject: Re: Attachment SwA or MTOM

Hi,

I was successfully able to write an independent web service with a client to 
test where the attachments' file name is passed as parameter in the web service 
method.

Based on the lines of  
http://thilinag.blogspot.com/2008/04/download-file-from-axis2-web-service.html
Hope what u meant is that you were able to retrieve the content of the file in 
the server side.  Did u had a look at the MTOM sample that comes with Axis2? 
Axis2 MTOM sample uploads a file to a webservice
using a WSDL generated client and a service.

My requirement in real world is that my web service may or may not have the 
attachments [0 or many attachments].

And my web service method should be able to support all the scenarios

There are obvious two ways of doing it:



 *   Add the array of attachment filenames in the webservice method signature 
and send it using MTOM (based on the arcticle above )
 *   Or send the attachments internal to soap message using data handlers using 
SwA (Can we do the same thing and say enableMTOM=true?) based on this article
Attachments go externally when SwA is used. No..you can't mix SwA and MTOM..

Looks like you are somehow confused with the filenames vs file content... I 
would suggest you to use MTOM, unless there is a requirement to support legacy 
web service clients (eg: axis 1.x)..

First look at the MTOM sample and get it to working. Focus on getting the 
attachment content right.. When you can get the attachments to the service, 
getting file names is a piece of cake. Then you can modify the WSDL given with 
the sample to make it support an array of optional elements containing 
attachments..

Adding max/minoccurs to the following element and wraping it using another 
parent element will do the trick.
<xsd:element name="AttachmentRequest" type="tns:AttachmentType"  minOccurs="0" 
maxOccurs="unbounded" />


Then you can code generate to your modified WSDL to write your new service and 
client. You can use MTOM sample client & service as references. You may also 
look at http://ws.apache.org/axis2/1_4_1/mtom-guide.html to get an idea about 
Axis2 attachments..

Please use a http sniffer like tcpmon 
(ws.apache.org/commons/tcpmon<http://ws.apache.org/commons/tcpmon>) to trace 
your messages and to verify whether the attachments are there in the message.

thanks,
Thilina


 *

http://wso2.org/library/1148



When using method 1, how do we handle the array of Strings to send to the 
client, I want to use handwritten client so I am using

OMElement fileNamesArray = BeanUtil.getOMElement(new 
QName(omNs.getNamespaceURI(),"attchFileNames"), filenames, null, false, null);



But this does not get me the datasource for the file in the webservice.



When using method 2 and I access the datahandler from messageContext obtained 
using getCurrentMessageContext, my data handlers are empty.



So I am not able to achieve the solution to transfer the file from client to 
webservice by either of the ways.



Help is really appreciated as I am completely stuck!



Thanks in advance,

Asmita



--
Thilina Gunarathne - http://thilinag.blogspot.com

Reply via email to