Search in sources :

Example 46 with ResteasyWebTarget

use of org.jboss.resteasy.client.jaxrs.ResteasyWebTarget in project wildfly by wildfly.

the class EjbBeanValidationTestCase method testObjectValidationOnSubclassThatExtendsAbstractClass.

@Test
public void testObjectValidationOnSubclassThatExtendsAbstractClass() throws Exception {
    Client client = ClientBuilder.newClient();
    WebTarget target = client.target(url.toURI().toString());
    ResteasyWebTarget rtarget = (ResteasyWebTarget) target;
    EchoResource customerResource = rtarget.proxy(EchoResource.class);
    DummyFlag dummyFlag = rtarget.proxy(DummyFlag.class);
    // Create subclass of DummyAbstractClass with valid values
    DummySubclass validDummySubclass = new DummySubclass();
    validDummySubclass.setDirection("north");
    validDummySubclass.setSpeed(10);
    // Create subclass of DummyAbstractClass with an invalid value (speed should be greater than 0)
    DummySubclass invalidDummySubclass = new DummySubclass();
    invalidDummySubclass.setDirection("north");
    invalidDummySubclass.setSpeed(0);
    Response response = customerResource.validateEchoThroughAbstractClass(validDummySubclass);
    // Verify that we received a Bad Request Code from HTTP
    assertTrue(String.format("Return code should be 200. It was %d", response.getStatus()), 200 == response.getStatus());
    // Verify that the service call has not been executed (flag set to false)
    assertTrue("Executed flag should be true", dummyFlag.getExecutedServiceCallFlag());
    dummyFlag.clearExecution();
    Response response2 = customerResource.validateEchoThroughAbstractClass(invalidDummySubclass);
    // Verify that we received a Bad Request Code from HTTP
    assertTrue(String.format("Return code should either be 400 or 500. It was %d", response2.getStatus()), 400 == response2.getStatus() || 500 == response2.getStatus());
    // Verify that the service call has not been executed (flag set to false)
    assertFalse("Executed flag should be false", dummyFlag.getExecutedServiceCallFlag());
}
Also used : Response(javax.ws.rs.core.Response) ResteasyWebTarget(org.jboss.resteasy.client.jaxrs.ResteasyWebTarget) ResteasyWebTarget(org.jboss.resteasy.client.jaxrs.ResteasyWebTarget) WebTarget(javax.ws.rs.client.WebTarget) Client(javax.ws.rs.client.Client) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) Test(org.junit.Test)

Example 47 with ResteasyWebTarget

use of org.jboss.resteasy.client.jaxrs.ResteasyWebTarget in project wildfly by wildfly.

the class EjbBeanValidationTestCase method testObjectValidationOnConcreteClass.

@Test
public void testObjectValidationOnConcreteClass() throws Exception {
    Client client = ClientBuilder.newBuilder().build();
    WebTarget target = client.target(url.toURI().toString());
    ResteasyWebTarget rtarget = (ResteasyWebTarget) target;
    EchoResource customerResource = rtarget.proxy(EchoResource.class);
    DummyFlag dummyFlag = rtarget.proxy(DummyFlag.class);
    // Create a concrete class with valid values
    DummyClass validDummyClass = new DummyClass();
    validDummyClass.setSpeed(5);
    validDummyClass.setDirection("north");
    // Create a concrete class with invalid values (direction is null and speed is less than 1)
    DummyClass invalidDummyClass = new DummyClass();
    invalidDummyClass.setSpeed(0);
    Response response = customerResource.validateEchoThroughClass(validDummyClass);
    // Verify that we received a Bad Request Code from HTTP
    assertTrue(String.format("Return code should be 200. It was %d", response.getStatus()), 200 == response.getStatus());
    // Verify that the service call has not been executed (flag set to false)
    assertTrue("Executed flag should be true", dummyFlag.getExecutedServiceCallFlag());
    // Reset flag
    dummyFlag.clearExecution();
    Response response2 = customerResource.validateEchoThroughClass(invalidDummyClass);
    // Verify that we received a Bad Request Code from HTTP
    assertTrue(String.format("Return code should either be 400 or 500, it was %d", response2.getStatus()), 400 == response2.getStatus() || 500 == response2.getStatus());
    // Verify that the service call has not been executed (flag set to false)
    assertFalse("Executed flag should be false", dummyFlag.getExecutedServiceCallFlag());
}
Also used : Response(javax.ws.rs.core.Response) ResteasyWebTarget(org.jboss.resteasy.client.jaxrs.ResteasyWebTarget) ResteasyWebTarget(org.jboss.resteasy.client.jaxrs.ResteasyWebTarget) WebTarget(javax.ws.rs.client.WebTarget) Client(javax.ws.rs.client.Client) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) Test(org.junit.Test)

