Search in sources :

Example 16 with ResponseProcessingException

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());
    }
}
Also used : Response(javax.ws.rs.core.Response) ResponseProcessingException(javax.ws.rs.client.ResponseProcessingException) WebTarget(javax.ws.rs.client.WebTarget) NoContentException(javax.ws.rs.core.NoContentException) ProcessingException(javax.ws.rs.ProcessingException) ResponseProcessingException(javax.ws.rs.client.ResponseProcessingException) Test(org.junit.Test)

Example 17 with ResponseProcessingException

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();
}
Also used : ArrayList(java.util.ArrayList) ResponseProcessingException(javax.ws.rs.client.ResponseProcessingException) ExecutionException(java.util.concurrent.ExecutionException) WebClient(org.apache.cxf.jaxrs.client.WebClient) Test(org.junit.Test)

Example 18 with ResponseProcessingException

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
    }
}
Also used : Response(javax.ws.rs.core.Response) Form(javax.ws.rs.core.Form) ResponseProcessingException(javax.ws.rs.client.ResponseProcessingException) WebClient(org.apache.cxf.jaxrs.client.WebClient) URL(java.net.URL)

Example 19 with ResponseProcessingException

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
    }
}
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 20 with ResponseProcessingException

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
    }
}
Also used : Response(javax.ws.rs.core.Response) Form(javax.ws.rs.core.Form) ResponseProcessingException(javax.ws.rs.client.ResponseProcessingException) WebClient(org.apache.cxf.jaxrs.client.WebClient) URL(java.net.URL)

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