如何使用Java解析XOP / MTOM SOAP响应?
我只想知道,是否有任何简单的方法可以解析MTOM / XOP
SOAP响应。问题是我使用纯HTTP发送肥皂消息和javax.xml来解析响应。但是某些服务以mulipart /
related回应了我,它需要更复杂的逻辑来解析它(性能很重要)。因此,我想知道我是否可以以某种方式利用apache
cxf,apache公理或任何其他库来解析MTOM / XOP SOAP响应?
回答:
这些单元测试向您展示了如何使用CXF从MTOM消息中提取附件。我将内联其中一项测试,以防将来此链接不存在:
private MessageImpl msg;@Before
public void setUp() throws Exception {
msg = new MessageImpl();
Exchange exchange = new ExchangeImpl();
msg.setExchange(exchange);
}
@Test
public void testDeserializerMtom() throws Exception {
InputStream is = getClass().getResourceAsStream("mimedata");
String ct = "multipart/related; type=\"application/xop+xml\"; "
+ "start=\"<soap.xml@xfire.codehaus.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"
会是响应的内容。
以上是 如何使用Java解析XOP / MTOM SOAP响应? 的全部内容, 来源链接: utcz.com/qa/411193.html