java gsoap mtom_如何使用java解析XOP / MTOM SOAP响应?

These unit tests将向您展示如何使用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=\"\"; "

+ "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 atts = msg.getAttachments();

assertNotNull(atts);

Iterator 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("

// try streaming a character off the wire

assertTrue(attIs.read() == '/');

assertTrue(attIs.read() == '9');

}

在您的情况下,ct将来自响应的内容类型标头. “mimedata”将是回应的内容.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值