Search in sources :

Example 1 with ClientConfig

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));
}
Also used : WebTarget(javax.ws.rs.client.WebTarget) ClientConfig(org.glassfish.jersey.client.ClientConfig) Client(javax.ws.rs.client.Client) JerseyTest(org.glassfish.jersey.test.JerseyTest) Test(org.junit.Test)

Example 2 with ClientConfig

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();
    }
}
Also used : WebTarget(javax.ws.rs.client.WebTarget) PoolingHttpClientConnectionManager(org.apache.http.impl.conn.PoolingHttpClientConnectionManager) HttpClientConnectionManager(org.apache.http.conn.HttpClientConnectionManager) ClientConfig(org.glassfish.jersey.client.ClientConfig) Client(javax.ws.rs.client.Client) ConnectionPoolTimeoutException(org.apache.http.conn.ConnectionPoolTimeoutException) IOException(java.io.IOException) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) HttpException(org.apache.http.HttpException) PoolingHttpClientConnectionManager(org.apache.http.impl.conn.PoolingHttpClientConnectionManager)

Example 3 with ClientConfig

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));
}
Also used : CredentialsProvider(org.apache.http.client.CredentialsProvider) WebTarget(javax.ws.rs.client.WebTarget) ClientConfig(org.glassfish.jersey.client.ClientConfig) Client(javax.ws.rs.client.Client) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) JerseyTest(org.glassfish.jersey.test.JerseyTest) Test(org.junit.Test)

Example 4 with ClientConfig

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));
}
Also used : CredentialsProvider(org.apache.http.client.CredentialsProvider) WebTarget(javax.ws.rs.client.WebTarget) ClientConfig(org.glassfish.jersey.client.ClientConfig) Client(javax.ws.rs.client.Client) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) JerseyTest(org.glassfish.jersey.test.JerseyTest) Test(org.junit.Test)

Example 5 with ClientConfig

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);
}
Also used : Response(javax.ws.rs.core.Response) CredentialsProvider(org.apache.http.client.CredentialsProvider) WebTarget(javax.ws.rs.client.WebTarget) ClientConfig(org.glassfish.jersey.client.ClientConfig) Client(javax.ws.rs.client.Client) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) JerseyTest(org.glassfish.jersey.test.JerseyTest) Test(org.junit.Test)

Aggregations

ClientConfig (org.glassfish.jersey.client.ClientConfig)169 Client (javax.ws.rs.client.Client)129 Test (org.junit.Test)85 Response (javax.ws.rs.core.Response)66 JerseyTest (org.glassfish.jersey.test.JerseyTest)52 WebTarget (javax.ws.rs.client.WebTarget)48 ClientBuilder (javax.ws.rs.client.ClientBuilder)17 SSLContext (javax.net.ssl.SSLContext)12 Invocation (javax.ws.rs.client.Invocation)12 ClientResponse (org.glassfish.jersey.client.ClientResponse)12 ApacheConnectorProvider (org.glassfish.jersey.apache.connector.ApacheConnectorProvider)10 IOException (java.io.IOException)9 IntegrationTest (com.hortonworks.streamline.common.test.IntegrationTest)8 URI (java.net.URI)7 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)7 CredentialsProvider (org.apache.http.client.CredentialsProvider)7 PoolingHttpClientConnectionManager (org.apache.http.impl.conn.PoolingHttpClientConnectionManager)7 CountDownLatch (java.util.concurrent.CountDownLatch)6 JerseyClient (org.glassfish.jersey.client.JerseyClient)6 JacksonJsonProvider (com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider)5