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());
}
}
}
}
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));
}
}
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());
}
}
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());
}
}
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());
}
}
Aggregations