Search in sources :

Example 1 with BaseClientResponse

use of org.jboss.resteasy.client.core.BaseClientResponse in project quickstarts by jboss-switchyard.

the class MyClientErrorInterceptor method handle.

public void handle(ClientResponse response) throws RuntimeException {
    try {
        BaseClientResponse r = (BaseClientResponse) response;
        InputStream stream = r.getStreamFactory().getInputStream();
        if (stream != null) {
            stream.reset();
        }
        if ((response.getResponseStatus() != null) && (response.getResponseStatus().getStatusCode() == 404) && !(r.getException() instanceof ItemNotFoundException)) {
            throw new WebApplicationException(Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(new ApiError("Error at " + response.getHeaders().get("full-path"))).build());
        }
    } catch (IOException e) {
    //...
    }
}
Also used : BaseClientResponse(org.jboss.resteasy.client.core.BaseClientResponse) WebApplicationException(javax.ws.rs.WebApplicationException) InputStream(java.io.InputStream) IOException(java.io.IOException)

Example 2 with BaseClientResponse

use of org.jboss.resteasy.client.core.BaseClientResponse in project quickstarts by jboss-switchyard.

the class MyClientExecutionInterceptor method execute.

public ClientResponse execute(ClientExecutionContext ctx) throws Exception {
    ClientRequest request = ctx.getRequest();
    ClientResponse response = null;
    response = ctx.proceed();
    if ((response.getResponseStatus() != null) && (response.getResponseStatus().getStatusCode() == 404)) {
        BaseClientResponse r = (BaseClientResponse) response;
        MultivaluedMap<String, String> headers = r.getHeaders();
        headers.add("full-path", request.getUri());
        r.setHeaders(headers);
    }
    return response;
}
Also used : BaseClientResponse(org.jboss.resteasy.client.core.BaseClientResponse) ClientResponse(org.jboss.resteasy.client.ClientResponse) BaseClientResponse(org.jboss.resteasy.client.core.BaseClientResponse) ClientRequest(org.jboss.resteasy.client.ClientRequest)

Aggregations

BaseClientResponse (org.jboss.resteasy.client.core.BaseClientResponse)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 ClientRequest (org.jboss.resteasy.client.ClientRequest)1 ClientResponse (org.jboss.resteasy.client.ClientResponse)1