use of javax.ws.rs.client.ResponseProcessingException in project cxf by apache.
the class AuthorizationGrantNegativeTest method testRepeatAuthorizationCode.
// Send the authorization code twice to get an access token
@org.junit.Test
public void testRepeatAuthorizationCode() 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);
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);
client.type("application/x-www-form-urlencoded").accept("application/json");
client.path("token");
// First invocation
Form form = new Form();
form.param("grant_type", "authorization_code");
form.param("code", code);
form.param("client_id", "consumer-id");
Response response = client.post(form);
ClientAccessToken token = response.readEntity(ClientAccessToken.class);
assertNotNull(token.getTokenKey());
// Now try to get a second token
response = client.post(form);
try {
response.readEntity(ClientAccessToken.class);
fail("Failure expected on trying to get a second access token");
} catch (ResponseProcessingException ex) {
// expected
}
}
use of javax.ws.rs.client.ResponseProcessingException in project cxf by apache.
the class OIDCNegativeTest method testJWTRequestNonmatchingClientId.
@org.junit.Test
public void testJWTRequestNonmatchingClientId() throws Exception {
URL busFile = OIDCNegativeTest.class.getResource("client.xml");
String address = "https://localhost:" + PORT + "/unsignedjwtservices/";
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);
JwtClaims claims = new JwtClaims();
claims.setIssuer("consumer-id");
claims.setIssuedAt(Instant.now().getEpochSecond());
claims.setAudiences(Collections.singletonList("https://localhost:" + PORT + "/unsignedjwtservices/"));
claims.setProperty("client_id", "consumer-id2");
JwsHeaders headers = new JwsHeaders();
headers.setAlgorithm("none");
JwtToken token = new JwtToken(headers, claims);
JwsJwtCompactProducer jws = new JwsJwtCompactProducer(token);
String request = jws.getSignedEncodedJws();
AuthorizationCodeParameters parameters = new AuthorizationCodeParameters();
parameters.setConsumerId("consumer-id");
parameters.setScope("openid");
parameters.setResponseType("code");
parameters.setPath("authorize/");
parameters.setRequest(request);
// Get Authorization Code
try {
OAuth2TestUtils.getLocation(client, parameters);
fail("Failure expected on a non-matching client id");
} catch (ResponseProcessingException ex) {
// expected
}
}
use of javax.ws.rs.client.ResponseProcessingException in project cxf by apache.
the class OIDCNegativeTest method testJWTRequestNonmatchingResponseType.
@org.junit.Test
public void testJWTRequestNonmatchingResponseType() throws Exception {
URL busFile = OIDCNegativeTest.class.getResource("client.xml");
String address = "https://localhost:" + PORT + "/unsignedjwtservices/";
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);
JwtClaims claims = new JwtClaims();
claims.setIssuer("consumer-id");
claims.setIssuedAt(Instant.now().getEpochSecond());
claims.setAudiences(Collections.singletonList("https://localhost:" + PORT + "/unsignedjwtservices/"));
claims.setProperty("response_type", "token");
JwsHeaders headers = new JwsHeaders();
headers.setAlgorithm("none");
JwtToken token = new JwtToken(headers, claims);
JwsJwtCompactProducer jws = new JwsJwtCompactProducer(token);
String request = jws.getSignedEncodedJws();
AuthorizationCodeParameters parameters = new AuthorizationCodeParameters();
parameters.setConsumerId("consumer-id");
parameters.setScope("openid");
parameters.setResponseType("code");
parameters.setPath("authorize/");
parameters.setRequest(request);
// Get Authorization Code
try {
OAuth2TestUtils.getLocation(client, parameters);
fail("Failure expected on a non-matching response_type");
} catch (ResponseProcessingException ex) {
// expected
}
}
use of javax.ws.rs.client.ResponseProcessingException in project stdlib by petergeneric.
the class RemoteExceptionClientResponseFilter method filter.
@Override
public void filter(final ClientRequestContext requestContext, final ClientResponseContext responseContext) throws IOException {
final int code = responseContext.getStatus();
String operationId;
if (Tracing.isVerbose()) {
operationId = requestContext.getHeaderString(TracingConstants.HTTP_HEADER_CORRELATION_ID);
if (operationId != null)
Tracing.logOngoing(operationId, "HTTP:resp", () -> "" + code);
else
// can't find outgoing trace id
operationId = Tracing.log("HTTP:resp:unexpected", () -> "" + code);
} else {
operationId = null;
}
if (code >= 200 && code <= 299)
// Do not run if the return code is 2xx
return;
if (responseContext.getHeaders().containsKey(RestThrowableConstants.HEADER_RICH_EXCEPTION)) {
try {
final InputStream is = responseContext.getEntityStream();
RestFailure failure;
if (tryParseLegacyExceptionNamespace) {
// If parsing the legacy namespace fails, throw the original parse error back to the client
try {
// Mark the start of the stream so we can reset back to it if we need to process this as a legacy exception
is.mark(Integer.MAX_VALUE);
failure = parseResponse(is);
} catch (JAXBUnmarshalException e) {
log.trace("Error parsing rich exception response, will fall back on parsing it as a legacy exception XML", e);
try {
failure = parseLegacyResponse(is);
} catch (Throwable legacyFailure) {
log.trace("Error parsing rich exception response as legacy rich exception XML!", legacyFailure);
// throw the original exception
throw e;
}
}
} else {
failure = parseResponse(is);
}
if (Tracing.isVerbose() && failure != null && failure.exception != null) {
final ExceptionInfo ei = failure.exception;
Tracing.logOngoing(operationId, "HTTP:error", () -> ei.shortName + " " + ei.detail);
}
RestException exception = exceptionFactory.build(failure, responseContext);
// Try to shorten the stack trace
exception.fillInStackTrace();
throw exception;
} catch (ResponseProcessingException e) {
throw e;
} catch (Throwable e) {
throw new ResponseProcessingException(null, "Error mapping exception from thrown from " + requestContext.getUri() + " to exception!", e);
}
}
}
use of javax.ws.rs.client.ResponseProcessingException in project jersey by jersey.
the class EmptyEntityTest method testReceiveEmptyJAXBElement.
@Test
public void testReceiveEmptyJAXBElement() {
WebTarget target = target("empty/getempty");
final Response response = target.request("application/xml").get();
assertEquals(200, response.getStatus());
try {
response.readEntity(new GenericType<JAXBElement<String>>() {
});
fail("ProcessingException expected.");
} catch (ProcessingException ex) {
assertSame(NoContentException.class, ex.getCause().getClass());
}
try {
target.request("application/xml").get(new GenericType<JAXBElement<String>>() {
});
fail("ResponseProcessingException expected.");
} catch (ResponseProcessingException ex) {
assertSame(NoContentException.class, ex.getCause().getClass());
}
}
Aggregations