CXF proxy how to handle certain response codes inside client
When I submit a request using a proxy client, if I get a specific response, I would like to be able to change the request and then send the same request again for all requests.
Usually I would do something like:
BookStore proxy = JAXRSClientFactory.create("http://books", BookStore.class);
try
{
proxy.getBook("someId");
}
catch(WebApplicationException ex)
{
Response r = ex.getResponse();
if (r.getStatusCode() == 404)
{
proxy.getBook("anotherId");
}
}
But in this case, there is a common thing I want to do for all requests: if I get a specific http code, change some header values ββand then try again (possibly with a limit on the number of attempts).
I haven't seen a way that cxf proxies explicitly support this, how can I implement it?
+3
source to share
1 answer
You need to write an interceptor to do this for every request. you will find sample code and documentation here http://cxf.apache.org/docs/jax-rs-filters.html
+1
source to share