从 CXF 生成的存根中获取附件

发布于 2024-11-24 03:30:05 字数 158 浏览 1 评论 0原文

我们正在从 AXIS1 迁移到 CXF,并使用 CXF 提供的 wsdltojava ANT 实用程序生成存根。但是,我们无法从 Webservicecall 的响应中获取附件,因为这些附件没有直接嵌入到响应中。早期的实现是使用 AXIS api 的标准方法 getAttachments()。 请帮忙

We are migrating from AXIS1 to CXF and generating stub using the wsdltojava ANT utility provided by CXF. However we are unable to getattachments from a response of Webservicecall as these attachments are not directly embedded in the response. The earlier implementation was using the standard method getAttachments() of the AXIS api.
Please help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

尴尬癌患者 2024-12-01 03:30:05

现在可能已经找到答案了,但对于其他人来说,关键是服务代理可以转换为 javax.xml.ws.Binding,然后您可以获得 ResponseContext (地图)和附件通过 org.apache.cxf.message.Message.ATTACHMENTS 键:

import javax.activation.DataHandler;
import javax.xml.ws.BindingProvider;
import org.apache.cxf.message.Attachment;
import org.apache.cxf.message.Message;

import org.apache.commons.io.IOUtils;
...

Collection<Attachment> attachments = (Collection<Attachment>)
    ((BindingProvider)yourServiceProxy).getResponseContext()
        .get(Message.ATTACHMENTS);
for (Attachment attachment : attachments) {
    // ID is in attachment.getId();
    // Data is in attachment.getDataHandler();

    // Eg:
    DataHandler data = attachment.getDataHandler();
    InputStream is = data.getInputStream();
    File dataFile = new File(data.getName());
    System.out.println("Writing data to:\n\t" + 
        dataFile.toString());     
    FileOutputStream fos = new FileOutputStream(dataFile);
    IOUtils.copy(is, fos);
    fos.close();   
}

Probably found the answer by now, but for anyone else the key is the service proxy can be cast to a javax.xml.ws.Binding and then you can get the ResponseContext (a map) and attachments via the org.apache.cxf.message.Message.ATTACHMENTS key:

import javax.activation.DataHandler;
import javax.xml.ws.BindingProvider;
import org.apache.cxf.message.Attachment;
import org.apache.cxf.message.Message;

import org.apache.commons.io.IOUtils;
...

Collection<Attachment> attachments = (Collection<Attachment>)
    ((BindingProvider)yourServiceProxy).getResponseContext()
        .get(Message.ATTACHMENTS);
for (Attachment attachment : attachments) {
    // ID is in attachment.getId();
    // Data is in attachment.getDataHandler();

    // Eg:
    DataHandler data = attachment.getDataHandler();
    InputStream is = data.getInputStream();
    File dataFile = new File(data.getName());
    System.out.println("Writing data to:\n\t" + 
        dataFile.toString());     
    FileOutputStream fos = new FileOutputStream(dataFile);
    IOUtils.copy(is, fos);
    fos.close();   
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文