use of javax.ws.rs.client.Client 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.Client 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.Client in project jersey by jersey.
the class ClientBufferingDisabledTest method testDisableBufferingWithFixedLengthViaMethod.
/**
* Test that buffering can be disabled with {@link HttpURLConnection}. By default, the
* {@code HttpURLConnection} buffers the output entity in order to calculate the
* Content-length request attribute. This cause problems for large entities.
* <p>
* This test uses {@link HttpUrlConnectorProvider#useFixedLengthStreaming()} to enable
* fix length streaming on {@code HttpURLConnection}.
*/
@Test
public void testDisableBufferingWithFixedLengthViaMethod() {
postLatch = new CountDownLatch(1);
// This IS sends out 10 chunks and waits whether they were received on the server. This tests
// whether the buffering is disabled.
InputStream is = getInputStream();
final HttpUrlConnectorProvider connectorProvider = new HttpUrlConnectorProvider().useFixedLengthStreaming();
ClientConfig clientConfig = new ClientConfig().connectorProvider(connectorProvider);
Client client = ClientBuilder.newClient(clientConfig);
final Response response = client.target(getBaseUri()).path("resource").request().header(HttpHeaders.CONTENT_LENGTH, LENGTH).post(Entity.entity(is, MediaType.APPLICATION_OCTET_STREAM));
Assert.assertEquals(200, response.getStatus());
final long count = response.readEntity(long.class);
Assert.assertEquals("Unexpected content length received.", LENGTH, count);
}
use of javax.ws.rs.client.Client 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>");
}
use of javax.ws.rs.client.Client in project jersey by jersey.
the class ClientPreInitTest method testReusingPreinitializedConfig2.
@Test
public void testReusingPreinitializedConfig2() {
Client client = ClientBuilder.newClient();
client.register(TestReader.class);
client.register(MyResponseFilter.class);
assertFalse(TestReader.initialized);
((JerseyClient) client).preInitialize();
assertTrue(TestReader.initialized);
final WebTarget target = client.target(super.getBaseUri()).path("resource");
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