我正在使用axis2來創建一個基本Web服務,該服務將獲取文件名作爲參數,並生成一個響應SOAP數據包,該數據包將隨SOAP一起附加文件。Axis2附件在響應中消失
這裏是我創建服務代碼(它的簡單和Axis2的示例代碼的啓發)
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;
}
現在的客戶端代碼的方式 -
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);
問題是,DataHandler的始終空值。儘管我認爲在服務器端,文件已經被讀取並且與SOAP數據包一起被附加。難道我做錯了什麼 ?
編輯: 我把<parameter name="enableSwA" locked="false">true</parameter>
放在axis2.xml文件中。