dermoritz
dermoritz

Reputation: 13028

How to get checked exception from cxf's WebClient or how to handle Exceptions

I created a little client api to connect to a proprietary rest-like service. I use org.apache.cxf.jaxrs.client.WebClient for connection. On this client i call get() and post().

The problem is that if service is unavailable or to slow (i set timeout to 10s) i only get RuntimeException of type javax.ws.rs.ProcessingException. But i need a checked exception for all kinds of connection issues to let users of api react on them. How to do this?

Here is the code that configures the WebClient client:

private void configureClient() {
    ClientConfiguration config = WebClient.getConfig(client);
    HTTPConduit http = (HTTPConduit) config.getConduit();
    HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
    httpClientPolicy.setConnectionTimeout(TIMEOUT);
    httpClientPolicy.setAllowChunking(false);
    http.setClient(httpClientPolicy);
}

Upvotes: 0

Views: 3324

Answers (1)

Karthik Prasad
Karthik Prasad

Reputation: 10024

You can use javax.ws.rs.WebApplicationException, java.net.ConnectException to catch connection related exception(Though I don't remember the exact exception class) and javax.ws.rs.client.ClientException to capture other JAXRS exception such has 400 415 etc.

Upvotes: 1

Related Questions