Hi,

Thanks for the information, Thilina !

Donald, I have included a bit of code to read in a jpg and send in by reference. The createSoapMimeDataSource() in the previous code example creates a multipart/related (MimeMultipart) attachment and returns a javax.mail.MultipartDataSource. I created my own implementation of MultipartDataSource which simply took in a MimePart and returns the data as a ByteArrayInputStream.
Hope this helps.


      try {
           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(new FileDataSource("c:\\attach.jpg"));
           OMText textData = fac.createOMText(dataHandler, true);
            textData.setOptimize(true);

            payload.addChild(textData);
            OMElement res = service.sendReceive(payload);
} catch (AxisFault axisFault) {
           System.out.println("Caught axis exception");
           axisFault.printStackTrace();
       } catch (XMLStreamException e) {
           // TODO Auto-generated catch block
           e.printStackTrace();
       } catch (IOException e) {
           // TODO Auto-generated catch block
           e.printStackTrace();
       }
POST /mm7 HTTP/1.1
SOAPAction: "urn:anonOutInOp"
User-Agent: Axis2
Transfer-Encoding: chunked

Content-Type: multipart/related; boundary=MIMEBoundaryurn_uuid_BBEEC37C31C4F665351171030094842; type="application/xop+xml"; start="<0.urn:uuid:[EMAIL PROTECTED]>"; start-info="text/xml"; charset=UTF-8

245b
--MIMEBoundaryurn_uuid_BBEEC37C31C4F665351171030094842
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><Message><xop:Include href="cid:1.urn:uuid:[EMAIL PROTECTED]" xmlns:xop="http://www.w3.org/2004/08/xop/include";></xop:Include>
.
.
.
</Message></soapenv:Body></soapenv:Envelope>

--MIMEBoundaryurn_uuid_BBEEC37C31C4F665351171030094842
content-type: image/jpeg
content-transfer-encoding: binary
content-id: <1.urn:uuid:[EMAIL PROTECTED]>

<content>


Maria


donald yang 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] <mailto:[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]
    <mailto: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]
    <mailto: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]
    <mailto:1.urn:uuid:[EMAIL PROTECTED]>"
    xmlns:xop="http://www.w3.org/2004/08/xop/include
    <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]
    <mailto: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]
    <mailto:[EMAIL PROTECTED]>
    For additional commands, e-mail: [EMAIL PROTECTED]
    <mailto:[EMAIL PROTECTED]>




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

Reply via email to