use of javax.ws.rs.client.WebTarget 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 javax.ws.rs.client.WebTarget in project jersey by jersey.
the class FollowRedirectsTest method testDontFollow.
@Test
public void testDontFollow() {
WebTarget t = target("test/redirect");
t.property(ClientProperties.FOLLOW_REDIRECTS, false);
assertEquals(303, t.request().get().getStatus());
}
use of javax.ws.rs.client.WebTarget 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 javax.ws.rs.client.WebTarget 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 javax.ws.rs.client.WebTarget 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));
}
Aggregations