use of org.glassfish.jersey.client.ClientConfig in project jersey by jersey.
the class HttpMethodTest method createPoolingClient.
protected Client createPoolingClient() {
ClientConfig cc = new ClientConfig();
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
connectionManager.setMaxTotal(100);
connectionManager.setDefaultMaxPerRoute(100);
cc.property(ApacheClientProperties.CONNECTION_MANAGER, connectionManager);
cc.connectorProvider(new ApacheConnectorProvider());
return ClientBuilder.newClient(cc);
}
use of org.glassfish.jersey.client.ClientConfig in project jersey by jersey.
the class GZIPContentEncodingTest method testPostChunked.
@Test
public void testPostChunked() {
ClientConfig cc = new ClientConfig(GZipEncoder.class);
cc.property(ClientProperties.CHUNKED_ENCODING_SIZE, 1024);
cc.connectorProvider(new ApacheConnectorProvider());
Client client = ClientBuilder.newClient(cc);
WebTarget r = client.target(getBaseUri());
byte[] content = new byte[1024 * 1024];
assertTrue(Arrays.equals(content, r.request().post(Entity.entity(content, MediaType.APPLICATION_OCTET_STREAM_TYPE)).readEntity(byte[].class)));
Response cr = r.request().post(Entity.text("POST"));
assertTrue(cr.hasEntity());
cr.close();
}
use of org.glassfish.jersey.client.ClientConfig in project jersey by jersey.
the class GZIPContentEncodingTest method testPost.
@Test
public void testPost() {
ClientConfig cc = new ClientConfig(GZipEncoder.class);
cc.connectorProvider(new ApacheConnectorProvider());
Client client = ClientBuilder.newClient(cc);
WebTarget r = client.target(getBaseUri());
byte[] content = new byte[1024 * 1024];
assertTrue(Arrays.equals(content, r.request().post(Entity.entity(content, MediaType.APPLICATION_OCTET_STREAM_TYPE)).readEntity(byte[].class)));
Response cr = r.request().post(Entity.entity(content, MediaType.APPLICATION_OCTET_STREAM_TYPE));
assertTrue(cr.hasEntity());
cr.close();
}
use of org.glassfish.jersey.client.ClientConfig in project jersey by jersey.
the class HelloWorldTest method testAsyncClientRequests.
@Test
public void testAsyncClientRequests() throws InterruptedException {
HttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
ClientConfig cc = new ClientConfig();
cc.property(ApacheClientProperties.CONNECTION_MANAGER, connectionManager);
cc.connectorProvider(new ApacheConnectorProvider());
Client client = ClientBuilder.newClient(cc);
WebTarget target = client.target(getBaseUri());
final int REQUESTS = 20;
final CountDownLatch latch = new CountDownLatch(REQUESTS);
final long tic = System.currentTimeMillis();
final Map<Integer, String> results = new ConcurrentHashMap<Integer, String>();
for (int i = 0; i < REQUESTS; i++) {
final int id = i;
target.path(ROOT_PATH).request().async().get(new InvocationCallback<Response>() {
@Override
public void completed(Response response) {
try {
final String result = response.readEntity(String.class);
results.put(id, result);
} finally {
latch.countDown();
}
}
@Override
public void failed(Throwable error) {
Logger.getLogger(HelloWorldTest.class.getName()).log(Level.SEVERE, "Failed on throwable", error);
results.put(id, "error: " + error.getMessage());
latch.countDown();
}
});
}
assertTrue(latch.await(10 * getAsyncTimeoutMultiplier(), TimeUnit.SECONDS));
final long toc = System.currentTimeMillis();
Logger.getLogger(HelloWorldTest.class.getName()).info("Executed in: " + (toc - tic));
StringBuilder resultInfo = new StringBuilder("Results:\n");
for (int i = 0; i < REQUESTS; i++) {
String result = results.get(i);
resultInfo.append(i).append(": ").append(result).append('\n');
}
Logger.getLogger(HelloWorldTest.class.getName()).info(resultInfo.toString());
for (int i = 0; i < REQUESTS; i++) {
String result = results.get(i);
assertEquals(HelloWorldResource.CLICHED_MESSAGE, result);
}
}
use of org.glassfish.jersey.client.ClientConfig in project jersey by jersey.
the class AuthTest method testAuthGet.
@Test
public void testAuthGet() {
CredentialsProvider credentialsProvider = new org.apache.http.impl.client.BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("name", "password"));
ClientConfig cc = new ClientConfig();
cc.property(ApacheClientProperties.CREDENTIALS_PROVIDER, credentialsProvider);
cc.connectorProvider(new ApacheConnectorProvider());
Client client = ClientBuilder.newClient(cc);
WebTarget r = client.target(getBaseUri()).path("test");
assertEquals("GET", r.request().get(String.class));
}
Aggregations