Search in sources :

Example 26 with ClientConfig

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

the class ConstrainedToTest method testClientWithProviderClasses.

@Test
public void testClientWithProviderClasses() {
    Client client = ClientBuilder.newClient(new ClientConfig(ClientFilterConstrainedToServer.class, ClientFilterConstrainedToClient.class, ClientFilter.class));
    _testFilters(client);
}
Also used : Client(javax.ws.rs.client.Client) ClientConfig(org.glassfish.jersey.client.ClientConfig) Test(org.junit.Test) JerseyTest(org.glassfish.jersey.test.JerseyTest)

Example 27 with ClientConfig

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

the class ConstrainedToTest method testClientWithProviderInstances.

@Test
public void testClientWithProviderInstances() {
    Client client = ClientBuilder.newClient(new ClientConfig(new ClientFilterConstrainedToServer(), new ClientFilterConstrainedToClient(), new ClientFilter()));
    _testFilters(client);
}
Also used : Client(javax.ws.rs.client.Client) ClientConfig(org.glassfish.jersey.client.ClientConfig) Test(org.junit.Test) JerseyTest(org.glassfish.jersey.test.JerseyTest)

Example 28 with ClientConfig

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

the class JsonEntityFilteringClientTest method testInvalidConfiguration.

@Test
public void testInvalidConfiguration() throws Exception {
    final ClientConfig config = new ClientConfig().property(EntityFilteringFeature.ENTITY_FILTERING_SCOPE, "invalid_value");
    configureClient(config);
    final OneFilteringOnClassEntity entity = ClientBuilder.newClient(config).target(getBaseUri()).request().post(Entity.entity(OneFilteringOnClassEntity.INSTANCE, MediaType.APPLICATION_JSON_TYPE), OneFilteringOnClassEntity.class);
    _testEmptyEntity(entity);
}
Also used : ClientConfig(org.glassfish.jersey.client.ClientConfig) OneFilteringOnClassEntity(org.glassfish.jersey.tests.e2e.entity.filtering.domain.OneFilteringOnClassEntity) JerseyTest(org.glassfish.jersey.test.JerseyTest) Test(org.junit.Test)

Example 29 with ClientConfig

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

the class UnderlyingCookieStoreAccessTest method testCookieStoreInstanceAccess.

@Test
public void testCookieStoreInstanceAccess() {
    final Client client = ClientBuilder.newClient(new ClientConfig().connectorProvider(new ApacheConnectorProvider()));
    final CookieStore csOnClient = ApacheConnectorProvider.getCookieStore(client);
    // important: the web target instance in this test must be only created AFTER the client has been pre-initialized
    // (see org.glassfish.jersey.client.Initializable.preInitialize method). This is here achieved by calling the
    // connector provider's static getCookieStore method above.
    final WebTarget target = client.target("http://localhost/");
    final CookieStore csOnTarget = ApacheConnectorProvider.getCookieStore(target);
    assertNotNull("CookieStore instance set on JerseyClient should not be null.", csOnClient);
    assertNotNull("CookieStore instance set on JerseyWebTarget should not be null.", csOnTarget);
    assertSame("CookieStore instance set on JerseyClient should be the same instance as the one set on JerseyWebTarget" + "(provided the target instance has not been further configured).", csOnClient, csOnTarget);
}
Also used : CookieStore(org.apache.http.client.CookieStore) WebTarget(javax.ws.rs.client.WebTarget) Client(javax.ws.rs.client.Client) ClientConfig(org.glassfish.jersey.client.ClientConfig) Test(org.junit.Test)

Example 30 with ClientConfig

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

the class RetryHandlerTest method testRetryGet.

@Test
public void testRetryGet() throws IOException {
    ClientConfig cc = new ClientConfig();
    cc.connectorProvider(new ApacheConnectorProvider());
    cc.property(ApacheClientProperties.RETRY_HANDLER, (HttpRequestRetryHandler) (exception, executionCount, context) -> true);
    cc.property(ClientProperties.READ_TIMEOUT, READ_TIMEOUT_MS);
    Client client = ClientBuilder.newClient(cc);
    WebTarget r = client.target(getBaseUri());
    assertEquals("GET", r.request().get(String.class));
}
Also used : POST(javax.ws.rs.POST) Context(javax.ws.rs.core.Context) GET(javax.ws.rs.GET) ClientConfig(org.glassfish.jersey.client.ClientConfig) Path(javax.ws.rs.Path) Client(javax.ws.rs.client.Client) IOException(java.io.IOException) Test(org.junit.Test) Application(javax.ws.rs.core.Application) ClientProperties(org.glassfish.jersey.client.ClientProperties) Entity(javax.ws.rs.client.Entity) ClientBuilder(javax.ws.rs.client.ClientBuilder) JerseyTest(org.glassfish.jersey.test.JerseyTest) HttpHeaders(javax.ws.rs.core.HttpHeaders) RequestEntityProcessing(org.glassfish.jersey.client.RequestEntityProcessing) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) WebTarget(javax.ws.rs.client.WebTarget) HttpRequestRetryHandler(org.apache.http.client.HttpRequestRetryHandler) Assert.assertEquals(org.junit.Assert.assertEquals) 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