Search in sources :

Example 51 with ResponseProcessingException

use of javax.ws.rs.client.ResponseProcessingException in project jersey by eclipse-ee4j.

the class LostResponseTest method asyncPutEntityAndClassFailure.

@Test
public void asyncPutEntityAndClassFailure() throws InterruptedException {
    try {
        Future<String> future = client.target(DUMMY_URL).request().async().put(bodyEntity, String.class);
        future.get();
        Assert.fail("Expected ResponseProcessing exception has not been thrown");
    } catch (ExecutionException ee) {
        try {
            throw (RuntimeException) ee.getCause();
        } catch (ResponseProcessingException rpe) {
            try (Response response = rpe.getResponse()) {
                Assert.assertEquals(RESPONSE_CODE, response.getStatus());
            }
        }
    }
}
Also used : Response(javax.ws.rs.core.Response) ResponseProcessingException(javax.ws.rs.client.ResponseProcessingException) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 52 with ResponseProcessingException

use of javax.ws.rs.client.ResponseProcessingException in project jersey by eclipse-ee4j.

the class LostResponseTest method asyncPutEntityWithCallbackFailure.

@Test
public void asyncPutEntityWithCallbackFailure() throws InterruptedException {
    AtomicReference<Throwable> callbackThrowable = new AtomicReference<>();
    CountDownLatch failedLatch = new CountDownLatch(1);
    try {
        Future<Response> future = client.target(DUMMY_URL).request().async().put(bodyEntity, new InvocationCallback<Response>() {

            @Override
            public void completed(Response response) {
                Assert.fail("Expected ResponseProcessing exception has not been thrown");
            }

            @Override
            public void failed(Throwable throwable) {
                callbackThrowable.set(throwable);
                failedLatch.countDown();
            }
        });
        future.get();
        Assert.fail("Expected ResponseProcessing exception has not been thrown");
    } catch (ExecutionException ee) {
        try {
            throw (RuntimeException) ee.getCause();
        } catch (ResponseProcessingException rpe) {
            try (Response response = rpe.getResponse()) {
                Assert.assertEquals(RESPONSE_CODE, response.getStatus());
            }
        }
        failedLatch.await(5000, TimeUnit.MILLISECONDS);
        Throwable ct = callbackThrowable.get();
        Assert.assertTrue("Callback has not been hit", ct != null);
        Assert.assertTrue("The exception is " + ct.getClass().getName(), ResponseProcessingException.class.isInstance(ct));
    }
}
Also used : Response(javax.ws.rs.core.Response) AtomicReference(java.util.concurrent.atomic.AtomicReference) ResponseProcessingException(javax.ws.rs.client.ResponseProcessingException) CountDownLatch(java.util.concurrent.CountDownLatch) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 53 with ResponseProcessingException

use of javax.ws.rs.client.ResponseProcessingException in project jersey by eclipse-ee4j.

the class EmptyEntityTest method testReceiveEmptyJAXBlist.

@Test
public void testReceiveEmptyJAXBlist() {
    WebTarget target = target("empty/getempty");
    final Response response = target.request("application/xml").get();
    assertEquals(200, response.getStatus());
    try {
        response.readEntity(new GenericType<List<TestJaxbBean>>() {
        });
        fail("ProcessingException expected.");
    } catch (ProcessingException ex) {
        assertSame(NoContentException.class, ex.getCause().getClass());
    }
    try {
        target.request("application/xml").get(new GenericType<List<TestJaxbBean>>() {
        });
        fail("ResponseProcessingException expected.");
    } catch (ResponseProcessingException ex) {
        assertSame(NoContentException.class, ex.getCause().getClass());
    }
}
Also used : Response(javax.ws.rs.core.Response) List(java.util.List) 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 54 with ResponseProcessingException

use of javax.ws.rs.client.ResponseProcessingException in project jersey by eclipse-ee4j.

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 55 with ResponseProcessingException

use of javax.ws.rs.client.ResponseProcessingException in project jersey by eclipse-ee4j.

the class EmptyEntityTest method testReceiveEmptyJAXBbean.

@Test
public void testReceiveEmptyJAXBbean() {
    WebTarget target = target("empty/getempty");
    final Response response = target.request("application/xml").get();
    assertEquals(200, response.getStatus());
    try {
        response.readEntity(TestJaxbBean.class);
        fail("ProcessingException expected.");
    } catch (ProcessingException ex) {
        assertSame(NoContentException.class, ex.getCause().getClass());
    }
    try {
        target.request("application/xml").get(TestJaxbBean.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)

Aggregations

ResponseProcessingException (javax.ws.rs.client.ResponseProcessingException)59 Response (javax.ws.rs.core.Response)38 Test (org.junit.Test)29 ProcessingException (javax.ws.rs.ProcessingException)20 WebClient (org.apache.cxf.jaxrs.client.WebClient)16 WebTarget (javax.ws.rs.client.WebTarget)15 URL (java.net.URL)14 Form (javax.ws.rs.core.Form)13 NoContentException (javax.ws.rs.core.NoContentException)12 ExecutionException (java.util.concurrent.ExecutionException)8 IOException (java.io.IOException)7 WebApplicationException (javax.ws.rs.WebApplicationException)5 ClientAccessToken (org.apache.cxf.rs.security.oauth2.common.ClientAccessToken)5 InputStream (java.io.InputStream)4 NotFoundException (javax.ws.rs.NotFoundException)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 InterruptedIOException (java.io.InterruptedIOException)2 PushbackInputStream (java.io.PushbackInputStream)2 SocketTimeoutException (java.net.SocketTimeoutException)2