use of javax.ws.rs.client.Client in project jersey by jersey.
the class EncodingFilterTest method testContentEncodingSkippedForNoEntity.
@Test
public void testContentEncodingSkippedForNoEntity() {
Client client = ClientBuilder.newClient(new ClientConfig(EncodingFilter.class, GZipEncoder.class, DeflateEncoder.class).property(ClientProperties.USE_ENCODING, "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 javax.ws.rs.client.Client in project jersey by jersey.
the class HttpBasicAuthFilterTest method testGet.
@Test
public void testGet() {
Client client = ClientBuilder.newClient(new ClientConfig(HttpAuthenticationFeature.basic("Uzivatelske jmeno", "Heslo")).connectorProvider(new TestConnector()));
Invocation.Builder invBuilder = client.target(UriBuilder.fromUri("/").build()).request();
Response r = invBuilder.get();
assertEquals("Basic " + Base64.encodeAsString("Uzivatelske jmeno:Heslo"), r.getHeaderString(HttpHeaders.AUTHORIZATION));
}
use of javax.ws.rs.client.Client in project jersey by jersey.
the class HttpBasicAuthFilterTest method testBlankUsernamePassword.
@Test
public void testBlankUsernamePassword() {
Client client = ClientBuilder.newClient(new ClientConfig(HttpAuthenticationFeature.basic("", "")).connectorProvider(new TestConnector()));
Invocation.Builder invBuilder = client.target(UriBuilder.fromUri("/").build()).request();
Response r = invBuilder.get();
assertEquals("Basic " + Base64.encodeAsString(":"), r.getHeaderString(HttpHeaders.AUTHORIZATION));
}
use of javax.ws.rs.client.Client in project jersey by jersey.
the class CustomConnectorTest method testConnectorProviderPreservedOnClientConfigCopy.
/**
* Reproducer for JERSEY-2318.
*
* The test verifies that the {@link org.glassfish.jersey.client.spi.ConnectorProvider} configured
* on one client instance is transferred to another client instance when the new client instance is
* created from the original client instance configuration.
*/
@Test
public void testConnectorProviderPreservedOnClientConfigCopy() {
final ClientConfig clientConfig = new ClientConfig().connectorProvider(new TestConnectorProvider());
final Client client = ClientBuilder.newClient(clientConfig);
try {
Response response;
final WebTarget target = client.target("http://wherever.org/");
response = target.request().get();
// let's first verify we are using the test loop-back connector.
assertThat(response.getStatus(), equalTo(TestConnector.TEST_LOOPBACK_CODE));
assertThat(response.readEntity(String.class), equalTo("http://wherever.org/"));
// and now with the filter...
target.register(TestClientFilter.class);
response = target.request().get();
// check if the connector provider has been propagated:
assertThat(response.getStatus(), equalTo(TestConnector.TEST_LOOPBACK_CODE));
// check if the filter has been invoked:
assertThat(response.readEntity(String.class), equalTo("http://wherever.org/filtered"));
} finally {
client.close();
}
}
use of javax.ws.rs.client.Client in project jersey by jersey.
the class JerseyInvocationTest method testClearHeader.
/**
* Regression test for JERSEY-2562.
*/
@Test
public void testClearHeader() {
final Client client = ClientBuilder.newClient();
final Invocation.Builder builder = client.target("http://localhost:8080/mypath").request();
final JerseyInvocation invocation = (JerseyInvocation) builder.header("foo", "bar").header("foo", null).header("bar", "foo").buildGet();
final MultivaluedMap<String, Object> headers = invocation.request().getHeaders();
assertThat(headers.size(), is(1));
assertThat(headers.keySet(), hasItem("bar"));
}
Aggregations