Package org.jboss.resteasy.client.jaxrs

Examples of org.jboss.resteasy.client.jaxrs.ResteasyClient


public class CustomerDatabaseClient
{
   public static List<String> getCustomers(HttpServletRequest request)
   {
      SkeletonKeySession session = (SkeletonKeySession)request.getAttribute(SkeletonKeySession.class.getName());
      ResteasyClient client = new ResteasyClientBuilder()
                 .trustStore(session.getMetadata().getTruststore())
                 .hostnameVerification(ResteasyClientBuilder.HostnameVerificationPolicy.ANY).build();
      try
      {
         Response response = client.target("https://localhost:8443/database/customers").request()
                 .header(HttpHeaders.AUTHORIZATION, "Bearer " + session.getToken()).get();
         return response.readEntity(new GenericType<List<String>>(){});
      }
      finally
      {
         client.close();
      }
   }
View Full Code Here


public class EchoTest
{
   @Test
   public void testUser() throws Exception
   {
      ResteasyClient client = new ResteasyClient();
      WebTarget keystoneServer = client.target("http://localhost:8080/keystone-server");
      SkeletonKeyAdminClient admin = new SkeletonKeyClientBuilder().username("admin").password("geheim").idp(keystoneServer).admin();
      User user = admin.users().get("1");
      System.out.println(user);
   }
View Full Code Here

   }

   @Test
   public void testUserSigned() throws Exception
   {
      ResteasyClient client = new ResteasyClient();
      WebTarget keystoneServer = client.target("http://localhost:8080/keystone-server");
      ResteasyWebTarget adminServerTarget = client.target("http://localhost:8080/keystone-server");
      String token = new SkeletonKeyClientBuilder().username("admin").password("geheim").idp(keystoneServer).signed("Keystone", adminServerTarget);
      System.out.println("token: " + token);
      Mappers.registerContextResolver(adminServerTarget.configuration());
      SkeletonKeyAdminClient admin = adminServerTarget.proxy(SkeletonKeyAdminClient.class);
      User user = admin.users().get("1");
View Full Code Here

   @Test
   public void testRole()
   {
      String newRole = "{ \"role\" : { \"name\" : \"admin\"} }";
      ResteasyClient client = new ResteasyClientBuilder().providerFactory(deployment.getProviderFactory()).build();
      Response response = client.target(generateURL("/roles")).request().post(Entity.json(newRole));
      Assert.assertEquals(response.getStatus(), 201);
      response.close();
      ResteasyWebTarget target = client.target(response.getLocation());
      String role = target.request().get(String.class);
      System.out.println(role);
      Role u = target.request().get(Role.class);
      System.out.println(u);
      Assert.assertEquals("admin", u.getName());
      Assert.assertEquals(target.request().delete().getStatus(), 204);
      response = target.request().get();
      Assert.assertEquals(404, response.getStatus());
      client.close();
   }
View Full Code Here

   }

   @Test
   public void testRoleText()
   {
      ResteasyClient client = new ResteasyClientBuilder().providerFactory(deployment.getProviderFactory()).build();
      Response response = client.target(generateURL("/roles")).request().post(Entity.text("admin"));
      Assert.assertEquals(response.getStatus(), 201);
      response.close();
      ResteasyWebTarget target = client.target(response.getLocation());
      String role = target.request().get(String.class);
      System.out.println(role);
      Role u = target.request().get(Role.class);
      System.out.println(u);
      Assert.assertEquals("admin", u.getName());
      Assert.assertEquals(target.request().delete().getStatus(), 204);
      response = target.request().get();
      Assert.assertEquals(404, response.getStatus());
      client.close();
   }
View Full Code Here

   @Test
   public void testRoleId()
   {
      String newRole = "{ \"role\" : { \"id\" : \"5\", \"name\" : \"admin\"} }";
      ResteasyClient client = new ResteasyClientBuilder().providerFactory(deployment.getProviderFactory()).build();
      Response response = client.target(generateURL("/roles")).request().post(Entity.json(newRole));
      Assert.assertEquals(response.getStatus(), 201);
      response.close();
      ResteasyWebTarget target = client.target(response.getLocation());
      String role = target.request().get(String.class);
      System.out.println(role);
      Role u = target.request().get(Role.class);
      System.out.println(u);
      Assert.assertEquals("admin", u.getName());
      Assert.assertEquals("5", u.getId());
      u.setName("administrator");
      Assert.assertEquals(target.request().put(Entity.json(u)).getStatus(), 204);
      u = target.request().get(Role.class);
      System.out.println(u);
      Assert.assertEquals("administrator", u.getName());
      Assert.assertEquals("5", u.getId());
      Assert.assertEquals(target.request().delete().getStatus(), 204);
      response = target.request().get();
      Assert.assertEquals(404, response.getStatus());
      client.close();
   }
View Full Code Here

*/
public class ProductDatabaseClient
{
   public static List<String> getProducts()
   {
      ResteasyClient client = new ResteasyClientBuilder()
                 .disableTrustManager() // shouldn't really do this, but I'm being lazy
                 .build();

      Form form = new Form().param("grant_type", "client_credentials");
      ResteasyWebTarget target = client.target("https://localhost:8443/auth-server/j_oauth_token_grant");
      // this is resteasy specific, check spec to make sure it hasn't added a way to do basic auth
      target.register(new BasicAuthentication("bburke@redhat.com", "password"));
      AccessTokenResponse res = target
              .request()
              .post(Entity.form(form), AccessTokenResponse.class);
      try
      {
         Response response = client.target("https://localhost:8443/database/products").request()
                 .header(HttpHeaders.AUTHORIZATION, "Bearer " + res.getToken()).get();
         return response.readEntity(new GenericType<List<String>>(){});
      }
      finally
      {
         client.close();
      }
   }
View Full Code Here

   }

   @Test
   public void testProxy() throws Exception
   {
      ResteasyClient client = new ResteasyClientBuilder().build();
      // or you can do...
      // ResteasyClient client = (ResteasyClient)ClientBuilder.newClient();
      CustomerProxy proxy = client.target("http://localhost:9095").proxy(CustomerProxy.class);
      Customer cust = proxy.getCustomer("Monica");
      Assert.assertEquals("Monica", cust.getName());
      client.close();
   }
View Full Code Here

   @Path("signed/text")
   @Produces("text/plain")
   public SignedOutput getText()
   {
      // just allocate a client to test that resteasy client is available and Apache HC4 is exposed.
      ResteasyClient client = new ResteasyClientBuilder().build();
      ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager();
      cm.setMaxTotal(100);
      cm.setDefaultMaxPerRoute(100);
      HttpClient httpClient = new DefaultHttpClient(cm);
View Full Code Here

   }

   @Test
   public void testAllValid() throws Exception
   {
      ResteasyClient client = new ResteasyClientBuilder().build();
      Invocation.Builder request = client.target("http://localhost:8080/RESTEASY-1008/input/11/13/17").request();
      Response response = request.get();
      int answer = response.readEntity(int.class);
      log.info("status: " + response.getStatus());
      log.info("entity: " + answer);
      assertEquals(200, response.getStatus());
View Full Code Here

TOP

Related Classes of org.jboss.resteasy.client.jaxrs.ResteasyClient

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.