Search in sources :

Example 71 with Client

use of javax.ws.rs.client.Client 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 72 with Client

use of javax.ws.rs.client.Client 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)

Example 73 with Client

use of javax.ws.rs.client.Client in project jersey by jersey.

the class AuthTest method testAuthDelete.

@Test
public void testAuthDelete() {
    ClientConfig config = new ClientConfig();
    config.property(JettyClientProperties.PREEMPTIVE_BASIC_AUTHENTICATION, new BasicAuthentication(getBaseUri(), "WallyWorld", "name", "password"));
    config.connectorProvider(new JettyConnectorProvider());
    Client client = ClientBuilder.newClient(config);
    Response response = client.target(getBaseUri()).path(PATH).request().delete();
    assertEquals(response.getStatus(), 204);
    client.close();
}
Also used : Response(javax.ws.rs.core.Response) BasicAuthentication(org.eclipse.jetty.client.util.BasicAuthentication) ClientConfig(org.glassfish.jersey.client.ClientConfig) Client(javax.ws.rs.client.Client) Test(org.junit.Test) JerseyTest(org.glassfish.jersey.test.JerseyTest)

Example 74 with Client

use of javax.ws.rs.client.Client in project jersey by jersey.

the class HelloWorldTest method testLoggingFilterClientClass.

@Test
public void testLoggingFilterClientClass() {
    Client client = client();
    client.register(CustomLoggingFilter.class).property("foo", "bar");
    CustomLoggingFilter.preFilterCalled = CustomLoggingFilter.postFilterCalled = 0;
    String s = target().path(ROOT_PATH).request().get(String.class);
    assertEquals(HelloWorldResource.CLICHED_MESSAGE, s);
    assertEquals(1, CustomLoggingFilter.preFilterCalled);
    assertEquals(1, CustomLoggingFilter.postFilterCalled);
    client.close();
}
Also used : Client(javax.ws.rs.client.Client) Test(org.junit.Test) JerseyTest(org.glassfish.jersey.test.JerseyTest)

Example 75 with Client

use of javax.ws.rs.client.Client in project jersey by jersey.

the class HelloWorldTest method testLoggingFilterClientInstance.

@Test
public void testLoggingFilterClientInstance() {
    Client client = client();
    client.register(new CustomLoggingFilter()).property("foo", "bar");
    CustomLoggingFilter.preFilterCalled = CustomLoggingFilter.postFilterCalled = 0;
    String s = target().path(ROOT_PATH).request().get(String.class);
    assertEquals(HelloWorldResource.CLICHED_MESSAGE, s);
    assertEquals(1, CustomLoggingFilter.preFilterCalled);
    assertEquals(1, CustomLoggingFilter.postFilterCalled);
    client.close();
}
Also used : Client(javax.ws.rs.client.Client) Test(org.junit.Test) JerseyTest(org.glassfish.jersey.test.JerseyTest)

Aggregations

Client (javax.ws.rs.client.Client)227 Test (org.junit.Test)160 WebTarget (javax.ws.rs.client.WebTarget)96 Response (javax.ws.rs.core.Response)87 JerseyTest (org.glassfish.jersey.test.JerseyTest)76 ClientConfig (org.glassfish.jersey.client.ClientConfig)71 URL (java.net.URL)20 ClientResponse (org.glassfish.jersey.client.ClientResponse)19 JerseyClientBuilder (io.dropwizard.client.JerseyClientBuilder)18 Before (org.junit.Before)17 Invocation (javax.ws.rs.client.Invocation)15 ResourceConfig (org.glassfish.jersey.server.ResourceConfig)14 IOException (java.io.IOException)12 ProcessingException (javax.ws.rs.ProcessingException)12 HttpServer (org.glassfish.grizzly.http.server.HttpServer)10 URI (java.net.URI)9 JerseyClient (org.glassfish.jersey.client.JerseyClient)9 PrintWriter (java.io.PrintWriter)8 CountDownLatch (java.util.concurrent.CountDownLatch)8 SSLContext (javax.net.ssl.SSLContext)8