Search in sources :

Example 1 with ResteasyClient

use of org.jboss.resteasy.client.jaxrs.ResteasyClient in project dubbo by alibaba.

the class RestProtocol method destroy.

public void destroy() {
    super.destroy();
    if (connectionMonitor != null) {
        connectionMonitor.shutdown();
    }
    for (Map.Entry<String, RestServer> entry : servers.entrySet()) {
        try {
            if (logger.isInfoEnabled()) {
                logger.info("Closing the rest server at " + entry.getKey());
            }
            entry.getValue().stop();
        } catch (Throwable t) {
            logger.warn("Error closing rest server", t);
        }
    }
    servers.clear();
    if (logger.isInfoEnabled()) {
        logger.info("Closing rest clients");
    }
    for (ResteasyClient client : clients) {
        try {
            client.close();
        } catch (Throwable t) {
            logger.warn("Error closing rest client", t);
        }
    }
    clients.clear();
}
Also used : ResteasyClient(org.jboss.resteasy.client.jaxrs.ResteasyClient) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 2 with ResteasyClient

use of org.jboss.resteasy.client.jaxrs.ResteasyClient in project wildfly-swarm by wildfly-swarm.

the class ZipkinJAXRSTest method testSpanLogging.

@Test
public void testSpanLogging() throws Exception {
    ResteasyClient client = (ResteasyClient) ResteasyClientBuilder.newClient();
    client.register(ClientRequestInterceptor.class);
    client.register(ClientResponseInterceptor.class);
    Response response = client.target("http://localhost:8080").request(MediaType.TEXT_PLAIN).get();
    Assert.assertEquals(200, response.getStatus());
    // check log file for span reporting & the specified service name
    // the default zipkin fraction logs to system out
    List<String> logContent = Files.readAllLines(Paths.get(LOG_FILE));
    boolean spanPresent = logContent.stream().anyMatch(line -> line.contains(SPAN_COLLECTOR));
    Assert.assertTrue("Span logging missing from log file", spanPresent);
    boolean serviceNamePresent = logContent.stream().anyMatch(line -> line.contains(SERVICE_NAME));
    Assert.assertTrue("Service name " + SERVICE_NAME + " missing from log file", serviceNamePresent);
}
Also used : Response(javax.ws.rs.core.Response) ResteasyClient(org.jboss.resteasy.client.jaxrs.ResteasyClient) Test(org.junit.Test)

Example 3 with ResteasyClient

use of org.jboss.resteasy.client.jaxrs.ResteasyClient in project tutorials by eugenp.

the class RestEasyClientLiveTest method testAddMovieMultiConnection.

@Test
public void testAddMovieMultiConnection() {
    final PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
    final CloseableHttpClient httpClient = HttpClients.custom().setConnectionManager(cm).build();
    final ApacheHttpClient4Engine engine = new ApacheHttpClient4Engine(httpClient);
    final ResteasyClient client = new ResteasyClientBuilder().httpEngine(engine).build();
    final ResteasyWebTarget target = client.target(FULL_PATH);
    final ServicesInterface proxy = target.proxy(ServicesInterface.class);
    final Response batmanResponse = proxy.addMovie(batmanMovie);
    final Response transformerResponse = proxy.addMovie(transformerMovie);
    if (batmanResponse.getStatus() != Response.Status.CREATED.getStatusCode()) {
        System.out.println("Batman Movie creation Failed : HTTP error code : " + batmanResponse.getStatus());
    }
    if (batmanResponse.getStatus() != Response.Status.CREATED.getStatusCode()) {
        System.out.println("Batman Movie creation Failed : HTTP error code : " + batmanResponse.getStatus());
    }
    batmanResponse.close();
    transformerResponse.close();
    cm.close();
}
Also used : Response(javax.ws.rs.core.Response) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) ResteasyClient(org.jboss.resteasy.client.jaxrs.ResteasyClient) ApacheHttpClient4Engine(org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine) ResteasyWebTarget(org.jboss.resteasy.client.jaxrs.ResteasyWebTarget) ServicesInterface(com.baeldung.client.ServicesInterface) PoolingHttpClientConnectionManager(org.apache.http.impl.conn.PoolingHttpClientConnectionManager) Test(org.junit.Test)

