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
}
}
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);
}
}
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;
}
}
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;
}
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);
}
}
}
Aggregations