Hi, Maria and Thilina,
     Many thanks for your reply. I have read your code, no difference
between yours and mine. Even if I changed the code as yours, I still can saw
that the binary data is sent by value not by reference. Here is my code:

   try {
                EndpointReference targetEPR = new EndpointReference(
               "http://localhost:8080/axis2/services/TestService";);
              ServiceClient service = new ServiceClient();
              Options options = new Options();
              options.setTo(targetEPR);
              options.setProperty(Constants.Configuration.ENABLE_MTOM,
                      Constants.VALUE_TRUE);
              service.setOptions(options);



              OMFactory fac = OMAbstractFactory.getOMFactory();
              OMNamespace omNs = fac.createOMNamespace(
                      "http://ws.apache.org/axis2/xsd";, "test1");
              OMElement payload = fac.createOMElement("transferMessage",
omNs);

              DataHandler dataHandler = new DataHandler(new
                      FileDataSource("d:\\test.txt"));
              OMText textData = fac.createOMText(dataHandler, true);
              textData.setOptimize(true);

              //the destination that the upload file should be saved in
              OMElement childNode = fac.createOMElement("name", omNs);
              childNode.setText("d:\\dest.txt");

               payload.addChild(childNode);

              //add tthe attachment
               childNode = fac.createOMElement("attachment", omNs);
               childNode.addChild(textData);
               payload.addChild(childNode);
               OMElement res = service.sendReceive(payload);

          } catch (AxisFault axisFault) {
              System.out.println("Caught axis exception");
              axisFault.printStackTrace();
          }

The file, test.txt, only contains simple text "hello".

The soap message is as follows:
<test1:transferMessage xmlns:test1="http://ws.apache.org/axis2/xsd";>
<test1:name>d:\dest.txt</test1:name><test1:attachment>aGVsbG8=</test1:attachment></test1:transferMessage>


On 2/9/07, Thilina Gunarathne <[EMAIL PROTECTED]> wrote:

Donald,
If possible please post the source of the place you are creating the
OMText.. In you case you can use a FileDataSource to create the data
handler and then you can create the OMText using that..

~Thilina

On 2/8/07, donald yang <[EMAIL PROTECTED]> wrote:
> Hi, Maria,
>
>     I am trying to send attachment to a web service using AXIS2-1.1.1.
But
> the binary data is sent by value not by reference. My client also
enabled
> MTOM and set optimization of OMText to TRUE. The only difference is that
you
> use createSoapMimeDataSource()( I don't know how you implement it), I
> directly pass a  FILE variable. Could you please give me one complete
> example how to sent attachment in client side? Sorry for interrupt you.
>
> best regards
> donald
>
>
> On 2/8/07, Maria McCafferty
> <[EMAIL PROTECTED] > wrote:
> > Hi,
> >
> > I am using Axis2 version 1.1.1. I have a client sending either and
MTOM or
> SwA message. Here is part of the
> > client code for sending an MTOM message:
> >
> >         ServiceClient service = new ServiceClient();
> >         Options options = new Options();
> >         options.setTo(targetEPR);
> >
> options.setProperty(Constants.Configuration.ENABLE_MTOM ,
> Constants.VALUE_TRUE);
> >
> >         service.setOptions(options);
> >
> >         OMElement payload = createPayload();
> >
> >         OMFactory fac = OMAbstractFactory.getOMFactory();
> >
> >         DataHandler dataHandler = new
> DataHandler(createSoapMimeDataSource());
> >
> >         OMText textData = fac.createOMText(dataHandler, true);
> >
> >         textData.setOptimize(true);
> >
> >         payload.addChild(textData);
> >
> >         OMElement res = service.sendReceive(payload);
> >
> > The SwA/MTOM request messages are fine and I am able to retrieve the
> attachments.
> > As you can see, I set the property ENABLE_MTOM to true. However I am
> having problems retrieving
> > the value from my server code. I am trying to access it by calling:
> >
> >
> MessageContext.getCurrentMessageContext().isDoingMTOM()
> >
> > I thought this would return true given that the option was set in the
> Client. I have also checked the
> > list of properties, and it is not included. I am getting the same
problem
> when sending an SwA request -
> > isDoingMTOM, isDoingSwA and isDoingREST are all set to false. I
realise I
> can check the for the xop header,
> > but felt that the above should work.
> >
> > Thanks,
> > Maria
> >
> >
> > POST /mm7 HTTP/1.1
> >
> > SOAPAction: "urn:anonOutInOp"
> > User-Agent: Axis2
> > Transfer-Encoding: chunked
> > Content-Type: multipart/related;
> boundary=MIMEBoundaryurn_uuid_29526B260178FA14181170945919864;
> type="application/xop+xml"; start="<
> 0.urn:uuid:[EMAIL PROTECTED]>";
> start-info="text/xml"; charset=UTF-8
> >
> > 2495
> > --MIMEBoundaryurn_uuid_29526B260178FA14181170945919864
> > content-type: application/xop+xml; charset=UTF-8; type="text/xml";
> > content-transfer-encoding: binary
> > content-id:
> <0.urn:uuid:[EMAIL PROTECTED]>
> >
> > <?xml version="1.0 " encoding="UTF-8"?><soapenv:Envelope
> xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/
"><soapenv:Header></soapenv:Header><soapenv:Body><SendMms><xop:Include
> href="cid:
> 1.urn:uuid:[EMAIL PROTECTED]"
> xmlns:xop="http://www.w3.org/2004/08/xop/include
> "></xop:Include>
> > <RequestElement>
> > .
> > .
> > .
> > </RequestElement></soapenv:Body></soapenv:Envelope>
> >
> > --MIMEBoundaryurn_uuid_29526B260178FA14181170945919864
> > content-type: multipart/related;
> > .boundary="----=_Part_0_23276589.1170945917770"
> > content-transfer-encoding: binary
> > content-id:
> <1.urn:uuid:[EMAIL PROTECTED] >
> >
> > ------=_Part_0_23276589.1170945917770
> > Content-Type: text/plain
> >
> > first attachment
> >
> > ------=_Part_0_23276589.1170945917770
> > Content-Type: image/jpeg
> > Content-Transfer-Encoding: base64
> > Content-Location: attach2.jpg
> > Content-Id: attach2.jpg
> >
> > <content>
> > ------=_Part_0_23276589.1170945917770--
> >
> >
> >
> > --MIMEBoundaryurn_uuid_29526B260178FA14181170945919864--
> >
> >
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
>
>


--
Thilina Gunarathne
WSO2, Inc.; http://www.wso2.com/
Home page: http://webservices.apache.org/~thilina/
Blog: http://thilinag.blogspot.com/

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


Reply via email to