Example 48 with ResteasyWebTarget

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

the class RestEasyClientLiveTest method testAddMovie.

@Test
public void testAddMovie() {
    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.addMovie(transformerMovie);
    if (moviesResponse.getStatus() != Response.Status.CREATED.getStatusCode()) {
        System.out.println("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)

Example 49 with ResteasyWebTarget

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

the class RestEasyClientLiveTest method testUpdateMovie.

@Test
public void testUpdateMovie() {
    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();
    batmanMovie.setTitle("Batman Begins");
    moviesResponse = proxy.updateMovie(batmanMovie);
    if (moviesResponse.getStatus() != Response.Status.OK.getStatusCode()) {
        System.out.println("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)

Example 50 with ResteasyWebTarget

use of org.jboss.resteasy.client.jaxrs.ResteasyWebTarget in project fabric8 by fabric8io.

the class ResteasyGitRepoClient method createWebClient.

/**
 * Creates a JAXRS web client for the given JAXRS client
 */
protected <T> T createWebClient(Class<T> clientType) {
    String address = getAddress();
    ResteasyProviderFactory providerFactory = ResteasyProviderFactory.getInstance();
    providerFactory.register(ResteasyJackson2Provider.class);
    providerFactory.register(Jackson2JsonpInterceptor.class);
    providerFactory.register(StringTextStar.class);
    providerFactory.register(DefaultTextPlain.class);
    providerFactory.register(FileProvider.class);
    providerFactory.register(InputStreamProvider.class);
    providerFactory.register(new Authenticator());
    providerFactory.register(clientType);
    ResteasyClientBuilder builder = new ResteasyClientBuilder();
    builder.providerFactory(providerFactory);
    builder.connectionPoolSize(3);
    Client client = builder.build();
    ResteasyWebTarget target = (ResteasyWebTarget) client.target(address);
    return target.proxy(clientType);
}
Also used : ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) ResteasyWebTarget(org.jboss.resteasy.client.jaxrs.ResteasyWebTarget) ResteasyProviderFactory(org.jboss.resteasy.spi.ResteasyProviderFactory) Client(javax.ws.rs.client.Client)

Aggregations

ResteasyWebTarget (org.jboss.resteasy.client.jaxrs.ResteasyWebTarget)59 ResteasyClient (org.jboss.resteasy.client.jaxrs.ResteasyClient)42 ResteasyClientBuilder (org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder)20 Response (javax.ws.rs.core.Response)13 NotConnectedRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException)10 Test (org.junit.Test)9 WebTarget (javax.ws.rs.client.WebTarget)8 Client (javax.ws.rs.client.Client)7 ServicesInterface (com.baeldung.client.ServicesInterface)6 IOException (java.io.IOException)6 ApacheHttpClient4Engine (org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine)5 ResteasyProviderFactory (org.jboss.resteasy.spi.ResteasyProviderFactory)5 TimeUnit (java.util.concurrent.TimeUnit)4 Invocation (javax.ws.rs.client.Invocation)4 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)4 NotConnectedException (org.ow2.proactive.scheduler.common.exception.NotConnectedException)4 HashMap (java.util.HashMap)3 List (java.util.List)3 Locale (java.util.Locale)3 Map (java.util.Map)3