use of org.glassfish.jersey.client.ClientConfig in project jersey by jersey.
the class DisableContentEncodingTest method testDefaultEncoding.
@Test
public void testDefaultEncoding() {
ClientConfig cc = new ClientConfig(GZipEncoder.class);
cc.connectorProvider(new ApacheConnectorProvider());
Client client = ClientBuilder.newClient(cc);
WebTarget r = client.target(getBaseUri());
String enc = r.request().get().readEntity(String.class);
assertEquals("gzip,deflate", enc);
}
use of org.glassfish.jersey.client.ClientConfig in project jersey by jersey.
the class CachingConnectorProviderTest method testCachingConnector.
@Test
public void testCachingConnector() {
final ReferenceCountingNullConnector connectorProvider = new ReferenceCountingNullConnector();
final CachingConnectorProvider cachingConnectorProvider = new CachingConnectorProvider(connectorProvider);
final ClientConfig configuration = new ClientConfig().connectorProvider(cachingConnectorProvider).getConfiguration();
Client client1 = ClientBuilder.newClient(configuration);
try {
client1.target(UriBuilder.fromUri("/").build()).request().get();
} catch (ProcessingException ce) {
assertEquals("test", ce.getMessage());
assertEquals(1, connectorProvider.getCount());
}
try {
client1.target(UriBuilder.fromUri("/").build()).request().async().get();
} catch (ProcessingException ce) {
assertEquals("test-async", ce.getMessage());
assertEquals(1, connectorProvider.getCount());
}
Client client2 = ClientBuilder.newClient(configuration);
try {
client2.target(UriBuilder.fromUri("/").build()).request().get();
} catch (ProcessingException ce) {
assertEquals("test", ce.getMessage());
assertEquals(1, connectorProvider.getCount());
}
try {
client2.target(UriBuilder.fromUri("/").build()).request().async().get();
} catch (ProcessingException ce) {
assertEquals("test-async", ce.getMessage());
assertEquals(1, connectorProvider.getCount());
}
}
use of org.glassfish.jersey.client.ClientConfig in project jersey by jersey.
the class EncodingFilterTest method testAcceptEncoding.
@Test
public void testAcceptEncoding() {
Client client = ClientBuilder.newClient(new ClientConfig(EncodingFilter.class, GZipEncoder.class, DeflateEncoder.class).connectorProvider(new TestConnector()));
Invocation.Builder invBuilder = client.target(UriBuilder.fromUri("/").build()).request();
Response r = invBuilder.get();
assertEquals("deflate,gzip,x-gzip", r.getHeaderString(ACCEPT_ENCODING));
assertNull(r.getHeaderString(CONTENT_ENCODING));
}
use of org.glassfish.jersey.client.ClientConfig in project jersey by jersey.
the class EncodingFilterTest method testUnsupportedContentEncoding.
@Test
public void testUnsupportedContentEncoding() {
Client client = ClientBuilder.newClient(new ClientConfig(EncodingFilter.class, GZipEncoder.class, DeflateEncoder.class).property(ClientProperties.USE_ENCODING, "non-gzip").connectorProvider(new TestConnector()));
Invocation.Builder invBuilder = client.target(UriBuilder.fromUri("/").build()).request();
Response r = invBuilder.get();
assertEquals("deflate,gzip,x-gzip", r.getHeaderString(ACCEPT_ENCODING));
assertNull(r.getHeaderString(CONTENT_ENCODING));
}
use of org.glassfish.jersey.client.ClientConfig in project jersey by jersey.
the class EncodingFilterTest method testClosingClientResponseStreamRetrievedByValueOnError.
/**
* Reproducer for JERSEY-2028.
*
* @see #testClosingClientResponseStreamRetrievedByResponseOnError
*/
@Test
public void testClosingClientResponseStreamRetrievedByValueOnError() {
final TestInputStream responseStream = new TestInputStream();
Client client = ClientBuilder.newClient(new ClientConfig().connectorProvider(new TestConnector() {
@Override
public ClientResponse apply(ClientRequest requestContext) throws ProcessingException {
final ClientResponse responseContext = new ClientResponse(Response.Status.OK, requestContext);
responseContext.header(CONTENT_ENCODING, "gzip");
responseContext.setEntityStream(responseStream);
return responseContext;
}
}).register(new EncodingFeature(GZipEncoder.class, DeflateEncoder.class)));
try {
client.target(UriBuilder.fromUri("/").build()).request().get(String.class);
fail("Exception caused by invalid gzip stream expected.");
} catch (ProcessingException ex) {
assertTrue("Response input stream not closed when exception is thrown.", responseStream.isClosed);
}
}
Aggregations