2015-11-04 57 views
1

我有这个端点:消息错误添加到响应主体泽西

@POST 
    @Path("login") 
    @Consumes(MediaType.APPLICATION_JSON) 
    public Response doLogin(LoginCredentials loginCredentials) { 
     try { 
      usersService.validate(loginCredentials); 
      return Response.ok().build(); 
     } catch (InvalidCredentialsException e) { 
      return Response.status(Response.Status.UNAUTHORIZED).build(); 
     } catch (NotAuthorizedUserException e) { 
      return Response.status(Response.Status.UNAUTHORIZED).build(); 
     } 
    } 

UNAUTHORIZED案件,我想将消息发送给指定具体的错误。怎么可以做到这一点?

在情况下的反应是ok,我这样做:

回报Response.ok("Some message here").build();

回答

4

使用实体(Object数据)方法:

Response.status(Response.Status.UNAUTHORIZED).entity("Some message here").build(); 
+0

那么容易!谢谢。 –