use of net.servicestack.client.ConnectionFilter in project ServiceStack.Java by ServiceStack.
the class JsonServiceClientTests method test_can_use_request_filter.
public void test_can_use_request_filter() {
final Boolean[] passTest = { false };
JsonServiceClient localTestClient = new JsonServiceClient("http://test.servicestack.net/");
localTestClient.RequestFilter = new ConnectionFilter() {
@Override
public void exec(HttpURLConnection conn) {
passTest[0] = true;
}
};
Hello request = new Hello().setName("World");
HelloResponse response = localTestClient.get(request);
assertEquals("Hello, World!", response.getResult());
assertTrue(passTest[0]);
}
use of net.servicestack.client.ConnectionFilter in project ServiceStack.Java by ServiceStack.
the class TestServiceTestsAsync method test_Can_send_ReturnVoid_Async.
public void test_Can_send_ReturnVoid_Async() {
final CountDownLatch signal = new CountDownLatch(1);
final List<String> sentMethods = new ArrayList<>();
client.RequestFilter = new ConnectionFilter() {
@Override
public void exec(HttpURLConnection conn) {
sentMethods.add(conn.getRequestMethod());
}
};
client.sendAsync(new HelloReturnVoid().setId(1), new AsyncResultVoid() {
@Override
public void success() {
assertEquals(HttpMethods.Post, sentMethods.get(sentMethods.size() - 1));
signal.countDown();
}
});
}
use of net.servicestack.client.ConnectionFilter in project ServiceStack.Java by ServiceStack.
the class TestServiceTests method test_Can_send_ReturnVoid.
public void test_Can_send_ReturnVoid() {
final List<String> sentMethods = new ArrayList<>();
client.RequestFilter = new ConnectionFilter() {
@Override
public void exec(HttpURLConnection conn) {
sentMethods.add(conn.getRequestMethod());
}
};
client.send(new HelloReturnVoid().setId(1));
assertEquals(HttpMethods.Post, sentMethods.get(sentMethods.size() - 1));
client.get(new HelloReturnVoid().setId(2));
assertEquals(HttpMethods.Get, sentMethods.get(sentMethods.size() - 1));
client.post(new HelloReturnVoid().setId(3));
assertEquals(HttpMethods.Post, sentMethods.get(sentMethods.size() - 1));
client.put(new HelloReturnVoid().setId(4));
assertEquals(HttpMethods.Put, sentMethods.get(sentMethods.size() - 1));
client.delete(new HelloReturnVoid().setId(5));
assertEquals(HttpMethods.Delete, sentMethods.get(sentMethods.size() - 1));
}
use of net.servicestack.client.ConnectionFilter in project ServiceStack.Java by ServiceStack.
the class TestServiceTests method test_does_fire_Request_and_Response_Filters.
public void test_does_fire_Request_and_Response_Filters() {
JsonServiceClient client = new JsonServiceClient("http://test.servicestack.net");
final ArrayList<String> events = new ArrayList<>();
JsonServiceClient.GlobalRequestFilter = new ConnectionFilter() {
@Override
public void exec(HttpURLConnection conn) {
events.add("GlobalRequestFilter");
}
};
JsonServiceClient.GlobalResponseFilter = new ConnectionFilter() {
@Override
public void exec(HttpURLConnection conn) {
events.add("GlobalResponseFilter");
}
};
client.RequestFilter = new ConnectionFilter() {
@Override
public void exec(HttpURLConnection conn) {
events.add("RequestFilter");
}
};
client.ResponseFilter = new ConnectionFilter() {
@Override
public void exec(HttpURLConnection conn) {
events.add("ResponseFilter");
}
};
Hello request = new Hello().setName("World");
HelloResponse response = client.get(request);
assertEquals("Hello, World!", response.getResult());
String results = strJoin(", ", events);
assertEquals("RequestFilter, GlobalRequestFilter, ResponseFilter, GlobalResponseFilter", results);
}
use of net.servicestack.client.ConnectionFilter in project ServiceStack.Java by ServiceStack.
the class TestServiceTestsAsync method test_does_fire_Request_and_Response_Filters_Async.
public void test_does_fire_Request_and_Response_Filters_Async() throws InterruptedException {
AndroidServiceClient client = new AndroidServiceClient("http://test.servicestack.net");
final ArrayList<String> events = new ArrayList<>();
AndroidServiceClient.GlobalRequestFilter = new ConnectionFilter() {
@Override
public void exec(HttpURLConnection conn) {
events.add("GlobalRequestFilter");
}
};
AndroidServiceClient.GlobalResponseFilter = new ConnectionFilter() {
@Override
public void exec(HttpURLConnection conn) {
events.add("GlobalResponseFilter");
}
};
client.RequestFilter = new ConnectionFilter() {
@Override
public void exec(HttpURLConnection conn) {
events.add("RequestFilter");
}
};
client.ResponseFilter = new ConnectionFilter() {
@Override
public void exec(HttpURLConnection conn) {
events.add("ResponseFilter");
}
};
Hello request = new Hello().setName("World");
final CountDownLatch signal = new CountDownLatch(1);
client.getAsync(request, new AsyncResult<HelloResponse>() {
@Override
public void success(HelloResponse response) {
assertEquals("Hello, World!", response.getResult());
String results = TextUtils.join(", ", events);
assertEquals("RequestFilter, GlobalRequestFilter, ResponseFilter, GlobalResponseFilter", results);
AndroidServiceClient.GlobalRequestFilter = null;
AndroidServiceClient.GlobalResponseFilter = null;
}
@Override
public void complete() {
signal.countDown();
}
});
assertTrue(signal.await(5, TimeUnit.SECONDS));
}
Aggregations