Package org.jboss.resteasy.client.jaxrs

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


   }

   @Test
   public void testThrowsException() throws Exception
   {
      ResteasyClient client = new ResteasyClientBuilder().build();

      ThrowsExceptionInterface proxy = client.target(generateURL("/")).proxy(ThrowsExceptionInterface.class);
      try {
          proxy.post();
      } catch (InternalServerErrorException e) {
          Response response = e.getResponse();
          String errorText = response.readEntity(String.class);
         System.out.println(errorText);
          Assert.assertNotNull(errorText);
      }

      client.close();
   }
View Full Code Here


   }

   @Test
   public void testMethods() throws Exception
   {
      ResteasyClient client = new ResteasyClientBuilder().build();

      {
         Response res = client.target(generateURL("/test")).request().get();
         Assert.assertEquals(200, res.getStatus());
         String entity = res.readEntity(String.class);
         Assert.assertEquals("get", entity);

      }

      {
         String entity = client.target(generateURL("/test")).request().get(String.class);
         Assert.assertEquals("get", entity);

      }

      {
         Response res = client.target(generateURL("/test")).request().delete();
         Assert.assertEquals(200, res.getStatus());
         String entity = res.readEntity(String.class);
         Assert.assertEquals("delete", entity);

      }

      {
         String entity = client.target(generateURL("/test")).request().delete(String.class);
         Assert.assertEquals("delete", entity);

      }
      {
          Response res = client.target(generateURL("/test")).request().put(Entity.text("hello"));
          Assert.assertEquals(200, res.getStatus());
          String entity = res.readEntity(String.class);
          Assert.assertEquals("put hello", entity);

       }
      {
         String entity = client.target(generateURL("/test")).request().put(Entity.text("hello"), String.class);
         Assert.assertEquals("put hello", entity);

      }

      {
          Response res = client.target(generateURL("/test")).request().post(Entity.text("hello"));
          Assert.assertEquals(200, res.getStatus());
          String entity = res.readEntity(String.class);
          Assert.assertEquals("post hello", entity);

       }
      {
         String entity = client.target(generateURL("/test")).request().post(Entity.text("hello"), String.class);
         Assert.assertEquals("post hello", entity);

      }

      {
          Response res = client.target(generateURL("/test")).request().method("PATCH", Entity.text("hello"));
          Assert.assertEquals(200, res.getStatus());
          String entity = res.readEntity(String.class);
          Assert.assertEquals("patch hello", entity);

       }
      {
         String entity = client.target(generateURL("/test")).request().method("PATCH", Entity.text("hello"), String.class);
         Assert.assertEquals("patch hello", entity);

      }
      client.close();
   }
View Full Code Here

   }

   @Test
   public void testInvoke() throws Exception
   {
      ResteasyClient client = new ResteasyClientBuilder().build();

      {
         Response res = client.target(generateURL("/test")).request().buildGet().invoke();
         Assert.assertEquals(200, res.getStatus());
         String entity = res.readEntity(String.class);
         Assert.assertEquals("get", entity);

      }

      {
         String entity = client.target(generateURL("/test")).request().buildGet().invoke(String.class);
         Assert.assertEquals("get", entity);

      }

      {
         Response res = client.target(generateURL("/test")).request().buildDelete().invoke();
         Assert.assertEquals(200, res.getStatus());
         String entity = res.readEntity(String.class);
         Assert.assertEquals("delete", entity);

      }

      {
         String entity = client.target(generateURL("/test")).request().buildDelete().invoke(String.class);
         Assert.assertEquals("delete", entity);

      }
      {
          Response res = client.target(generateURL("/test")).request().buildPut(Entity.text("hello")).invoke();
          Assert.assertEquals(200, res.getStatus());
          String entity = res.readEntity(String.class);
          Assert.assertEquals("put hello", entity);

       }
      {
         String entity = client.target(generateURL("/test")).request().buildPut(Entity.text("hello")).invoke(String.class);
         Assert.assertEquals("put hello", entity);

      }

      {
          Response res = client.target(generateURL("/test")).request().buildPost(Entity.text("hello")).invoke();
          Assert.assertEquals(200, res.getStatus());
          String entity = res.readEntity(String.class);
          Assert.assertEquals("post hello", entity);

       }
      {
         String entity = client.target(generateURL("/test")).request().buildPost(Entity.text("hello")).invoke(String.class);
         Assert.assertEquals("post hello", entity);

      }

      {
          Response res = client.target(generateURL("/test")).request().build("PATCH", Entity.text("hello")).invoke();
          Assert.assertEquals(200, res.getStatus());
          String entity = res.readEntity(String.class);
          Assert.assertEquals("patch hello", entity);

       }
      {
         String entity = client.target(generateURL("/test")).request().build("PATCH", Entity.text("hello")).invoke(String.class);
         Assert.assertEquals("patch hello", entity);

      }
      client.close();
   }
