Java RESTEasy成功返回PDF,失败返回XML
我正在尝试使用RESTEasy创建一个RESTful web服务。这是我的资源界面:Java RESTEasy成功返回PDF,失败返回XML,java,xml,pdf,resteasy,Java,Xml,Pdf,Resteasy,我正在尝试使用RESTEasy创建一个RESTful web服务。这是我的资源界面: @Path("/report/{bookId}") @GET @Produces({"application/pdf", "application/xml"}) public Response getReport(@PathParam("bookId")Long book); 在服务实现bean中: responseBuilder = Response.status(200).entity(byteAr
@Path("/report/{bookId}")
@GET
@Produces({"application/pdf", "application/xml"})
public Response getReport(@PathParam("bookId")Long book);
在服务实现bean中:
responseBuilder = Response.status(200).entity(byteArrayOutputStream.toByteArray()).type("application/pdf");
responseBuilder.header("Content-Disposition", "attachment; filename=\"Report.pdf\"");
} catch (Exception e) {
responseBuilder = Response.status(500).entity(new ErrorDTO("123",
"Could not get the report. Cause by " + e.getMessage()));
e.printStackTrace();
}
return responseBuilder.build();
但它不是这样工作的。如果返回实体是PDF,它总是尝试将该实体解析为XML
如果成功,我想返回PDF,如果失败,我想返回XML。
有什么想法吗?
提前感谢 您究竟是如何尝试访问此资源的。我无法重现您体验到的行为Gi peeskillet,我使用firefox和rest客户端插件来访问资源