我正在使用 Jersey 2.0 来生成 REST 响应。我有以下方法可以响应 json 文本和八位字节流数据(PDF):
@GET
@Produces("application/json", "multipart/mixed; boundary=Test")
public Response getInfo((@Context HttpHeaders header, @Context HttpServletResponse respo, @Context HttpServletRequest req) {
// Code to Create JSON (variable json below)
// Code to Fetch PDF document (variable os is ByteArrayOutputStream)
// create bodyparts and return Response
MimeMultipart multiPart = new MimeMultipart();
MimeBodyPart mbp1 = new MimeBodyPart();
mbp1.setContent(os.toByteArray(), MediaType.APPLICATION_OCTET_STREAM);
MimeBodyPart mbp2 = new MimeBodyPart();
mbp2.setContent(json, MediaType.APPLICATION_JSON);
multiPart.addBodyPart(mbp2);
multiPart.addBodyPart(mbp1);
return Response.ok(multiPart, "multipart/mixed;boundary=Test").build();
}
发生的事情是我在没有指定“边界”的情况下得到以下输出。
------=_Part_0_195280885.1377005531310
{“状态”:“确定”,“索引”:1}
------=_Part_0_195280885.1377005531310
BLA bla bla bla .... PDF 版本 1.4 .... adsas da sf sgf sdg startxref 42417 %%EOF
------=_Part_0_195280885.1377005531310--
边界不应该是 --Test 吗?
我在这里错过了什么吗?