Search in sources :

Example 1 with JerseyClient

use of org.glassfish.jersey.client.JerseyClient in project dropwizard by dropwizard.

the class Http2CIntegrationTest method testHttp11.

@Test
public void testHttp11() {
    final String hostname = "127.0.0.1";
    final int port = appRule.getLocalPort();
    final JerseyClient http11Client = new JerseyClientBuilder().build();
    final Response response = http11Client.target("http://" + hostname + ":" + port + "/api/test").request().get();
    assertThat(response.getHeaderString(HttpHeaders.CONTENT_TYPE)).isEqualTo(MediaType.APPLICATION_JSON);
    assertThat(response.readEntity(String.class)).isEqualTo(FakeApplication.HELLO_WORLD);
    http11Client.close();
}
Also used : Response(javax.ws.rs.core.Response) JerseyClient(org.glassfish.jersey.client.JerseyClient) JerseyClientBuilder(org.glassfish.jersey.client.JerseyClientBuilder) Test(org.junit.Test)

Example 2 with JerseyClient

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

the class CookieTest method testCookies.

@Test
public void testCookies() {
    ClientConfig cc = new ClientConfig();
    cc.connectorProvider(new JettyConnectorProvider());
    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 JettyConnector connector = (JettyConnector) client.getConfiguration().getConnector();
    assertNotNull(connector.getCookieStore().getCookies());
    assertEquals(1, connector.getCookieStore().getCookies().size());
    assertEquals("value", connector.getCookieStore().getCookies().get(0).getValue());
    client.close();
}
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 3 with JerseyClient

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

the class ClientPreInitTest method testReusingPreinitializedConfig2.

@Test
public void testReusingPreinitializedConfig2() {
    Client client = ClientBuilder.newClient();
    client.register(TestReader.class);
    client.register(MyResponseFilter.class);
    assertFalse(TestReader.initialized);
    ((JerseyClient) client).preInitialize();
    assertTrue(TestReader.initialized);
    final WebTarget target = client.target(super.getBaseUri()).path("resource");
    final WebTarget childTarget = target.path("child");
    final Response response = childTarget.request().get();
    checkResponse(response, "child:<null>");
    final Response resourceResponse = target.request().get();
    checkResponse(resourceResponse, "resource:<null>");
}
Also used : Response(javax.ws.rs.core.Response) JerseyWebTarget(org.glassfish.jersey.client.JerseyWebTarget) WebTarget(javax.ws.rs.client.WebTarget) Client(javax.ws.rs.client.Client) JerseyClient(org.glassfish.jersey.client.JerseyClient) JerseyClient(org.glassfish.jersey.client.JerseyClient) JerseyTest(org.glassfish.jersey.test.JerseyTest) Test(org.junit.Test)

Example 4 with JerseyClient

use of org.glassfish.jersey.client.JerseyClient 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 5 with JerseyClient

use of org.glassfish.jersey.client.JerseyClient in project dropwizard by dropwizard.

the class Http2IntegrationTest method testHttp11.

@Test
public void testHttp11() throws Exception {
    final String hostname = "localhost";
    final int port = appRule.getLocalPort();
    final JerseyClient http11Client = new JerseyClientBuilder().sslContext(sslContextFactory.getSslContext()).build();
    final Response response = http11Client.target("https://" + hostname + ":" + port + "/api/test").request().get();
    assertThat(response.getHeaderString(HttpHeaders.CONTENT_TYPE)).isEqualTo(MediaType.APPLICATION_JSON);
    assertThat(response.readEntity(String.class)).isEqualTo(FakeApplication.HELLO_WORLD);
    http11Client.close();
}
Also used : Response(javax.ws.rs.core.Response) JerseyClient(org.glassfish.jersey.client.JerseyClient) JerseyClientBuilder(org.glassfish.jersey.client.JerseyClientBuilder) Test(org.junit.Test)

Aggregations

JerseyClient (org.glassfish.jersey.client.JerseyClient)9 Test (org.junit.Test)8 JerseyTest (org.glassfish.jersey.test.JerseyTest)6 WebTarget (javax.ws.rs.client.WebTarget)5 ClientConfig (org.glassfish.jersey.client.ClientConfig)4 Response (javax.ws.rs.core.Response)3 JerseyClientBuilder (org.glassfish.jersey.client.JerseyClientBuilder)3 Field (java.lang.reflect.Field)1 Collection (java.util.Collection)1 Client (javax.ws.rs.client.Client)1 JerseyWebTarget (org.glassfish.jersey.client.JerseyWebTarget)1