Search in sources :

Example 31 with ResponseProcessingException

use of javax.ws.rs.client.ResponseProcessingException in project so by onap.

the class RestClientTest method retryOnChunkedNetworkIssue.

@Test
public void retryOnChunkedNetworkIssue() throws Exception {
    RestClient spy = buildSpy();
    doThrow(new ResponseProcessingException(null, "something something", new SSLException("wow"))).when(spy).buildRequest(any(String.class), ArgumentMatchers.isNull());
    try {
        spy.get();
    } catch (Exception e) {
    // ignore this exception for this test
    }
    verify(spy, times(3)).buildRequest(any(String.class), ArgumentMatchers.isNull());
}
Also used : ResponseProcessingException(javax.ws.rs.client.ResponseProcessingException) SSLException(javax.net.ssl.SSLException) URISyntaxException(java.net.URISyntaxException) SocketTimeoutException(java.net.SocketTimeoutException) ExpectedException(org.junit.rules.ExpectedException) MalformedURLException(java.net.MalformedURLException) UriBuilderException(javax.ws.rs.core.UriBuilderException) NotFoundException(javax.ws.rs.NotFoundException) SSLException(javax.net.ssl.SSLException) ProcessingException(javax.ws.rs.ProcessingException) WebApplicationException(javax.ws.rs.WebApplicationException) ResponseProcessingException(javax.ws.rs.client.ResponseProcessingException) Test(org.junit.Test)

Example 32 with ResponseProcessingException

use of javax.ws.rs.client.ResponseProcessingException in project oci-java-sdk by oracle.

the class RestClient method convertToBmcException.

/**
 * Wraps a ProcessingException as a BmcException.
 *
 * @param target
 *            The target being called.
 * @param e
 *            The processing exception.
 * @return A new BmcException.
 */
private static BmcException convertToBmcException(WebTarget target, ProcessingException e, InvocationInformation info) {
    if (e instanceof ResponseProcessingException) {
        final ResponseProcessingException responseProcessingException = (ResponseProcessingException) e;
        final Response response = responseProcessingException.getResponse();
        if (response != null) {
            final String statusMessage = response.getStatusInfo() != null ? response.getStatusInfo().getReasonPhrase() : "";
            return new BmcException(response.getStatus(), statusMessage, e.getMessage(), info.getRequestId(), e);
        }
    }
    Throwable t = Throwables.getRootCause(e);
    if (t instanceof InterruptedIOException) {
        return new BmcException(true, "Timed out while communicating to: " + getUriSafe(target), e, info.getRequestId());
    }
    return new BmcException(false, "Processing exception while communicating to: " + getUriSafe(target), e, info.getRequestId());
}
Also used : Response(javax.ws.rs.core.Response) InterruptedIOException(java.io.InterruptedIOException) BmcException(com.oracle.bmc.model.BmcException) ResponseProcessingException(javax.ws.rs.client.ResponseProcessingException)

Example 33 with ResponseProcessingException

use of javax.ws.rs.client.ResponseProcessingException in project tomee by apache.

the class ResponseImpl method close.

@Override
public void close() throws ProcessingException {
    if (!entityClosed) {
        if (!entityBufferred && entity instanceof InputStream) {
            try {
                ((InputStream) entity).close();
            } catch (IOException ex) {
                throw new ResponseProcessingException(this, ex);
            }
        }
        entity = null;
        entityClosed = true;
    }
}
Also used : PushbackInputStream(java.io.PushbackInputStream) ReaderInputStream(org.apache.cxf.io.ReaderInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ResponseProcessingException(javax.ws.rs.client.ResponseProcessingException) IOException(java.io.IOException)

Example 34 with ResponseProcessingException

use of javax.ws.rs.client.ResponseProcessingException in project tomee by apache.

the class ResponseImpl method bufferEntity.

@Override
public boolean bufferEntity() throws ProcessingException {
    checkEntityIsClosed();
    if (!entityBufferred && entity instanceof InputStream) {
        try {
            InputStream oldEntity = (InputStream) entity;
            entity = IOUtils.loadIntoBAIS(oldEntity);
            oldEntity.close();
            entityBufferred = true;
        } catch (IOException ex) {
            throw new ResponseProcessingException(this, ex);
        }
    }
    return entityBufferred;
}
Also used : PushbackInputStream(java.io.PushbackInputStream) ReaderInputStream(org.apache.cxf.io.ReaderInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ResponseProcessingException(javax.ws.rs.client.ResponseProcessingException) IOException(java.io.IOException)

Example 35 with ResponseProcessingException

use of javax.ws.rs.client.ResponseProcessingException in project cxf by apache.

the class AbstractClient method checkClientException.

protected void checkClientException(Message outMessage, Exception ex) throws Exception {
    Throwable actualEx = ex instanceof Fault ? ((Fault) ex).getCause() : ex;
    Exchange exchange = outMessage.getExchange();
    Integer responseCode = getResponseCode(exchange);
    if (actualEx instanceof ResponseProcessingException) {
        throw (ResponseProcessingException) actualEx;
    } else if (responseCode == null || responseCode < 300 && !(actualEx instanceof IOException) || actualEx instanceof IOException && exchange.get("client.redirect.exception") != null) {
        if (actualEx instanceof ProcessingException) {
            throw (RuntimeException) actualEx;
        } else if (actualEx != null) {
            Object useProcExProp = exchange.get("wrap.in.processing.exception");
            if (actualEx instanceof RuntimeException && useProcExProp != null && PropertyUtils.isFalse(useProcExProp)) {
                throw (Exception) actualEx;
            }
            throw new ProcessingException(actualEx);
        } else if (!exchange.isOneWay() || cfg.isResponseExpectedForOneway()) {
            waitForResponseCode(exchange);
        }
    }
}
Also used : Exchange(org.apache.cxf.message.Exchange) Fault(org.apache.cxf.interceptor.Fault) ResponseProcessingException(javax.ws.rs.client.ResponseProcessingException) IOException(java.io.IOException) ProcessingException(javax.ws.rs.ProcessingException) WebApplicationException(javax.ws.rs.WebApplicationException) ResponseProcessingException(javax.ws.rs.client.ResponseProcessingException) IOException(java.io.IOException) ProcessingException(javax.ws.rs.ProcessingException) ResponseProcessingException(javax.ws.rs.client.ResponseProcessingException)

Aggregations

ResponseProcessingException (javax.ws.rs.client.ResponseProcessingException)60 Response (javax.ws.rs.core.Response)38 Test (org.junit.Test)29 ProcessingException (javax.ws.rs.ProcessingException)19 WebClient (org.apache.cxf.jaxrs.client.WebClient)16 WebTarget (javax.ws.rs.client.WebTarget)15 URL (java.net.URL)14 Form (javax.ws.rs.core.Form)13 NoContentException (javax.ws.rs.core.NoContentException)12 IOException (java.io.IOException)8 ExecutionException (java.util.concurrent.ExecutionException)8 InputStream (java.io.InputStream)5 WebApplicationException (javax.ws.rs.WebApplicationException)5 ClientAccessToken (org.apache.cxf.rs.security.oauth2.common.ClientAccessToken)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 PushbackInputStream (java.io.PushbackInputStream)4 NotFoundException (javax.ws.rs.NotFoundException)4 ReaderInputStream (org.apache.cxf.io.ReaderInputStream)4 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 InterruptedIOException (java.io.InterruptedIOException)2