Axis2 attachments are vanishing in the response

Posted by Shamik on Stack Overflow See other posts from Stack Overflow or by Shamik
Published on 2010-03-10T23:18:39Z Indexed on 2010/03/11 5:33 UTC
Read the original article Hit count: 564

Filed under:
|
|

I am using axis2 to come up with a basic web service which will get the file name as parameter and produces a response SOAP packet which will have the file attached along with the SOAP.

Here is the way I am creating the service code (its simple and inspired by Axis2 sample code)

public String getFile(String name) throws IOException
{
MessageContext msgCtx = MessageContext.getCurrentMessageContext();
File file = new File (name);
System.out.println("File = " + name);
System.out.println("File exists = " + file.exists());
FileDataSource fileDataSource = new FileDataSource(file);
System.out.println("fileDataSource = " + fileDataSource);
DataHandler dataHandler = new DataHandler(fileDataSource);
System.out.println("DataHandler = " + dataHandler);
    String attachmentID = msgCtx.addAttachment(dataHandler);
    System.out.println("attachment ID = " + attachmentID);
    return attachmentID;
}

Now The client side code -

      MessageContext response = mepClient
            .getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
    SOAPBody body = response.getEnvelope().getBody();
    OMElement element = body.getFirstElement().getFirstChildWithName(
    new QName("http://service.soapwithattachments.sample","return"));
    String attachementId = element.getText();
    System.out.println("attachment id is " + attachementId);
    Attachments attachment = response.getAttachmentMap();
        DataHandler dataHandler = attachment.getDataHandler(attachementId);

Problem is that dataHandler is always null. Though I think at the server side, the file was read and attached along with the SOAP packet. Am I doing something wrong ?

EDIT : I have put <parameter name="enableSwA" locked="false">true</parameter> in the axis2.xml file.

© Stack Overflow or respective owner

Related posts about web-services

Related posts about axis2