Search in sources :

Example 1 with MicroProfileClientProviderFactory

use of org.apache.cxf.microprofile.client.MicroProfileClientProviderFactory in project cxf by apache.

the class MicroProfileClientProxyImpl method checkResponse.

@Override
protected void checkResponse(Method m, Response r, Message inMessage) throws Throwable {
    MicroProfileClientProviderFactory factory = MicroProfileClientProviderFactory.getInstance(inMessage);
    List<ResponseExceptionMapper<?>> mappers = factory.createResponseExceptionMapper(inMessage, Throwable.class);
    for (ResponseExceptionMapper<?> mapper : mappers) {
        if (mapper.handles(r.getStatus(), r.getHeaders())) {
            Throwable t = mapper.toThrowable(r);
            if (t == null) {
                continue;
            }
            if (t instanceof RuntimeException) {
                throw t;
            } else if (CompletionStage.class.isAssignableFrom(m.getReturnType())) {
                throw new CompletionException(t);
            } else if (m.getExceptionTypes() != null) {
                // its a checked exception, make sure its declared
                for (Class<?> c : m.getExceptionTypes()) {
                    if (c.isAssignableFrom(t.getClass())) {
                        throw t;
                    }
                }
                if (LOG.isLoggable(Level.FINEST)) {
                    LOG.log(Level.FINEST, "ResponseExceptionMapper, " + mapper.getClass().getName() + ", handles " + "response, but client method does not declare it's Throwable type, " + t.getClass().getName());
                }
            }
        }
    }
}
Also used : ResponseExceptionMapper(org.eclipse.microprofile.rest.client.ext.ResponseExceptionMapper) CompletionException(java.util.concurrent.CompletionException) MicroProfileClientProviderFactory(org.apache.cxf.microprofile.client.MicroProfileClientProviderFactory) CompletionStage(java.util.concurrent.CompletionStage)

Aggregations

CompletionException (java.util.concurrent.CompletionException)1 CompletionStage (java.util.concurrent.CompletionStage)1 MicroProfileClientProviderFactory (org.apache.cxf.microprofile.client.MicroProfileClientProviderFactory)1 ResponseExceptionMapper (org.eclipse.microprofile.rest.client.ext.ResponseExceptionMapper)1