Package org.jboss.resteasy.client

Examples of org.jboss.resteasy.client.ClientRequest


      return new ClientRequest(uriTemplate, this);
   }

   public ClientRequest createRequest(UriBuilder uriBuilder)
   {
      return new ClientRequest(uriBuilder, this);
   }
View Full Code Here


   @Test
   public void testPopulateDB() throws Exception
   {
      String url = "http://localhost:9095/shop";
      ClientRequest request = new ClientRequest("http://localhost:9095/shop");
      ClientResponse response = request.head();
      Map<String, Link> shoppingLinks = processLinkHeaders(response);

      System.out.println("** Populate Products");
      request = new ClientRequest(shoppingLinks.get("products").getHref());

      Product product = new Product();
      product.setName("iPhone");
      product.setCost(199.99);
      request.body("application/xml", product);
      response = request.post();
      response.releaseConnection();
      Assert.assertEquals(201, response.getStatus());

      product = new Product();
      product.setName("MacBook Pro");
      product.setCost(3299.99);
      request.body("application/xml", product);
      response = request.post();
      response.releaseConnection();
      Assert.assertEquals(201, response.getStatus());

      product = new Product();
      product.setName("iPod");
      product.setCost(49.99);
      request.body("application/xml", product);
      response = request.post();
      response.releaseConnection();
      Assert.assertEquals(201, response.getStatus());

   }
View Full Code Here

   @Test
   public void testCreateOrder() throws Exception
   {
      String url = "http://localhost:9095/shop";
      ClientRequest request = new ClientRequest("http://localhost:9095/shop");
      ClientResponse response = request.head();
      Map<String, Link> shoppingLinks = processLinkHeaders(response);

      System.out.println("** Buy an iPhone for Bill Burke");
      System.out.println();
      System.out.println("** First see if Bill Burke exists as a customer");
      request = new ClientRequest(shoppingLinks.get("customers").getHref() + "?firstName=Bill&lastName=Burke");
      Customers customers = request.getTarget(Customers.class);
      Customer customer = null;
      if (customers.getCustomers().size() > 0)
      {
         System.out.println("- Found a Bill Burke in the database, using that");
         customer = customers.getCustomers().iterator().next();
      }
      else
      {
         System.out.println("- Cound not find a Bill Burke in the database, creating one.");
         customer = new Customer();
         customer.setFirstName("Bill");
         customer.setLastName("Burke");
         customer.setStreet("222 Dartmouth Street");
         customer.setCity("Boston");
         customer.setState("MA");
         customer.setZip("02115");
         customer.setCountry("USA");
         request = new ClientRequest(shoppingLinks.get("customers").getHref());
         request.body("application/xml", customer);
         response = request.post();
         Assert.assertEquals(201, response.getStatus());
         String uri = (String) response.getHeaders().getFirst("Location");

         request = new ClientRequest(uri);
         customer = request.getTarget(Customer.class);
      }

      System.out.println();
      System.out.println("Search for iPhone in the Product database");
      request = new ClientRequest(shoppingLinks.get("products").getHref() + "?name=iPhone");
      Products products = request.getTarget(Products.class);
      Product product = null;
      if (products.getProducts().size() > 0)
      {
         System.out.println("- Found iPhone in the database.");
         product = products.getProducts().iterator().next();
      }
      else
      {
         throw new RuntimeException("Failed to find an iPhone in the database!");
      }

      System.out.println();
      System.out.println("** Create Order for iPhone");
      LineItem item = new LineItem();
      item.setProduct(product);
      item.setQuantity(1);
      Order order = new Order();
      order.setTotal(product.getCost());
      order.setCustomer(customer);
      order.setDate(new Date().toString());
      order.getLineItems().add(item);
      request = new ClientRequest(shoppingLinks.get("orders").getHref());
      request.body("application/xml", order);
      response = request.post();
      Assert.assertEquals(201, response.getStatus());

      System.out.println();
      System.out.println("** Show all orders.");
      request = new ClientRequest(shoppingLinks.get("orders").getHref());
      String xml = request.getTarget(String.class);
      System.out.println(xml);


   }
View Full Code Here

      }
   }

   public ClientRequest createRequest(String uriTemplate)
   {
      return new ClientRequest(uriTemplate, this);
   }
View Full Code Here

      return new ClientRequest(uriTemplate, this);
   }

   public ClientRequest createRequest(UriBuilder uriBuilder)
   {
      return new ClientRequest(uriBuilder, this);
   }
View Full Code Here

{
   @Test
   public void testAll() throws Exception
   {
      RegisterBuiltin.register(ResteasyProviderFactory.getInstance());
      ClientRequest request = new ClientRequest("http://localhost:8080/scanning-test/test/doit");
      ClientResponse response = request.get();
      Assert.assertEquals(200, response.getStatus());
      Assert.assertEquals("hello world", response.getEntity(String.class));
   }
View Full Code Here

   }

   @Test
   public void testRelativeLink() throws Exception
   {
      ClientRequest request = new ClientRequest(generateURL("/products/333"));
      ClientResponse<Product> response = request.get(Product.class);
      Product product = response.getEntity();
      Assert.assertEquals(product.getLinks().get(0).getHref().getPath(), "/products/333/self");
      Assert.assertEquals(product.getLinks().get(1).getHref().getPath(), "/products");
      System.out.println();
   }
View Full Code Here

   }

   @Test
   public void testRelativeLink2() throws Exception
   {
      ClientRequest request = new ClientRequest(generateURL("/products/333"));
      ClientResponse<String> response = request.get(String.class);
      System.out.println(response.getEntity());
   }
View Full Code Here

{
   @Test
   public void testCustomerResource() throws Exception
   {
      //RegisterBuiltin.register(ResteasyProviderFactory.getInstance());
      ClientRequest request = new ClientRequest("http://localhost:9095/customers/1");
      ClientResponse<Customer> response = request.get(Customer.class);
      Assert.assertEquals(200, response.getStatus());
      Customer cust = response.getEntity();

      String etag = response.getHeaders().getFirst("ETag");
      System.out.println("Doing a conditional GET with ETag: " + etag);
      request.clear();
      request.header("If-None-Match", etag);
      response = request.get(Customer.class);
      Assert.assertEquals(304, response.getStatus());

      // Update and send a bad etag with conditional PUT
      cust.setCity("Bedford");
      request.clear();
      request.header("If-Match", "JUNK");
      request.body("application/xml", cust);
      ClientResponse response2 = request.put();
      Assert.assertEquals(412, response2.getStatus());
   }
View Full Code Here

   {
      Verifier verifier = new Verifier();
      Verification verification = verifier.addNew();
      verification.setRepository(repository);

      ClientRequest request = new ClientRequest("http://localhost:9095/signed");
      ClientResponse<String> response = request.get(String.class);
      response.getAttributes().put(Verifier.class.getName(), verifier);

      System.out.println(response.getHeaders().getFirst(DKIMSignature.DKIM_SIGNATURE));
      Assert.assertEquals(200, response.getStatus());
View Full Code Here

TOP

Related Classes of org.jboss.resteasy.client.ClientRequest

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.