【发布时间】:2017-08-29 01:13:25
【问题描述】:
在泽西岛,我可以像这样发送多部分/混合数据:
MultiPart multipartWrapper = new MultiPart(MultiPartMediaTypes.MULTIPART_MIXED_TYPE);
for (IMessageContainer msgCont : input.getMessages()) {
MultiPart m = new MultiPart(MultiPartMediaTypes.MULTIPART_MIXED_TYPE)
.bodyPart(
new BodyPart(msgCont.getDescription(), MediaType.APPLICATION_JSON_TYPE))
.bodyPart(
new BodyPart(msgCont.getDetails(), MediaType.APPLICATION_OCTET_STREAM_TYPE));
//nest the new multipart into a bodypart within the root multipart
multipartWrapper.bodyPart(new BodyPart(m, MultiPartMediaTypes.MULTIPART_MIXED_TYPE));
}
}
现在可以作为响应的一部分通过网络发送这种封装的 multipart/mixed。在接收端我们可以做
MultiPart entity = response.readEntity(MultiPart.class);
List<BodyPart> bodyParts = entity.getBodyParts();
List<IMessageWrapper> rslt = new ArrayList<>();
for(BodyPart bp : bodyParts) {
//how do we get the wrapped Multipart here, so we can
//get into its BodyParts?
}
我觉得我错过了什么。我们如何才能到达包裹在 BodyPart 中的 Multipart?在检查 BodyPart 时,它只包含 org.jvnet.mimepull.MimePart。
【问题讨论】:
标签: java jersey-2.0 jersey-client