RESTEasy

From Null-pointer

Jump to: navigation, search

Release a connection

  • Register a client error interceptor [1].
RestClientProxyFactory() {
        ResteasyProviderFactory providerFactory = ResteasyProviderFactory.getInstance();
        providerFactory.addClientErrorInterceptor(new RestClientErrorInterceptor());
        RegisterBuiltin.register(providerFactory);
    }
  • Release the connection. Other this will not get released on server error.
public class RestClientErrorInterceptor implements ClientErrorInterceptor {
    @Override
    public void handle(ClientResponse<?> clientResponse) throws RuntimeException {
        clientResponse.releaseConnection();
        throw new RuntimeException(String.format("Error response [%s].", clientResponse.getResponseStatus()));
    }
}


References

  1. "Client Error Handling" RESTEasy JAX-RS:RESTFul Web Services for Java:2.2.0.GA. Retrieved 15 Jun 2011.
Personal tools