use of javax.ws.rs.client.WebTarget in project jersey by jersey.
the class InterceptorGzipTest method testGzipInterceptorOnServerandClient.
@Test
public void testGzipInterceptorOnServerandClient() throws IOException {
client().register(GZIPReaderTestInterceptor.class).register(GZIPWriterTestInterceptor.class);
WebTarget target = target().path("test");
String entity = "hello, this is text entity";
Response response = target.request().put(Entity.entity(entity, MediaType.TEXT_PLAIN_TYPE));
String str = response.readEntity(String.class);
assertEquals(entity + FROM_RESOURCE, str);
}
use of javax.ws.rs.client.WebTarget in project jersey by jersey.
the class BasicClientTest method testSyncClientInvocationErrorResponse.
@Test
public void testSyncClientInvocationErrorResponse() throws InterruptedException, ExecutionException {
final WebTarget errorResource = target().path("resource").path("error");
Response r1 = errorResource.request().get();
assertEquals(404, r1.getStatus());
assertEquals("error", r1.readEntity(String.class));
try {
errorResource.request().get(String.class);
fail("ExecutionException expected.");
} catch (WebApplicationException ex) {
final Response r = ex.getResponse();
assertEquals(404, r.getStatus());
assertEquals("error", r.readEntity(String.class));
}
try {
target().path("resource").path("errorlist").request().get(new GenericType<List<String>>() {
});
fail("ExecutionException expected.");
} catch (WebApplicationException ex) {
final Response r = ex.getResponse();
assertEquals(404, r.getStatus());
assertEquals("error", r.readEntity(String.class));
}
}
use of javax.ws.rs.client.WebTarget in project jersey by jersey.
the class BufferingTest method makeRequest.
private void makeRequest(ClientConfig cc, String entity, String expected) {
Client client = ClientBuilder.newClient(cc);
WebTarget target = client.target(UriBuilder.fromUri(getBaseUri()).path("resource").build());
Response response = target.request().post(Entity.entity(entity, MediaType.TEXT_PLAIN_TYPE));
Assert.assertEquals(200, response.getStatus());
Assert.assertEquals(expected, response.readEntity(String.class));
}
use of javax.ws.rs.client.WebTarget in project jersey by jersey.
the class BufferingTest method testWithChunkEncodingPerRequest.
/**
* Tests that {@link org.glassfish.jersey.client.ClientProperties#REQUEST_ENTITY_PROCESSING} can be defined
* per request with different values.
*/
private void testWithChunkEncodingPerRequest(ClientConfig cc) {
cc.property(ClientProperties.REQUEST_ENTITY_PROCESSING, RequestEntityProcessing.CHUNKED);
cc.property(ClientProperties.CHUNKED_ENCODING_SIZE, 3000);
Client client = ClientBuilder.newClient(cc);
WebTarget target = client.target(UriBuilder.fromUri(getBaseUri()).path("resource").build());
String entity = getVeryLongString();
Response response = target.request().post(Entity.entity(entity, MediaType.TEXT_PLAIN_TYPE));
Assert.assertEquals(200, response.getStatus());
Assert.assertEquals("chunked", response.readEntity(String.class));
response = target.property(ClientProperties.REQUEST_ENTITY_PROCESSING, RequestEntityProcessing.BUFFERED).request().post(Entity.entity(entity, MediaType.TEXT_PLAIN_TYPE));
Assert.assertEquals(200, response.getStatus());
Assert.assertEquals(String.valueOf(entity.length()), response.readEntity(String.class));
}
use of javax.ws.rs.client.WebTarget in project jersey by jersey.
the class ClientPreInitTest method testReusingPreinitializedConfig.
@Test
public void testReusingPreinitializedConfig() {
Client client = ClientBuilder.newClient();
client.register(TestReader.class);
final WebTarget target = client.target(super.getBaseUri()).path("resource");
target.register(MyResponseFilter.class);
((JerseyWebTarget) target).preInitialize();
assertTrue(TestReader.initialized);
final WebTarget childTarget = target.path("child");
final Response response = childTarget.request().get();
checkResponse(response, "child:<null>");
final Response resourceResponse = target.request().get();
checkResponse(resourceResponse, "resource:<null>");
}
Aggregations