Search in sources :

Example 21 with ResponseProcessingException

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

the class AuthorizationGrantNegativeTest method testRefreshWithBadToken.

@org.junit.Test
public void testRefreshWithBadToken() throws Exception {
    URL busFile = AuthorizationGrantTest.class.getResource("client.xml");
    String address = "https://localhost:" + PORT + "/services/";
    WebClient client = WebClient.create(address, OAuth2TestUtils.setupProviders(), "alice", "security", busFile.toString());
    // Save the Cookie for the second request...
    WebClient.getConfig(client).getRequestContext().put(org.apache.cxf.message.Message.MAINTAIN_SESSION, Boolean.TRUE);
    // Get Authorization Code
    String code = OAuth2TestUtils.getAuthorizationCode(client, "read_balance");
    assertNotNull(code);
    // Now get the access token
    client = WebClient.create(address, OAuth2TestUtils.setupProviders(), "consumer-id", "this-is-a-secret", busFile.toString());
    // Save the Cookie for the second request...
    WebClient.getConfig(client).getRequestContext().put(org.apache.cxf.message.Message.MAINTAIN_SESSION, Boolean.TRUE);
    ClientAccessToken accessToken = OAuth2TestUtils.getAccessTokenWithAuthorizationCode(client, code);
    assertNotNull(accessToken.getTokenKey());
    assertNotNull(accessToken.getRefreshToken());
    // Refresh the access token - using a bad token
    client.type("application/x-www-form-urlencoded").accept("application/json");
    Form form = new Form();
    form.param("grant_type", "refresh_token");
    form.param("client_id", "consumer-id");
    form.param("scope", "read_balance");
    Response response = client.post(form);
    // No refresh token
    try {
        response = client.post(form);
        response.readEntity(ClientAccessToken.class);
        fail("Failure expected on no refresh token");
    } catch (ResponseProcessingException ex) {
    // expected
    }
    // Now specify a bad refresh token
    form.param("refresh_token", "12345");
    try {
        response = client.post(form);
        response.readEntity(ClientAccessToken.class);
        fail("Failure expected on a bad refresh token");
    } catch (ResponseProcessingException ex) {
    // expected
    }
}
Also used : Response(javax.ws.rs.core.Response) Form(javax.ws.rs.core.Form) ClientAccessToken(org.apache.cxf.rs.security.oauth2.common.ClientAccessToken) ResponseProcessingException(javax.ws.rs.client.ResponseProcessingException) WebClient(org.apache.cxf.jaxrs.client.WebClient) URL(java.net.URL)

Example 22 with ResponseProcessingException

use of javax.ws.rs.client.ResponseProcessingException in project docker-client by spotify.

the class DefaultDockerClient method propagate.

