球衣读取嵌套多部分(多部分/混合) [英] Jersey reading nested Multipart (multipart/mixed)

查看:80
本文介绍了球衣读取嵌套多部分(多部分/混合)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在泽西岛,我可以像这样发送多部分/混合数据:

In Jersey I can send multipart/mixed data like this :

    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));
            }
        }

现在,可以将包裹的多部分/混合部分作为响应的一部分通过电线发送.在接收方,我们可以做到

This enveloping multipart/mixed can now be sent over the wire as part of a Response. On the receiving side we can do

    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.

I feel like I am missing something. How can we get to the Multipart wrapped inside the BodyPart? When examining the BodyPart, it just encloses org.jvnet.mimepull.MimePart.

推荐答案

发布答案后,答案很明确.

Immediately after posting the answer was clear.

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

这篇关于球衣读取嵌套多部分(多部分/混合)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