Apache CXF如何添加SOAP附件(MTOM)

时间:2019-05-24 12:47:46

标签: java soap wsdl cxf soap-client

我正在尝试从Apache CXF客户端调用附件SOAP Web服务,但无法调用。

以下是我的示例

public class Test1 {

    public static void doInvoke() throws Exception {
        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
        Client client = dcf.createClient("http://localhost:6060/ForAttachments", classLoader);

        ClientImpl clientImpl = (ClientImpl) client;
        Endpoint endpoint = clientImpl.getEndpoint();
        endpoint.put("mtom-enabled", "true");
        BindingOperationInfo bindingOperationInfo = client.getEndpoint().getBinding().getBindingInfo()
                .getOperation(new QName(endpoint.getService().getName().getNamespaceURI(), "Attachments"));

        List<Attachment> attachments = new ArrayList<Attachment>();
        Map<String, List<String>> headers = new TreeMap<String, List<String>>(String.CASE_INSENSITIVE_ORDER);
        headers.put("Content-Type", Arrays.asList("application/pdf"));

        Attachment attach = AttachmentUtil
                .createAttachment(new FileDataSource(new File("D:\\images\\test.pdf")).getInputStream(), headers);
        attachments.add(attach);

        Object[] result = client.invoke(bindingOperationInfo, attachments);
    }
}

我已经在Fidler中捕获了请求

此处缺少二进制数据.........

Content-Length: 567
Content-Type: multipart/related;
type="application/xop+xml"; 
boundary="uuid:09b6bee3-59f3-4662-a3ac-5e0b01d2f76f";
start="<root.message@cxf.apache.org>"; start-info="text/xml"

请找到WSDL图像 enter image description here

请您帮我解决这个问题

0 个答案:

没有答案