I use axis2 to create a basic web service that will receive the file name as a parameter and give the response a SOAP package in which the file will be attached along with SOAP.
This is how I create utility code (its simple and inspired by the Axis2 code sample)
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 is
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);
The problem is that dataHandler is always null. Although I think that on the server side the file was read and attached along with the SOAP package. Am I doing something wrong?
EDIT: I placed <parameter name="enableSwA" locked="false">true</parameter> in the axis2.xml file.
source share