Package org.jboss.resteasy.client.jaxrs

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


   }

   @Test
   public void testClientResponse() throws Exception
   {
      ResteasyClient resteasyClient = new ResteasyClientBuilder().build();
      Client client = ProxyBuilder.builder(Client.class, resteasyClient.target(generateBaseUrl())).build();

      Assert.assertEquals("hello", client.getAsString());
      Response is = client.getAsInputStream();
      Assert.assertEquals("hello", new String(ReadFromStream.readFromStream(
              1024, is.readEntity(InputStream.class))));
      is.close();
      client.postString("new value");
      Assert.assertEquals("new value", client.getAsString());
      client.postInputStream(new ByteArrayInputStream("new value 2".getBytes()));
      Assert.assertEquals("new value 2", client.getAsString());
      resteasyClient.close();

   }
View Full Code Here


   }

   @Test
   public void testPreflight() throws Exception
   {
      ResteasyClient client = new ResteasyClientBuilder().build();
      WebTarget target = client.target(TestPortProvider.generateURL("/test"));
      Response response = target.request().header(CorsHeaders.ORIGIN, "http://localhost")
              .options();
      Assert.assertEquals(403, response.getStatus());
      response.close();
      response = target.request().header(CorsHeaders.ORIGIN, "http://localhost")
              .get();
      Assert.assertEquals(403, response.getStatus());
      response.close();
      corsFilter.getAllowedOrigins().add("http://localhost");
      response = target.request().header(CorsHeaders.ORIGIN, "http://localhost")
                                 .options();
      Assert.assertEquals(200, response.getStatus());
      response.close();
      response = target.request().header(CorsHeaders.ORIGIN, "http://localhost")
              .get();
      Assert.assertEquals(200, response.getStatus());
      Assert.assertEquals(response.getHeaderString(CorsHeaders.ACCESS_CONTROL_ALLOW_ORIGIN), "http://localhost");
      Assert.assertEquals("hello", response.readEntity(String.class));
      response.close();




      client.close();
   }
View Full Code Here

   }

   @Test
   public void testIt() throws Exception
   {
      ResteasyClient client = new ResteasyClientBuilder().providerFactory(deployment.getProviderFactory()).build();
      MyClient proxy = client.target(generateBaseUrl()).proxy(MyClient.class);
      proxy.put("pojo", "pojo", "pojo", "pojo");
      client.close();
   }
View Full Code Here

   }

   @Test
   public void testDefault() throws Exception
   {
      ResteasyClient client = new ResteasyClientBuilder().providerFactory(deployment.getProviderFactory()).build();
      MyDefaultClient proxy = client.target(generateBaseUrl()).proxy(MyDefaultClient.class);
      proxy.put();
      client.close();
   }
View Full Code Here

   }

   @Test
   public void testMe2() throws Exception
   {
      ResteasyClient client = new ResteasyClientBuilder().build();
      Invocation.Builder request = client.target(generateURL("/fromstring/ORANGE/football")).request();
      System.out.println(request.get(String.class));
      client.close();
   }
View Full Code Here

    * Verifies that a more specific media type is preferred.
    */
   @Test
   public void testVariant() throws Exception
   {
      ResteasyClient client = new ResteasyClientBuilder().build();
      Invocation.Builder request = client.target(TestPortProvider.generateURL("/variant")).request();
      request.accept(MediaType.WILDCARD_TYPE);
      request.accept(MediaType.TEXT_HTML_TYPE);
      Response response = request.get();
      Assert.assertEquals(200, response.getStatus());
      String entity = response.readEntity(String.class);
View Full Code Here

    * Verifies that the number of parameters does not outweigh more specific media types.
    */
   @Test
   public void testVariantWithParameters() throws Exception
   {
      ResteasyClient client = new ResteasyClientBuilder().build();
      Invocation.Builder request = client.target(TestPortProvider.generateURL("/params")).request();
      request.accept(WILDCARD_WITH_PARAMS);
      request.accept(MediaType.TEXT_HTML_TYPE);
      Response response = request.get();
      Assert.assertEquals(200, response.getStatus());
      String entity = response.readEntity(String.class);
View Full Code Here


   @Test
   public void testProxy() throws Exception
   {
      ResteasyClient client = new ResteasyClientBuilder().build();
      ResteasyWebTarget target = client.target(generateBaseUrl());
      IGZIP proxy = target.proxy(IGZIP.class);
      Assert.assertEquals("HELLO WORLD", proxy.getText());
      Assert.assertEquals("HELLO WORLD", proxy.getGzipText());

      // resteasy-651
      try
      {
         String error = proxy.getGzipErrorText();
         Assert.fail("unreachable");
      }
      catch (WebApplicationException failure)
      {
         Assert.assertEquals(500, failure.getResponse().getStatus());
         String txt = (String) failure.getResponse().readEntity(String.class);
         Assert.assertEquals("Hello", txt);
      }
      finally
      {
         client.close();
      }
   }
View Full Code Here

    * @throws Exception
    */
   @Test
   public void testContentLength() throws Exception
   {
      ResteasyClient client = new ResteasyClientBuilder().build();
      {
         WebTarget target = client.target(TestPortProvider.generateURL("/text"));
         Response response = target.request().get();
         Assert.assertEquals("HELLO WORLD", response.readEntity(String.class));
         String cl = response.getHeaderString("Content-Length");
         if (cl != null)
         {
            // make sure the content length is greater than 11 because this will be a gzipped encoding
         Assert.assertTrue(response.getLength() > 11);
         }
      }
      {
         WebTarget target = client.target(TestPortProvider.generateURL("/bytes"));
         Response response = target.request().acceptEncoding("gzip").get();
         String cl = response.getHeaderString("Content-Length");
         if (cl != null)
         {
            // make sure the content length is greater than 11 because this will be a gzipped encoding
            int i = response.getLength();
            System.out.println("***");
            System.out.println("Content-Length: " + i);
            System.out.println("***");
            Assert.assertTrue(i > 11);
         }
         Assert.assertEquals("HELLO WORLD", response.readEntity(String.class));
      }
      client.close();
   }
View Full Code Here

   }

   @Test
   public void testRequestError() throws Exception
   {
      ResteasyClient client = new ResteasyClientBuilder().build();
      WebTarget target = client.target(TestPortProvider.generateURL("/error"));
      Response response = target.request().get();
      Assert.assertEquals(405, response.getStatus());
      client.close();

   }
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.