Search in sources :

Example 21 with ProcessingException

use of javax.ws.rs.ProcessingException in project jersey by jersey.

the class InMemoryConnector method apply.

@Override
public Future<?> apply(final ClientRequest request, final AsyncConnectorCallback callback) {
    CompletableFuture<ClientResponse> future = new CompletableFuture<>();
    try {
        ClientResponse response = apply(request);
        callback.response(response);
        future.complete(response);
    } catch (ProcessingException ex) {
        future.completeExceptionally(ex);
    } catch (Throwable t) {
        callback.failure(t);
        future.completeExceptionally(t);
    }
    return future;
}
Also used : ClientResponse(org.glassfish.jersey.client.ClientResponse) CompletableFuture(java.util.concurrent.CompletableFuture) ProcessingException(javax.ws.rs.ProcessingException)

Example 22 with ProcessingException

use of javax.ws.rs.ProcessingException in project jersey by jersey.

the class EmptyEntityTest method testReceiveEmptyCharacter.

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

use of javax.ws.rs.ProcessingException in project jersey by jersey.

the class BeanStreamingTest method testBean.

@Test
public void testBean() throws Exception {
    Bean b = new Bean("bean", 123, 3.1415f);
    // the following should work using BeanProvider which
    // supports Bean.class for type application/bean
    WebTarget r = target().path("/bean");
    r.request().post(Entity.entity(b, "application/bean"), Bean.class);
    try {
        r = target().path("/plain");
        r.request().post(Entity.entity(b, "text/plain"), Bean.class);
        assertFalse(false);
    } catch (ProcessingException ex) {
        assertTrue(true);
    }
}
Also used : WebTarget(javax.ws.rs.client.WebTarget) ProcessingException(javax.ws.rs.ProcessingException) JerseyTest(org.glassfish.jersey.test.JerseyTest) Test(org.junit.Test)

Example 24 with ProcessingException

use of javax.ws.rs.ProcessingException in project jersey by jersey.

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)

Example 25 with ProcessingException

use of javax.ws.rs.ProcessingException in project jersey by jersey.

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)

Aggregations

ProcessingException (javax.ws.rs.ProcessingException)91 Test (org.junit.Test)32 IOException (java.io.IOException)26 Response (javax.ws.rs.core.Response)20 WebTarget (javax.ws.rs.client.WebTarget)19 JerseyTest (org.glassfish.jersey.test.JerseyTest)16 WebApplicationException (javax.ws.rs.WebApplicationException)11 CountDownLatch (java.util.concurrent.CountDownLatch)9 Client (javax.ws.rs.client.Client)9 ResponseProcessingException (javax.ws.rs.client.ResponseProcessingException)9 ByteArrayOutputStream (java.io.ByteArrayOutputStream)8 ClientRequest (org.glassfish.jersey.client.ClientRequest)8 ClientResponse (org.glassfish.jersey.client.ClientResponse)8 ByteArrayInputStream (java.io.ByteArrayInputStream)6 URI (java.net.URI)6 NoContentException (javax.ws.rs.core.NoContentException)6 OutputStream (java.io.OutputStream)5 Map (java.util.Map)5 CompletableFuture (java.util.concurrent.CompletableFuture)5 EventSource (org.glassfish.jersey.media.sse.EventSource)5