Search in sources :

Example 91 with ClientConfig

use of org.glassfish.jersey.client.ClientConfig in project jersey by jersey.

the class AuthTest method testAuthDeleteWithClientFilter.

@Test
public void testAuthDeleteWithClientFilter() {
    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");
    Response response = r.request().delete();
    assertEquals(204, response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) 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 92 with ClientConfig

use of org.glassfish.jersey.client.ClientConfig in project jersey by jersey.

the class AuthTest method testAuthGetWithClientFilter.

@Test
public void testAuthGetWithClientFilter() {
    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("GET", r.request().get(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 93 with ClientConfig

use of org.glassfish.jersey.client.ClientConfig in project jersey by jersey.

the class AuthTest method testAuthPost.

@Test
@Ignore("JERSEY-1750: Cannot retry request with a non-repeatable request entity. How to buffer the entity?" + " Allow repeatable write in jersey?")
public void testAuthPost() {
    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("POST", r.request().post(Entity.text("POST"), 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) Ignore(org.junit.Ignore) JerseyTest(org.glassfish.jersey.test.JerseyTest) Test(org.junit.Test)

Example 94 with ClientConfig

use of org.glassfish.jersey.client.ClientConfig in project jersey by jersey.

the class CookieTest method testDisabledCookies.

@Test
public void testDisabledCookies() {
    ClientConfig cc = new ClientConfig();
    cc.property(ApacheClientProperties.DISABLE_COOKIES, true);
    cc.connectorProvider(new ApacheConnectorProvider());
    JerseyClient client = JerseyClientBuilder.createClient(cc);
    WebTarget r = client.target(getBaseUri());
    assertEquals("NO-COOKIE", r.request().get(String.class));
    assertEquals("NO-COOKIE", r.request().get(String.class));
    final ApacheConnector connector = (ApacheConnector) client.getConfiguration().getConnector();
    if (connector.getCookieStore() != null) {
        assertTrue(connector.getCookieStore().getCookies().isEmpty());
    } else {
        assertNull(connector.getCookieStore());
    }
}
Also used : WebTarget(javax.ws.rs.client.WebTarget) ClientConfig(org.glassfish.jersey.client.ClientConfig) JerseyClient(org.glassfish.jersey.client.JerseyClient) Test(org.junit.Test) JerseyTest(org.glassfish.jersey.test.JerseyTest)

Example 95 with ClientConfig

use of org.glassfish.jersey.client.ClientConfig in project jersey by jersey.

the class DisableContentEncodingTest method testDisabledByRequestConfig.

@Test
public void testDisabledByRequestConfig() {
    ClientConfig cc = new ClientConfig(GZipEncoder.class);
    final RequestConfig requestConfig = RequestConfig.custom().setContentCompressionEnabled(false).build();
    cc.property(ApacheClientProperties.REQUEST_CONFIG, requestConfig);
    cc.connectorProvider(new ApacheConnectorProvider());
    Client client = ClientBuilder.newClient(cc);
    WebTarget r = client.target(getBaseUri());
    String enc = r.request().get().readEntity(String.class);
    assertEquals("", enc);
}
Also used : RequestConfig(org.apache.http.client.config.RequestConfig) WebTarget(javax.ws.rs.client.WebTarget) ClientConfig(org.glassfish.jersey.client.ClientConfig) Client(javax.ws.rs.client.Client) Test(org.junit.Test) JerseyTest(org.glassfish.jersey.test.JerseyTest)

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