Hi All,


Ok I was successful in sending Attachment using MTOM from client to server. I 
needed to add OMElement in the my method signature. So the wsdl changes.

I have two things remaining to be resolved though:

1.Can I send in attachment(s) to webservice without change in the method 
signature and can I still access the attachments using the 
MessgeContext.getCurrentMessageContext().getAttachmentMap() ?? If so how do I 
do that?

myServiceMethod(String param0,String param1, String param2, OMElement 
attachment)

I want to use myServiceMethod(String param0,String param1,String param2) and 
still be able to send the attachments using MTOM - how is it possible?

2.Also another thing - I send in only one attachment to the webr service and I 
have three String parameters in the web service that I send in from my client, 
The last of the String parameters is an xml message and it shows up like an 
attachment in the AttachmentMap obtained from messageContext. the content type 
is obviously text/xml. But the only attachment I am sending is image. The 
Attachment Map has these two attachments where as I am expecting only one. 
Right now I am making it work by skipping the first in the AttachmentMap 
everytime. But how do I make sure I see only image in the attachmentMap?



This is how my client is sending the request to webservice

ServiceClient sc= new ServiceClient()

Options options = new Options();

options.set..... // I set ENABLE_MTOM in one of these.

sc.setOptions(options);

sc.sendRecieve(payload)



Where payload is created using Axiom.

method.addChild(param0);

method.addChild(param1);

method.addChild(param2);

method.addChild(attachment);



Where attachment is a OMElement created by adding OMText obtained from the 
datahandlers of the attachments.

Why does param2 show up as attachment in AttachmentMap of MessageContext.



Any help is appreciated.

Thanks a ton for looking into this in advance,

Asmita





 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 
<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 
<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) to trace 
your messages and to verify whether the attachments are there in the message.

thanks,
Thilina


        *

        http://wso2.org/library/1148 <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


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to