【问题标题】:Jersey reading nested Multipart (multipart/mixed)泽西阅读嵌套多部分(多部分/混合)
【发布时间】: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


    【解决方案1】:

    发布后立即明确了答案。

    MultiPart nestedMultiPart = (MultiPart)bp.getEntity();
    List<BodyPart> msgParts = nestedMultiPart.getBodyParts();
    

    【讨论】:

      猜你喜欢
      • 2017-01-26
      • 2011-04-23
      • 2012-11-08
      • 1970-01-01
      • 2016-11-08
      • 1970-01-01
      • 2011-11-10
      • 2013-04-17
      • 1970-01-01
      相关资源
      最近更新 更多