Search in sources :

Example 6 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)

Example 7 with ClientConfig

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

the class CookieTest method testCookies.

@Test
public void testCookies() {
    ClientConfig cc = new ClientConfig();
    cc.connectorProvider(new ApacheConnectorProvider());
    JerseyClient client = JerseyClientBuilder.createClient(cc);
    WebTarget r = client.target(getBaseUri());
    assertEquals("NO-COOKIE", r.request().get(String.class));
    assertEquals("value", r.request().get(String.class));
    final ApacheConnector connector = (ApacheConnector) client.getConfiguration().getConnector();
    assertNotNull(connector.getCookieStore().getCookies());
    assertEquals(1, connector.getCookieStore().getCookies().size());
    assertEquals("value", connector.getCookieStore().getCookies().get(0).getValue());
}
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 8 with ClientConfig

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

the class CookieTest method testCookieResource.

@Test
public void testCookieResource() {
    ClientConfig cc = new ClientConfig();
    cc.connectorProvider(new ApacheConnectorProvider());
    Client client = ClientBuilder.newClient(cc);
    WebTarget r = client.target(getBaseUri());
    assertEquals("NO-COOKIE", r.request().get(String.class));
    assertEquals("value", 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) JerseyClient(org.glassfish.jersey.client.JerseyClient) Test(org.junit.Test) JerseyTest(org.glassfish.jersey.test.JerseyTest)

Example 9 with ClientConfig

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

the class DisableContentEncodingTest method testEnabledByRequestConfig.

@Test
public void testEnabledByRequestConfig() {
    ClientConfig cc = new ClientConfig(GZipEncoder.class);
    final RequestConfig requestConfig = RequestConfig.custom().setContentCompressionEnabled(true).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("gzip,deflate", 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)

Example 10 with ClientConfig

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

the class DisableContentEncodingTest method testDefaultEncodingOverridden.

@Test
public void testDefaultEncodingOverridden() {
    ClientConfig cc = new ClientConfig(GZipEncoder.class);
    cc.connectorProvider(new ApacheConnectorProvider());
    Client client = ClientBuilder.newClient(cc);
    WebTarget r = client.target(getBaseUri());
    String enc = r.request().acceptEncoding("gzip").get().readEntity(String.class);
    assertEquals("gzip", enc);
}
Also used : 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)94 Test (org.junit.Test)77 Client (javax.ws.rs.client.Client)74 JerseyTest (org.glassfish.jersey.test.JerseyTest)51 WebTarget (javax.ws.rs.client.WebTarget)46 Response (javax.ws.rs.core.Response)33 ClientResponse (org.glassfish.jersey.client.ClientResponse)12 Invocation (javax.ws.rs.client.Invocation)8 CountDownLatch (java.util.concurrent.CountDownLatch)7 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)7 CredentialsProvider (org.apache.http.client.CredentialsProvider)7 JerseyClient (org.glassfish.jersey.client.JerseyClient)6 SSLContext (javax.net.ssl.SSLContext)5 ProcessingException (javax.ws.rs.ProcessingException)5 ClientBuilder (javax.ws.rs.client.ClientBuilder)5 ApacheConnectorProvider (org.glassfish.jersey.apache.connector.ApacheConnectorProvider)5 IOException (java.io.IOException)4 HttpUrlConnectorProvider (org.glassfish.jersey.client.HttpUrlConnectorProvider)4 ResourceConfig (org.glassfish.jersey.server.ResourceConfig)4 Ignore (org.junit.Ignore)4