private RuntimeException propagate(final String method, final WebTarget resource, final Exception ex) throws DockerException, InterruptedException {
    Throwable cause = ex.getCause();
    // So we unpack it here.
    if (ex instanceof MultiException) {
        cause = cause.getCause();
    }
    Response response = null;
    if (cause instanceof ResponseProcessingException) {
        response = ((ResponseProcessingException) cause).getResponse();
    } else if (cause instanceof WebApplicationException) {
        response = ((WebApplicationException) cause).getResponse();
    } else if ((cause instanceof ProcessingException) && (cause.getCause() != null)) {
        // For a ProcessingException, The exception message or nested Throwable cause SHOULD contain
        // additional information about the reason of the processing failure.
        cause = cause.getCause();
    }
    if (response != null) {
        throw new DockerRequestException(method, resource.getUri(), response.getStatus(), message(response), cause);
    } else if ((cause instanceof SocketTimeoutException) || (cause instanceof ConnectTimeoutException)) {
        throw new DockerTimeoutException(method, resource.getUri(), ex);
    } else if ((cause instanceof InterruptedIOException) || (cause instanceof InterruptedException)) {
        throw new InterruptedException("Interrupted: " + method + " " + resource);
    } else {
        throw new DockerException(ex);
    }
}
Also used : DockerException(com.spotify.docker.client.exceptions.DockerException) InterruptedIOException(java.io.InterruptedIOException) WebApplicationException(javax.ws.rs.WebApplicationException) DockerRequestException(com.spotify.docker.client.exceptions.DockerRequestException) DockerTimeoutException(com.spotify.docker.client.exceptions.DockerTimeoutException) ConfigCreateResponse(com.spotify.docker.client.messages.swarm.ConfigCreateResponse) Response(javax.ws.rs.core.Response) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) SecretCreateResponse(com.spotify.docker.client.messages.swarm.SecretCreateResponse) ServiceCreateResponse(com.spotify.docker.client.messages.ServiceCreateResponse) SocketTimeoutException(java.net.SocketTimeoutException) ResponseProcessingException(javax.ws.rs.client.ResponseProcessingException) MultiException(org.glassfish.hk2.api.MultiException) ProcessingException(javax.ws.rs.ProcessingException) ResponseProcessingException(javax.ws.rs.client.ResponseProcessingException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ConnectTimeoutException(org.apache.http.conn.ConnectTimeoutException)

Example 23 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 24 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 25 with ResponseProcessingException

use of javax.ws.rs.client.ResponseProcessingException in project verify-hub by alphagov.

the class SoapRequestClient method makePost.

/**
 * Wrap the supplied element in a SOAP wrapper and post to the specified end-point
 *
 * @return Response from the remote server
 * @throws SOAPRequestError            if the remote server returns a non-200 status code
 * @throws ResponseProcessingException in case processing of a received HTTP response fails (e.g. in a filter
 *                                     or during conversion of the response entity data to an instance
 *                                     of a particular Java type).
 * @throws ProcessingException         in case the request processing or subsequent I/O operation fails.
 */
protected SoapResponse makePost(URI uri, Element requestElement) throws SOAPRequestError {
    LOG.info(format("Making SOAP request to: {0}", uri));
    Document requestDocument = soapMessageManager.wrapWithSoapEnvelope(requestElement);
    WebTarget target = client.target(uri);
    final Invocation.Builder request = target.request();
    final Response response = request.post(Entity.entity(requestDocument, MediaType.TEXT_XML_TYPE));
    try {
        if (response.getStatus() != 200) {
            LOG.warn(format("Unexpected status code ({0}) when contacting ({1}))", response.getStatus(), uri));
            // let the calling code handle this issue appropriately
            throw new SOAPRequestError(response);
        } else {
            try {
                return giveMeMySoap(response);
            } catch (BadRequestException e) {
                LOG.warn(format("Couldn't parse SOAP response when contacting ({0}))", uri), e);
                throw new SOAPRequestError(response, e);
            }
        }
    } finally {
        // (e.g. the response body is never read from).
        try {
            response.close();
        } catch (ProcessingException f) {
            LOG.warn("Problem closing Jersey connection.", f);
        }
    }
}
Also used : SoapResponse(uk.gov.ida.hub.samlsoapproxy.soap.SoapResponse) Response(javax.ws.rs.core.Response) Invocation(javax.ws.rs.client.Invocation) BadRequestException(javax.ws.rs.BadRequestException) WebTarget(javax.ws.rs.client.WebTarget) Document(org.w3c.dom.Document) ProcessingException(javax.ws.rs.ProcessingException) ResponseProcessingException(javax.ws.rs.client.ResponseProcessingException)

Aggregations

ResponseProcessingException (javax.ws.rs.client.ResponseProcessingException)26 Response (javax.ws.rs.core.Response)16 ProcessingException (javax.ws.rs.ProcessingException)10 WebClient (org.apache.cxf.jaxrs.client.WebClient)9 URL (java.net.URL)8 WebTarget (javax.ws.rs.client.WebTarget)8 Test (org.junit.Test)8 Form (javax.ws.rs.core.Form)7 IOException (java.io.IOException)6 InputStream (java.io.InputStream)6 NoContentException (javax.ws.rs.core.NoContentException)6 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ReaderInputStream (org.apache.cxf.io.ReaderInputStream)4 ClientAccessToken (org.apache.cxf.rs.security.oauth2.common.ClientAccessToken)4 PushbackInputStream (java.io.PushbackInputStream)2 BadRequestException (javax.ws.rs.BadRequestException)2 WebApplicationException (javax.ws.rs.WebApplicationException)2 JwsHeaders (org.apache.cxf.rs.security.jose.jws.JwsHeaders)2 JwsJwtCompactProducer (org.apache.cxf.rs.security.jose.jws.JwsJwtCompactProducer)2 JwtClaims (org.apache.cxf.rs.security.jose.jwt.JwtClaims)2