如何使用Java解析XOPMTOM SOAP响应?

如何使用Java解析XOPMTOM SOAP响应?,第1张

如何使用Java解析XOP / MTOM SOAP响应

这些单元测试向您展示了如何使用CXF从MTOM消息中提取附件。我将内联其中一项测试,以防将来此链接不存在:

private MessageImpl msg;@Beforepublic void setUp() throws Exception {    msg = new MessageImpl();    Exchange exchange = new ExchangeImpl();    msg.setExchange(exchange);}@Testpublic void testDeserializerMtom() throws Exception {    InputStream is = getClass().getResourceAsStream("mimedata");    String ct = "multipart/related; type="application/xop+xml"; "     + "start="<soap.xml@xfire.prehaus.org>"; "     + "start-info="text/xml; charset=utf-8"; "     + "boundary="----=_Part_4_701508.1145579811786"";    msg.put(Message.CONTENT_TYPE, ct);    msg.setContent(InputStream.class, is);    AttachmentDeserializer deserializer = new AttachmentDeserializer(msg);    deserializer.initializeAttachments();    InputStream attBody = msg.getContent(InputStream.class);    assertTrue(attBody != is);    assertTrue(attBody instanceof DelegatingInputStream);    Collection<Attachment> atts = msg.getAttachments();    assertNotNull(atts);    Iterator<Attachment> itr = atts.iterator();    assertTrue(itr.hasNext());    Attachment a = itr.next();    assertNotNull(a);    InputStream attIs = a.getDataHandler().getInputStream();    // check the cached output stream    ByteArrayOutputStream out = new ByteArrayOutputStream();    IOUtils.copy(attBody, out);    assertTrue(out.toString().startsWith("<env:Envelope"));    // try streaming a character off the wire    assertTrue(attIs.read() == '/');    assertTrue(attIs.read() == '9');}

您的情况

ct
将来自响应的内容类型标头。该
"mimedata"
会是响应的内容。



欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5438939.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-11
下一篇 2022-12-11

发表评论

登录后才能评论

评论列表(0条)

保存