我一直致力于创建一个基于SAAJ的客户端。一切似乎都很正常,直到我实现了将附件作为web服务请求的一部分发送的逻辑。
web服务操作很简单-它需要一个用于文件位置的string元素和一个用于文件内容的base64binary元素。
我已经使用SoapUI测试了ws操作,一切似乎都很正常。但是,当我从基于SAAJ的客户端发送文件附件时,web服务操作将只接收file-location元素的值。我在ws-server上编写了一个处理程序来拦截WS操作请求,以便查看附件是否到达web服务。正如预期的那样,附件运行良好,我可以在处理程序中使用SAAJ api访问其内容。
这让我想知道-当使用SAAJ发送附件并通过JAXB绑定接收附件时,是否存在兼容性问题?我是不是漏掉了什么?
谢谢你的帮助!
发布于 2010-10-01 20:38:38
您需要确保在解组器上注册了一个AttachmentUnmarshaller,以便在JAXB中接收附件。
import javax.activation.DataHandler;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;
import javax.xml.bind.attachment.AttachmentUnmarshaller;
public class Demo {
public static void main(String[] args) throws Exception {
JAXBContext jaxbContext = JAXBContext.newInstance(Demo.class);
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
unmarshaller.setAttachmentUnmarshaller(new MyAttachmentUnmarshaller());
}
private static class MyAttachmentUnmarshaller extends AttachmentUnmarshaller {
@Override
public DataHandler getAttachmentAsDataHandler(String cid) {
// TODO - Lookup MIME content by content-id, cid, and return as a DataHandler.
...
}
@Override
public byte[] getAttachmentAsByteArray(String cid) {
// TODO - Retrieve the attachment identified by content-id, cid, as a byte[]
...
}
}
}https://stackoverflow.com/questions/3839089
复制相似问题