Reputation: 1032
I have a jersey rest project and one newbie question. From server side:
throw new WebApplicationException(Response.status(Status.NOT_FOUND)
.entity("no access token found").build());
From 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 is
java.lang.ClassCastException: org.glassfish.jersey.client.HttpUrlConnector$1 cannot be cast to java.lang.String
Why I can't get error string on client side ? Is this correct (String) response.getEntity() for that ?
Upvotes: 4
Views: 4850
Reputation: 1032
You need to use response.readEntity(String.class)
instead of (String) response.getEntity()
Upvotes: 11