Examples of ClientResponse


Examples of org.jboss.resteasy.client.ClientResponse

   @Test
   public void testMapper() throws Exception
   {
      ClientRequest request = new ClientRequest(generateBaseUrl() + "/test");
      ClientResponse response = request.get();
      Assert.assertEquals(Response.Status.PRECONDITION_FAILED.getStatusCode(), response.getStatus());
   }
View Full Code Here

Examples of org.jboss.resteasy.client.ClientResponse

   @Test
   public void testMapper() throws Exception
   {
      ClientRequest request = new ClientRequest(TestPortProvider.generateURL("/interception"));
      ClientResponse res = request.get();
      Assert.assertEquals(412, res.getStatus());

   }
View Full Code Here

Examples of org.jboss.resteasy.client.ClientResponse

      contentSignature.setDomain("client.com");
      request.getAttributes().put(KeyRepository.class.getName(), repository);

      request.header(DKIMSignature.DKIM_SIGNATURE, contentSignature);
      request.body("text/plain", "hello world");
      ClientResponse response = request.post();
      Assert.assertEquals(204, response.getStatus());


   }
View Full Code Here

Examples of org.jboss.resteasy.client.ClientResponse

   @Test
   public void testPopulateDB() throws Exception
   {
      String url = "http://localhost:9095/shop";
      ClientRequest request = new ClientRequest("http://localhost:8080/ex11_1-war/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();
      Assert.assertEquals(201, response.getStatus());

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

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

   }
View Full Code Here

Examples of org.jboss.resteasy.client.ClientResponse

   @Test
   public void testCreateOrder() throws Exception
   {
      String url = "http://localhost:9095/shop";
      ClientRequest request = new ClientRequest("http://localhost:8080/ex11_1-war/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);
View Full Code Here

Examples of org.jboss.resteasy.client.ClientResponse

   }

   protected ClientResponse handleExpired(ClientExecutionContext ctx,
                                          ClientRequest request, BrowserCache.Entry entry) throws Exception
   {
      ClientResponse response = ctx.proceed();
      if (response.getStatus() == Response.Status.NOT_MODIFIED.getStatusCode())
      {
         return updateOnNotModified(request, entry, (BaseClientResponse) response);
      }
      return cache(request, response);
   }
View Full Code Here

Examples of org.jboss.resteasy.client.ClientResponse

   public void testNullJaxb() throws Exception
   {
      ClientRequest request = new ClientRequest("http://localhost:9095/my/null");
      request.header("Content-Length", "0");
      request.header("Content-Type", "application/xml");
      ClientResponse res = request.post();
      Assert.assertEquals(204, res.getStatus());
   }
View Full Code Here

Examples of org.jboss.resteasy.client.ClientResponse

   @SuppressWarnings("unchecked")
   private void doTest(String path, int expectedStatus, boolean get) throws Exception
   {
      ClientRequest request = new ClientRequest(generateURL(path));
      ClientResponse response = get ? request.get() : request.delete();
      Assert.assertEquals(expectedStatus, response.getStatus());
      Assert.assertNotNull(response.getHeaders().getFirst("custom-header"));

   }
View Full Code Here

Examples of org.jboss.resteasy.client.ClientResponse

   @Test
   public void testMapper() throws Exception
   {
      ClientRequest request = new ClientRequest(generateBaseUrl() + "/test");
      ClientResponse response = request.get();
      Assert.assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
   }
View Full Code Here

Examples of org.jboss.resteasy.client.ClientResponse

   @Test
   public void testProduces() throws Exception
   {
      // test that media type is chosen from resource method
      ClientRequest request = new ClientRequest(generateURL("/mapper/produces"));
      ClientResponse response = request.get();
      Assert.assertEquals(412, response.getStatus());
      Assert.assertEquals("application/xml", response.getHeaders().getFirst("Content-Type"));
      String error = (String) response.getEntity(String.class);
      Assert.assertNotNull(error);
      System.out.println(error);

   }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.