0
        @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 is described as none-detectable exception, and should return 403. However, the console output does show the trace of exception (I think this means it is detectable), and the client receives 200 as code. It is also mentioned in answer "should not return entity". It is impossible for a jersey just return 403 but not a bean when nothing goes wrong. I cannot use glassfish jersey. jdk 1.7 thanks.

<!-- 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>
Community
  • 1
  • 1
Tiina
  • 4,285
  • 7
  • 44
  • 73
  • There's a concept of exceptionMappers that can map your response to wherever you want. Alternatively, return the response directly and wrap your entity in it: Response.status(MY_STATUS).entity(MY_ENTITY).build() – pandaadb Oct 03 '16 at 09:14
  • @pandaadb I have tried, but nothing changes. WebApplicationException still causes stack printed, and the response status code is still 200. – Tiina Oct 09 '16 at 04:44
  • @pandaadb finally found the bug in code :)). At the corner there is a catch(Exception e) – Tiina Oct 09 '16 at 08:22

0 Answers0