HTTP响应不会生成定义的多部分边界

时间:2013-08-20 13:46:47

标签: java rest jersey jax-rs

我使用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

{ “状态”: “OK”, “索引”:1}

------ = _ Part_0_195280885.1377005531310

BLA bla bla bla .... PDF 1.4版.... adsas DA SF SGF SDG startxref 42417 %% EOF

------ = _ Part_0_195280885.1377005531310 -

不应该边界 - 测试?

我在这里错过了什么吗?

0 个答案:

没有答案