如何要求太阳球衣返回200以外的http码

时间:2016-09-30 02:36:35

标签: java jersey

        @GET
        @Path("/rest/balancequery")
        @Produces(MediaType.APPLICATION_JSON)
        public XXXPojo balanceQuery(@Context UriInfo ui) {
            XXXPojo p = new XXXPojo();
            Boolean fail = this.checkAuthority(ui);
            if(fail) {
                 throw new WebApplicationException(Response.Status.FORBIDDEN);
            } 
            else {
                 p = getPojo();
            }
            return p
        }

WebAppliactionException被描述为不可检测的异常,并且应该返回403.但是,控制台输出确实显示异常的跟踪(我认为这意味着它是可检测的),并且客户端接收200作为代码。在answer中也提到“不应该返回实体”。如果没有任何问题,球衣不可能只返回403而不是豆子。我不能使用glassfish球衣。 jdk 1.7谢谢。

<!-- jersey -->
<dependency>
    <groupId>com.sun.jersey</groupId>
    <artifactId>jersey-server</artifactId>
    <version>1.19</version>
</dependency>
<dependency>
    <groupId>com.sun.jersey</groupId>
    <artifactId>jersey-json</artifactId>
    <version>1.19</version>
</dependency>
<dependency>
    <groupId>com.sun.jersey</groupId>
    <artifactId>jersey-client</artifactId>
    <version>1.19</version>
    <scope>test</scope>
</dependency>
<!-- Jetty -->
<dependency>
    <groupId>org.eclipse.jetty.aggregate</groupId>
    <artifactId>jetty-all-server</artifactId>
    <version>8.1.16.v20140903</version>
</dependency>

0 个答案:

没有答案