use of org.glassfish.jersey.client.ClientConfig in project jersey by jersey.
the class AuthTest method testAuthPostWithClientFilter.
@Test
public void testAuthPostWithClientFilter() {
ClientConfig cc = new ClientConfig();
cc.connectorProvider(new ApacheConnectorProvider());
Client client = ClientBuilder.newClient(cc);
client.register(HttpAuthenticationFeature.basic("name", "password"));
WebTarget r = client.target(getBaseUri()).path("test/filter");
assertEquals("POST", r.request().post(Entity.text("POST"), String.class));
}
use of org.glassfish.jersey.client.ClientConfig in project jersey by jersey.
the class HelloWorldTest method _testConnectionPoolSharing.
public void _testConnectionPoolSharing(final boolean sharingEnabled) throws Exception {
final HttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
final ClientConfig cc = new ClientConfig();
cc.property(ApacheClientProperties.CONNECTION_MANAGER, connectionManager);
cc.property(ApacheClientProperties.CONNECTION_MANAGER_SHARED, sharingEnabled);
cc.connectorProvider(new ApacheConnectorProvider());
final Client clientOne = ClientBuilder.newClient(cc);
WebTarget target = clientOne.target(getBaseUri()).path(ROOT_PATH);
target.request().get();
clientOne.close();
final boolean exceptionExpected = !sharingEnabled;
final Client clientTwo = ClientBuilder.newClient(cc);
target = clientTwo.target(getBaseUri()).path(ROOT_PATH);
try {
target.request().get();
if (exceptionExpected) {
Assert.fail("Exception expected");
}
} catch (Exception e) {
if (!exceptionExpected) {
Assert.fail("Exception not expected");
}
} finally {
clientTwo.close();
}
if (sharingEnabled) {
connectionManager.shutdown();
}
}
use of org.glassfish.jersey.client.ClientConfig in project jersey by jersey.
the class AuthTest method testPreemptiveAuth.
@Test
public void testPreemptiveAuth() {
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).property(ApacheClientProperties.PREEMPTIVE_BASIC_AUTHENTICATION, true);
cc.connectorProvider(new ApacheConnectorProvider());
Client client = ClientBuilder.newClient(cc);
WebTarget r = client.target(getBaseUri());
assertEquals("GET", r.request().get(String.class));
}
use of org.glassfish.jersey.client.ClientConfig in project jersey by jersey.
the class AuthTest method testAuthInteractiveGet.
@Test
public void testAuthInteractiveGet() {
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));
}
use of org.glassfish.jersey.client.ClientConfig in project jersey by jersey.
the class AuthTest method testAuthDelete.
@Test
public void testAuthDelete() {
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");
Response response = r.request().delete();
assertEquals(response.getStatus(), 204);
}
Aggregations