Example 4 with ResteasyClient

use of org.jboss.resteasy.client.jaxrs.ResteasyClient in project tutorials by eugenp.

the class RestEasyClientLiveTest method testListAllMovies.

@Test
public void testListAllMovies() {
    final ResteasyClient client = new ResteasyClientBuilder().build();
    final ResteasyWebTarget target = client.target(FULL_PATH);
    final ServicesInterface proxy = target.proxy(ServicesInterface.class);
    Response moviesResponse = proxy.addMovie(transformerMovie);
    moviesResponse.close();
    moviesResponse = proxy.addMovie(batmanMovie);
    moviesResponse.close();
    final List<Movie> movies = proxy.listMovies();
    System.out.println(movies);
}
Also used : Response(javax.ws.rs.core.Response) ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) Movie(com.baeldung.model.Movie) ResteasyClient(org.jboss.resteasy.client.jaxrs.ResteasyClient) ResteasyWebTarget(org.jboss.resteasy.client.jaxrs.ResteasyWebTarget) ServicesInterface(com.baeldung.client.ServicesInterface) Test(org.junit.Test)

Example 5 with ResteasyClient

use of org.jboss.resteasy.client.jaxrs.ResteasyClient in project tutorials by eugenp.

the class RestEasyClientLiveTest method testDeleteMovie.

@Test
public void testDeleteMovie() {
    final ResteasyClient client = new ResteasyClientBuilder().build();
    final ResteasyWebTarget target = client.target(FULL_PATH);
    final ServicesInterface proxy = target.proxy(ServicesInterface.class);
    Response moviesResponse = proxy.addMovie(batmanMovie);
    moviesResponse.close();
    moviesResponse = proxy.deleteMovie(batmanMovie.getImdbId());
    if (moviesResponse.getStatus() != Response.Status.OK.getStatusCode()) {
        System.out.println(moviesResponse.readEntity(String.class));
        throw new RuntimeException("Failed : HTTP error code : " + moviesResponse.getStatus());
    }
    moviesResponse.close();
    System.out.println("Response Code: " + moviesResponse.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) ResteasyClient(org.jboss.resteasy.client.jaxrs.ResteasyClient) ResteasyWebTarget(org.jboss.resteasy.client.jaxrs.ResteasyWebTarget) ServicesInterface(com.baeldung.client.ServicesInterface) Test(org.junit.Test)

Aggregations

ResteasyClient (org.jboss.resteasy.client.jaxrs.ResteasyClient)56 ResteasyWebTarget (org.jboss.resteasy.client.jaxrs.ResteasyWebTarget)41 ResteasyClientBuilder (org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder)23 Response (javax.ws.rs.core.Response)11 NotConnectedRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException)10 Test (org.junit.Test)9 ServicesInterface (com.baeldung.client.ServicesInterface)6 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)6 NotConnectedException (org.ow2.proactive.scheduler.common.exception.NotConnectedException)6 ProcessingException (javax.ws.rs.ProcessingException)5 ApacheHttpClient4Engine (org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine)5 Map (java.util.Map)4 RequestConfig (org.apache.http.client.config.RequestConfig)4 PoolingHttpClientConnectionManager (org.apache.http.impl.conn.PoolingHttpClientConnectionManager)4 ClientHttpEngine (org.jboss.resteasy.client.jaxrs.ClientHttpEngine)4 IOException (java.io.IOException)3 Locale (java.util.Locale)3 WebApplicationException (javax.ws.rs.WebApplicationException)3 ApacheHttpClient4Resource (org.jboss.additional.testsuite.jdkall.present.jaxrs.client.resource.ApacheHttpClient4Resource)3 ApacheHttpClient43Engine (org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient43Engine)3