Search in sources :

Example 1 with Client

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

the class MyResourceTest method setUp.

@Before
public void setUp() throws Exception {
    // start the server
    server = Main.startServer();
    // create the client
    Client c = ClientBuilder.newClient();
    // uncomment the following line if you want to enable
    // support for JSON in the client (you also have to uncomment
    // dependency on jersey-media-json module in pom.xml and Main.startServer())
    // --
    // c.configuration().enable(new org.glassfish.jersey.media.json.JsonJaxbFeature());
    target = c.target(Main.BASE_URI);
}
Also used : Client(javax.ws.rs.client.Client) Before(org.junit.Before)

Example 2 with Client

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

the class AuthTest method testAuthPostWithClientFilter.

@Test
public void testAuthPostWithClientFilter() {
    ClientConfig cc = new ClientConfig();
    cc.connectorProvider(new ApacheConnectorProvider());
    Client client = ClientBuilder.newClient(cc);
    client.register(HttpAuthenticationFeature.basic("name", "password"));
    WebTarget r = client.target(getBaseUri()).path("test/filter");
    assertEquals("POST", r.request().post(Entity.text("POST"), String.class));
}
Also used : WebTarget(javax.ws.rs.client.WebTarget) ClientConfig(org.glassfish.jersey.client.ClientConfig) Client(javax.ws.rs.client.Client) JerseyTest(org.glassfish.jersey.test.JerseyTest) Test(org.junit.Test)

Example 3 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);
}
Also used : Client(javax.ws.rs.client.Client) JerseyTest(org.glassfish.jersey.test.JerseyTest) Test(org.junit.Test)

Example 4 with Client

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

the class HelloWorldTest method testConfigurationUpdate.

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

Example 5 with Client

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

the class HelloWorldTest method _testConnectionPoolSharing.

public void _testConnectionPoolSharing(final boolean sharingEnabled) throws Exception {
    final HttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
    final ClientConfig cc = new ClientConfig();
    cc.property(ApacheClientProperties.CONNECTION_MANAGER, connectionManager);
    cc.property(ApacheClientProperties.CONNECTION_MANAGER_SHARED, sharingEnabled);
    cc.connectorProvider(new ApacheConnectorProvider());
    final Client clientOne = ClientBuilder.newClient(cc);
    WebTarget target = clientOne.target(getBaseUri()).path(ROOT_PATH);
    target.request().get();
    clientOne.close();
    final boolean exceptionExpected = !sharingEnabled;
    final Client clientTwo = ClientBuilder.newClient(cc);
    target = clientTwo.target(getBaseUri()).path(ROOT_PATH);
    try {
        target.request().get();
        if (exceptionExpected) {
            Assert.fail("Exception expected");
        }
    } catch (Exception e) {
        if (!exceptionExpected) {
            Assert.fail("Exception not expected");
        }
    } finally {
        clientTwo.close();
    }
    if (sharingEnabled) {
        connectionManager.shutdown();
    }
}
Also used : WebTarget(javax.ws.rs.client.WebTarget) PoolingHttpClientConnectionManager(org.apache.http.impl.conn.PoolingHttpClientConnectionManager) HttpClientConnectionManager(org.apache.http.conn.HttpClientConnectionManager) ClientConfig(org.glassfish.jersey.client.ClientConfig) Client(javax.ws.rs.client.Client) ConnectionPoolTimeoutException(org.apache.http.conn.ConnectionPoolTimeoutException) IOException(java.io.IOException) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) HttpException(org.apache.http.HttpException) PoolingHttpClientConnectionManager(org.apache.http.impl.conn.PoolingHttpClientConnectionManager)

Aggregations

Client (javax.ws.rs.client.Client)623 Response (javax.ws.rs.core.Response)318 Test (org.junit.Test)273 WebTarget (javax.ws.rs.client.WebTarget)269 ClientConfig (org.glassfish.jersey.client.ClientConfig)131 ClientBuilder (javax.ws.rs.client.ClientBuilder)98 JerseyTest (org.glassfish.jersey.test.JerseyTest)76 Message (com.remswork.project.alice.model.support.Message)58 Invocation (javax.ws.rs.client.Invocation)44 IOException (java.io.IOException)43 Builder (javax.ws.rs.client.Invocation.Builder)41 RunAsClient (org.jboss.arquillian.container.test.api.RunAsClient)41 URL (java.net.URL)39 List (java.util.List)36 Test (org.junit.jupiter.api.Test)34 ClientResponse (org.glassfish.jersey.client.ClientResponse)27 WebClient (org.apache.cxf.jaxrs.client.WebClient)26 JerseyClientBuilder (io.dropwizard.client.JerseyClientBuilder)25 GenericType (javax.ws.rs.core.GenericType)25 Before (org.junit.Before)24