Java Code Examples for org.jboss.resteasy.client.ClientResponse#getHeaderAsLink()

The following examples show how to use org.jboss.resteasy.client.ClientResponse#getHeaderAsLink() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PushReg.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
   // get the push consumers factory resource
   ClientRequest request = new ClientRequest("http://localhost:8080/queues/orders");
   ClientResponse res = request.head();
   Link pushConsumers = res.getHeaderAsLink("msg-push-consumers");

   // next create the XML document that represents the registration
   // Really, just create a link with the shipping URL and the type you want posted
   PushRegistration reg = new PushRegistration();
   XmlLink target = new XmlLink();
   target.setHref("http://localhost:8080/queues/shipping");
   target.setType("application/xml");
   target.setRelationship("destination");
   reg.setTarget(target);

   res = pushConsumers.request().body("application/xml", reg).post();
   System.out.println("Create push registration.  Resource URL: " + res.getLocationLink().getHref());
}
 
Example 2
Source File: PostOrderWithId.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
   if (args.length < 1 || args[0] == null)
      throw new RuntimeException("You must pass in a parameter");

   // first get the create URL for the shipping queue
   ClientRequest request = new ClientRequest("http://localhost:8080/queues/orders");
   ClientResponse res = request.head();
   Link create = res.getHeaderAsLink("msg-create-with-id");

   Order order = new Order();
   order.setName(args[0]);
   order.setItem("iPhone4");
   order.setAmount("$199.99");

   res = create.request().pathParameter("id", args[0]).body("application/xml", order).post();

   if (res.getStatus() != 201)
      throw new RuntimeException("Failed to post");

   System.out.println("Sent order " + args[0]);
}
 
Example 3
Source File: ReceiveOrder.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
   // first get the create URL for the shipping queue
   ClientRequest request = new ClientRequest("http://localhost:8080/queues/orders");
   ClientResponse res = request.head();
   Link pullConsumers = res.getHeaderAsLink("msg-pull-consumers");
   res.releaseConnection();
   res = pullConsumers.request().post();
   Link consumeNext = res.getHeaderAsLink("msg-consume-next");
   res.releaseConnection();
   while (true) {
      System.out.println("Waiting...");
      res = consumeNext.request().header("Accept-Wait", "10").post();
      if (res.getStatus() == 503) {
         System.out.println("Timeout...");
         consumeNext = res.getHeaderAsLink("msg-consume-next");
      } else if (res.getStatus() == 200) {
         Order order = (Order) res.getEntity(Order.class);
         System.out.println(order);
         consumeNext = res.getHeaderAsLink("msg-consume-next");
      } else {
         throw new RuntimeException("Failure! " + res.getStatus());
      }
      res.releaseConnection();
   }
}
 
Example 4
Source File: RestSend.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
   // first get the create URL for the shipping queue
   ClientRequest request = new ClientRequest("http://localhost:8080/queues/orders");
   ClientResponse res = request.head();
   Link create = res.getHeaderAsLink("msg-create");

   System.out.println("Send order...");
   Order order = new Order();
   order.setName("Bill");
   order.setItem("iPhone4");
   order.setAmount("$199.99");

   res = create.request().body("application/xml", order).post();
   if (res.getStatus() != 201)
      throw new RuntimeException("Failed to post");
}
 
Example 5
Source File: RestReceive.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
   // first get the create URL for the shipping queue
   ClientRequest request = new ClientRequest("http://localhost:8080/queues/orders");
   ClientResponse res = request.head();
   Link pullConsumers = res.getHeaderAsLink("msg-pull-consumers");
   res = pullConsumers.request().formParameter("autoAck", "false").post();
   Link ackNext = res.getHeaderAsLink("msg-acknowledge-next");
   res.releaseConnection();
   while (true) {
      System.out.println("Waiting...");
      res = ackNext.request().header("Accept-Wait", "10").header("Accept", "application/xml").post();
      if (res.getStatus() == 503) {
         System.out.println("Timeout...");
         ackNext = res.getHeaderAsLink("msg-acknowledge-next");
      } else if (res.getStatus() == 200) {
         Order order = (Order) res.getEntity(Order.class);
         System.out.println(order);
         Link ack = res.getHeaderAsLink("msg-acknowledgement");
         res = ack.request().formParameter("acknowledge", "true").post();
         ackNext = res.getHeaderAsLink("msg-acknowledge-next");
      } else {
         throw new RuntimeException("Failure! " + res.getStatus());
      }
      res.releaseConnection();
   }
}
 
Example 6
Source File: PostOrder.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
   // first get the create URL for the shipping queue
   ClientRequest request = new ClientRequest("http://localhost:8080/queues/orders");
   ClientResponse res = request.head();
   Link create = res.getHeaderAsLink("msg-create");

   System.out.println("Send Bill's order...");
   Order order = new Order();
   order.setName("Bill");
   order.setItem("iPhone4");
   order.setAmount("$199.99");

   res = create.request().body("application/xml", order).post();

   if (res.getStatus() == 307) {
      Link redirect = res.getLocationLink();
      res.releaseConnection();
      res = redirect.request().body("application/xml", order).post();
   }

   if (res.getStatus() != 201)
      throw new RuntimeException("Failed to post");

   create = res.getHeaderAsLink("msg-create-next");

   if (res.getStatus() != 201)
      throw new RuntimeException("Failed to post");

   System.out.println("Send Monica's order...");
   order.setName("Monica");

   res.releaseConnection();
   res = create.request().body("application/xml", order).post();

   if (res.getStatus() != 201)
      throw new RuntimeException("Failed to post");

   System.out.println("Resend Monica's order over same create-next link...");

   res.releaseConnection();
   res = create.request().body("application/xml", order).post();

   if (res.getStatus() != 201)
      throw new RuntimeException("Failed to post");
}