View Full Code Here

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

   }

    @Test
    public void test() throws Exception
    {
       ResteasyClient client = new ResteasyClientBuilder().build();
        WebTarget target = client.target("http://localhost:8081/test/one/");
        System.out.println("Sending request");
        Response response = target.request().get();
       String entity = response.readEntity(String.class);
       System.out.println("Received response: " + entity);
        Assert.assertEquals(200, response.getStatus());
        Assert.assertTrue("Type property is missing.", entity.contains("type"));
       response.close();

       target = client.target("http://localhost:8081/test/list/");
        System.out.println("Sending request");
        response = target.request().get();
        entity = response.readEntity(String.class);
       System.out.println("Received response: " + entity);
        Assert.assertEquals(200, response.getStatus());
        Assert.assertTrue("Type property is missing.", entity.contains("type"));
       response.close();
       client.close();
    }
View Full Code Here

//   @Test
   public void testDispatchStatic() throws Exception
   {
      log.info("starting testFilter()");
      ResteasyClient client = new ResteasyClientBuilder().build();
      Invocation.Builder request = client.target("http://localhost:8080/RESTEASY-903/test/dispatch/static").request();
      Response response = request.get();
      log.info("Status: " + response.getStatus());
      log.info("result: " + response.readEntity(String.class));
      assertEquals(200, response.getStatus());
   }
View Full Code Here

   @Test
   public void testDispatchDynamic() throws Exception
   {
      log.info("starting testFilter()");
      ResteasyClient client = new ResteasyClientBuilder().build();
      Invocation.Builder request = client.target("http://localhost:8080/RESTEASY-903/test/dispatch/dynamic").request();
      Response response = request.get();
      String result = response.readEntity(String.class);
      log.info("Status: " + response.getStatus());
      log.info("result: " + result);
      assertEquals(200, response.getStatus());
View Full Code Here

public class SayHelloTest {

     @Test
     public void testEcho()
     {
       ResteasyClient client = new ResteasyClientBuilder().build();
       ResteasyWebTarget target = client.target("http://localhost:9095");
       HelloString proxy = target.proxy(HelloString.class);
       String hello = proxy.sayHi("hello");
       Assert.assertEquals("hello", hello);
     }
View Full Code Here

   private static final String SPACES_REQUEST = "something something";

   @Test
   public void testEcho()
   {
      ResteasyClient client = new ResteasyClientBuilder().build();
      HelloClient proxy = client.target(generateBaseUrl()).proxy(HelloClient.class);
      Assert.assertEquals(SPACES_REQUEST, proxy.sayHi(SPACES_REQUEST));
      client.close();
   }
View Full Code Here

   @Test
   public void testInvalidMediaTypes() throws Exception
   {
      before();
      ResteasyClient client = new ResteasyClientBuilder().build();
      Invocation.Builder request = client.target(TestPortProvider.generateURL("/test")).request();
     
      // Missing type or subtype
      doTest(request, "/");
      doTest(request, "/*");
      doTest(request, "*/");
      doTest(request, "text/");
      doTest(request, "/plain");
     
      // Illegal white space
      doTest(request, " /*");
      doTest(request, "/* ");
      doTest(request, " /* ");
      doTest(request, "/ *");
      doTest(request, "* /");
      doTest(request, " / *");
      doTest(request, "* / ");
      doTest(request, "* / *");
      doTest(request, " * / *");
      doTest(request, "* / * ");
      doTest(request, "text/ plain");
      doTest(request, "text /plain");
      doTest(request, " text/plain");
      doTest(request, "text/plain ");
      doTest(request, " text/plain ");
      doTest(request, " text / plain ");
      client.close();
      after();
   }
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.