Package javax.ws.rs.core

Examples of javax.ws.rs.core.Link$JaxbLink


   public void testCreateCancelPurge() throws Exception
   {
      String base = "http://localhost:8080/services/shop";
      Response response = client.target(base).request().head();

      Link customers = response.getLink("customers");
      Link orders = response.getLink("orders");
      response.close();

      System.out.println("** Create a customer through this URL: " + customers.getUri().toString());

      Customer customer = new Customer();
      customer.setFirstName("Bill");
      customer.setLastName("Burke");
      customer.setStreet("10 Somewhere Street");
      customer.setCity("Westford");
      customer.setState("MA");
      customer.setZip("01711");
      customer.setCountry("USA");

      response = client.target(customers).request().post(Entity.xml(customer));
      Assert.assertEquals(201, response.getStatus());
      response.close();


      Order order = new Order();
      order.setTotal("$199.99");
      order.setCustomer(customer);
      order.setDate(new Date().toString());
      LineItem item = new LineItem();
      item.setCost("$199.99");
      item.setProduct("iPhone");
      order.setLineItems(new ArrayList<LineItem>());
      order.getLineItems().add(item);

      System.out.println();
      System.out.println("** Create an order through this URL: " + orders.getUri().toString());
      response = client.target(orders).request().post(Entity.xml(order));
      Assert.assertEquals(201, response.getStatus());
      URI createdOrderUrl = response.getLocation();
      response.close();

      System.out.println();
      System.out.println("** New list of orders");
      response = client.target(orders).request().get();
      String orderList = response.readEntity(String.class);
      System.out.println(orderList);
      Link purge = response.getLink("purge");
      response.close();

      response = client.target(createdOrderUrl).request().head();
      Link cancel = response.getLink("cancel");
      response.close();
      if (cancel != null)
      {
         System.out.println("** Canceling the order at URL: " + cancel.getUri().toString());
         response = client.target(cancel).request().post(null);
         Assert.assertEquals(204, response.getStatus());
         response.close();
      }

View Full Code Here


   protected void send(UriBuilder base, AsyncResponse async, Message message)
   {
      URI nextUri = base.clone().path(CustomerChat.class)
              .queryParam("current", message.id).build();
      Link next = Link.fromUri(nextUri).rel("next").build();
      Response response = Response.ok(message.message, MediaType.TEXT_PLAIN_TYPE).links(next).build();
      async.resume(response);
   }
View Full Code Here

   protected void send(UriBuilder base, AsyncResponse async, Message message)
   {
      URI nextUri = base.clone().path(CustomerChat.class)
              .queryParam("current", message.id).build();
      Link next = Link.fromUri(nextUri).rel("next").build();
      Response response = Response.ok(message.message, MediaType.TEXT_PLAIN_TYPE).links(next).build();
      async.resume(response);
   }
View Full Code Here

      for (Object obj : orderEntities)
      {
         OrderEntity entity = (OrderEntity) obj;
         Order order = entity2domain(entity);
         URI self = uriInfo.getAbsolutePathBuilder().path(Integer.toString(order.getId())).build();
         Link selfLink = Link.fromUri(self).rel("self").type("application/xml").build();
         order.addLink(selfLink);
         if (!order.isCancelled())
         {
            URI cancel = uriInfo.getAbsolutePathBuilder().path(Integer.toString(order.getId())).path("cancel").build();
            Link cancelLink = Link.fromUri(cancel).rel("cancel").type("application/xml").build();
            order.addLink(cancelLink);
         }
         list.add(order);
      }
      // next link
      // If the size returned is equal then assume there is a next
      if (orderEntities.size() == size)
      {
         int next = start + size;
         URI nextUri = builder.clone().build(next, size);
         Link nextLink = Link.fromUri(nextUri).rel("next").type("application/xml").build();
         links.add(nextLink);
      }
      // previous link
      if (start > 0)
      {
         int previous = start - size;
         if (previous < 0) previous = 0;
         URI previousUri = builder.clone().build(previous, size);
         Link previousLink = Link.fromUri(previousUri).rel("previous").type("application/xml").build();
         links.add(previousLink);
      }
      Orders orders = new Orders();
      orders.setOrders(list);
      orders.setLinks(links);
View Full Code Here

      for (Object obj : orderEntities)
      {
         OrderEntity entity = (OrderEntity) obj;
         Order order = entity2domain(entity);
         URI self = uriInfo.getAbsolutePathBuilder().path(Integer.toString(order.getId())).build();
         Link selfLink = Link.fromUri(self).rel("self").type("application/xml").build();
         order.addLink(selfLink);
         if (!order.isCancelled())
         {
            URI cancel = uriInfo.getAbsolutePathBuilder().path(Integer.toString(order.getId())).path("cancel").build();
            Link cancelLink = Link.fromUri(cancel).rel("cancel").type("application/xml").build();
            order.addLink(cancelLink);
         }
         list.add(order);
      }
      // next link
      // If the size returned is equal then assume there is a next
      if (orderEntities.size() == size)
      {
         int next = start + size;
         URI nextUri = builder.clone().build(next, size);
         Link nextLink = Link.fromUri(nextUri).rel("next").type("application/xml").build();
         links.add(nextLink);
      }
      // previous link
      if (start > 0)
      {
         int previous = start - size;
         if (previous < 0) previous = 0;
         URI previousUri = builder.clone().build(previous, size);
         Link previousLink = Link.fromUri(previousUri).rel("previous").type("application/xml").build();
         links.add(previousLink);
      }
      Orders orders = new Orders();
      orders.setOrders(list);
      orders.setLinks(links);
View Full Code Here

   public Response getOrder(int id, UriInfo uriInfo)
   {
      OrderEntity entity = em.getReference(OrderEntity.class, id);
      Order order = entity2domain(entity);
      URI self = uriInfo.getAbsolutePathBuilder().build();
      Link selfLink = Link.fromUri(self).rel("self").type("application/xml").build();
      order.addLink(selfLink);
      if (!order.isCancelled())
      {
         URI cancel = uriInfo.getAbsolutePathBuilder().path("cancel").build();
         Link cancelLink = Link.fromUri(cancel).rel("cancel").type("application/xml").build();
         order.addLink(cancelLink);
      }

      Response.ResponseBuilder builder = Response.ok(order);
      if (!order.isCancelled()) addCancelHeader(uriInfo, builder);
View Full Code Here

   {
      UriBuilder absolute = uriInfo.getBaseUriBuilder();
      URI customerUrl = absolute.clone().path("customers").build();
      URI orderUrl = absolute.clone().path("orders").build();
      URI productUrl = absolute.clone().path("products").build();
      Link customers = Link.fromUri(customerUrl).rel("customers").type("application/xml").build();
      Link orders = Link.fromUri(orderUrl).rel("orders").type("application/xml").build();
      Link products = Link.fromUri(productUrl).rel("products").type("application/xml").build();

      Response.ResponseBuilder builder = Response.ok().links(customers, orders, products);
      return builder.build();
   }
View Full Code Here

      {
         return new EntityExtractor<String>()
         {
            public String extractEntity(ClientContext context, Object... args)
            {
               Link link2 = getLink(link, context);
               return link2 == null ? null : link2.getUri().toString();
            }
         };
      }

      if (returnType == URL.class)
View Full Code Here

   }

   @Override
   public Response.ResponseBuilder link(URI uri, String rel)
   {
      Link link = Link.fromUri(uri).rel(rel).build();
      metadata.add(HttpHeaders.LINK, link);
      return this;
   }
View Full Code Here

   }

   @Override
   public Response.ResponseBuilder link(String uri, String rel)
   {
      Link link = Link.fromUri(uri).rel(rel).build();
      metadata.add(HttpHeaders.LINK, link);
      return this;
   }
View Full Code Here

TOP

Related Classes of javax.ws.rs.core.Link$JaxbLink

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.