use of javax.ws.rs.client.ResponseProcessingException in project jersey by jersey.
the class EmptyEntityTest method testReceiveEmptyBoolean.
@Test
public void testReceiveEmptyBoolean() {
WebTarget target = target("empty/getempty");
final Response response = target.request("text/plain").get();
assertEquals(200, response.getStatus());
try {
response.readEntity(Boolean.class);
fail("ProcessingException expected.");
} catch (ProcessingException ex) {
assertSame(NoContentException.class, ex.getCause().getClass());
}
try {
target.request("text/plain").get(Boolean.class);
fail("ResponseProcessingException expected.");
} catch (ResponseProcessingException ex) {
assertSame(NoContentException.class, ex.getCause().getClass());
}
}
use of javax.ws.rs.client.ResponseProcessingException in project cxf by apache.
the class JAXRSAsyncClientTest method testGetBookResponseProcessingException.
@Test
public void testGetBookResponseProcessingException() throws Exception {
String address = "http://localhost:" + PORT + "/bookstore/books/123";
List<Object> providers = new ArrayList<>();
providers.add(new FaultyBookReader());
WebClient wc = WebClient.create(address, providers);
Future<Book> future = wc.async().get(Book.class);
try {
future.get();
fail("Exception expected");
} catch (ExecutionException ex) {
assertTrue(ex.getCause() instanceof ResponseProcessingException);
}
wc.close();
}
use of javax.ws.rs.client.ResponseProcessingException in project cxf by apache.
the class AuthorizationGrantNegativeTest method testUnknownGrantType.
@org.junit.Test
public void testUnknownGrantType() throws Exception {
URL busFile = AuthorizationGrantTest.class.getResource("client.xml");
String address = "https://localhost:" + PORT + "/services/";
WebClient client = WebClient.create(address, OAuth2TestUtils.setupProviders(), "consumer-id", "this-is-a-secret", busFile.toString());
// Get Access Token
client.type("application/x-www-form-urlencoded").accept("application/json");
client.path("token");
Form form = new Form();
// form.param("grant_type", "password");
form.param("username", "alice");
form.param("password", "security");
Response response = client.post(form);
// No grant_type
try {
response.readEntity(ClientAccessToken.class);
fail("Failure expected on no grant type");
} catch (ResponseProcessingException ex) {
// expected
}
// Unknown grant_type
form.param("grant_type", "unknown");
response = client.post(form);
try {
response.readEntity(ClientAccessToken.class);
fail("Failure expected on an unknown grant type");
} catch (ResponseProcessingException ex) {
// expected
}
}
use of javax.ws.rs.client.ResponseProcessingException in project cxf by apache.
the class AuthorizationGrantNegativeTest method testRepeatRefreshCall.
// Try to refresh the access token twice using the same refresh token
@org.junit.Test
public void testRepeatRefreshCall() 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
client.type("application/x-www-form-urlencoded").accept("application/json");
Form form = new Form();
form.param("grant_type", "refresh_token");
form.param("refresh_token", accessToken.getRefreshToken());
form.param("client_id", "consumer-id");
form.param("scope", "read_balance");
Response response = client.post(form);
accessToken = response.readEntity(ClientAccessToken.class);
assertNotNull(accessToken.getTokenKey());
assertNotNull(accessToken.getRefreshToken());
// Now try to refresh it again
try {
response = client.post(form);
response.readEntity(ClientAccessToken.class);
fail("Failure expected on trying to reuse a refresh token");
} catch (ResponseProcessingException ex) {
// expected
}
}
use of javax.ws.rs.client.ResponseProcessingException in project cxf by apache.
the class AuthorizationGrantNegativeTest method testPasswordCredentialsGrantUnknownUsers.
@org.junit.Test
public void testPasswordCredentialsGrantUnknownUsers() throws Exception {
URL busFile = AuthorizationGrantTest.class.getResource("client.xml");
String address = "https://localhost:" + PORT + "/services/";
WebClient client = WebClient.create(address, OAuth2TestUtils.setupProviders(), "consumer-id", "this-is-a-secret", busFile.toString());
// Get Access Token
client.type("application/x-www-form-urlencoded").accept("application/json");
client.path("token");
Form form = new Form();
Response response = client.post(form);
// No username
try {
response.readEntity(ClientAccessToken.class);
fail("Failure expected on no username");
} catch (ResponseProcessingException ex) {
// expected
}
// Bad username
form.param("username", "alice2");
response = client.post(form);
try {
response.readEntity(ClientAccessToken.class);
fail("Failure expected on a bad username");
} catch (ResponseProcessingException ex) {
// expected
}
// No password
form.param("username", "alice");
response = client.post(form);
try {
response.readEntity(ClientAccessToken.class);
fail("Failure expected on no password");
} catch (ResponseProcessingException ex) {
// expected
}
// Bad password
form.param("password", "security2");
response = client.post(form);
try {
response.readEntity(ClientAccessToken.class);
fail("Failure expected on a bad password");
} catch (ResponseProcessingException ex) {
// expected
}
}
Aggregations