Class exception in jersey design?

I have a knitwear project and one question with a beginner. From the server side:

throw new WebApplicationException(Response.status(Status.NOT_FOUND) .entity("no access token found").build()); 

On the client side

 else if (Status.fromStatusCode(response.getStatus()) == Status.NOT_FOUND || Status.fromStatusCode(response.getStatus()) == Status.GONE) { final VerifyTokenResponse verifyTokenResponse = new VerifyTokenResponse(); verifyTokenResponse.setError((String) response.getEntity()); return verifyTokenResponse; } 

Problem

 java.lang.ClassCastException: org.glassfish.jersey.client.HttpUrlConnector$1 cannot be cast to java.lang.String 

Why can't I get a client-side error string? Is this the correct (String) response.getEntity () for this?

+4
source share
1 answer

You need to use response.readEntity(String.class) instead of (String) response.getEntity()

+11
source

Source: https://habr.com/ru/post/1500474/


All Articles