Search in sources :

Example 6 with JerseyClient

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

the class CookieTest method testDisabledCookies.

@Test
public void testDisabledCookies() {
    ClientConfig cc = new ClientConfig();
    cc.property(JettyClientProperties.DISABLE_COOKIES, true);
    cc.connectorProvider(new JettyConnectorProvider());
    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 JettyConnector connector = (JettyConnector) client.getConfiguration().getConnector();
    if (connector.getCookieStore() != null) {
        assertTrue(connector.getCookieStore().getCookies().isEmpty());
    } else {
        assertNull(connector.getCookieStore());
    }
    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 7 with JerseyClient

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

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

the class ShutdownHookMemoryLeakTest method getShutdownHooks.

private Collection getShutdownHooks(javax.ws.rs.client.Client client) throws NoSuchFieldException, IllegalAccessException {
    JerseyClient jerseyClient = (JerseyClient) client;
    Field shutdownHooksField = JerseyClient.class.getDeclaredField("shutdownHooks");
    shutdownHooksField.setAccessible(true);
    return (Collection) shutdownHooksField.get(jerseyClient);
}
Also used : Field(java.lang.reflect.Field) Collection(java.util.Collection) JerseyClient(org.glassfish.jersey.client.JerseyClient)

Example 9 with JerseyClient

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

the class ClientDestroyTest method testLifecycleListenerProvider.

@Test
public void testLifecycleListenerProvider() {
    final JerseyClientBuilder builder = new JerseyClientBuilder();
    final JerseyClient client = builder.build();
    final BarListener filter = new BarListener();
    final BarListener filter2 = new BarListener2();
    // ClientRuntime initializes lazily, so it is forced by invoking a (dummy) request
    // instance registered into client
    client.register(filter2);
    // instance registration into target
    client.target(getBaseUri()).register(filter).request().get(String.class);
    assertTrue("Filter was expected to be already initialized.", filter.isInitialized());
    assertTrue("Filter2 was expected to be already initialized.", filter2.isInitialized());
    // class registration into target
    client.target(getBaseUri()).register(FooListener.class).request().get(String.class);
    assertTrue("Class-registered filter was expected to be already initialized", FooListener.isInitialized());
    assertFalse("Class-registered filter was expected to be still open.", FooListener.isClosed());
    assertFalse("Filter was expected to be still open.", filter.isClosed());
    assertFalse("Filter2 was expected to be still open.", filter2.isClosed());
    client.close();
    assertTrue("Class-registered filter was expected to be closed.", FooListener.isClosed());
    assertTrue("Filter was expected to be closed.", filter.isClosed());
    assertTrue("Filter2 was expected to be closed.", filter2.isClosed());
}
Also used : JerseyClient(org.glassfish.jersey.client.JerseyClient) JerseyClientBuilder(org.glassfish.jersey.client.JerseyClientBuilder) JerseyTest(org.glassfish.jersey.test.JerseyTest) 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