use of net.servicestack.client.WebServiceException in project ServiceStack.Java by ServiceStack.
the class JsonServiceClientTests method test_does_process_missing_service_correctly.
public void test_does_process_missing_service_correctly() {
JsonServiceClient localTestClient = new JsonServiceClient("https://servicestack.net/");
try {
localTestClient.get(new EchoTypes());
fail("Should throw");
} catch (WebServiceException ex) {
assertEquals(ex.getStatusCode(), 405);
}
}
use of net.servicestack.client.WebServiceException in project ServiceStack.Java by ServiceStack.
the class TestServiceTestsAsync method test_Does_handle_404_Error_Async.
public void test_Does_handle_404_Error_Async() throws InterruptedException {
AndroidServiceClient testClient = new AndroidServiceClient("http://test.servicestack.net");
// Wow Java, you suck.
final Exception[] globalError = new Exception[1];
final Exception[] localError = new Exception[1];
final WebServiceException[] thrownError = { null };
AndroidServiceClient.GlobalExceptionFilter = new ExceptionFilter() {
@Override
public void exec(HttpURLConnection res, Exception ex) {
globalError[0] = ex;
}
};
testClient.ExceptionFilter = new ExceptionFilter() {
@Override
public void exec(HttpURLConnection res, Exception ex) {
localError[0] = ex;
}
};
ThrowType request = new ThrowType().setType("NotFound").setMessage("not here");
final CountDownLatch signal = new CountDownLatch(1);
testClient.putAsync(request, new AsyncResult<ThrowTypeResponse>() {
@Override
public void success(ThrowTypeResponse response) {
fail("should not succeed");
}
@Override
public void error(Exception ex) {
thrownError[0] = (WebServiceException) ex;
}
@Override
public void complete() {
signal.countDown();
}
});
assertTrue(signal.await(5, TimeUnit.SECONDS));
assertNotNull(globalError[0]);
assertNotNull(localError[0]);
assertNotNull(thrownError[0]);
ResponseStatus status = thrownError[0].getResponseStatus();
assertEquals("NotFound", status.getErrorCode());
assertEquals("not here", status.getMessage());
assertNotNull(status.getStackTrace());
}
Aggregations