Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java RESTEasy成功返回PDF,失败返回XML_Java_Xml_Pdf_Resteasy - Fatal编程技术网

Java RESTEasy成功返回PDF,失败返回XML

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

我正在尝试使用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(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客户端插件来访问资源