ClientRequest request = new ClientRequest(generateURL("/queues/testQueue"));
ClientResponse response = request.head();
Assert.assertEquals(200, response.getStatus());
Link sender = MessageTestBase.getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "create");
System.out.println("create: " + sender);
Link consumers = MessageTestBase.getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "pull-consumers");
System.out.println("pull: " + consumers);
response = consumers.request().formParameter("autoAck", "true").post();
Link consumeNext = MessageTestBase.getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "consume-next");
System.out.println("consume-next: " + consumeNext);
// test that Accept header is used to set content-type
{
Order order = new Order();
order.setName("1");
order.setAmount("$5.00");
publish("testQueue", order, null);
ClientResponse res = consumeNext.request().accept("application/xml").post(String.class);
Assert.assertEquals(200, res.getStatus());
Assert.assertEquals("application/xml", res.getHeaders().getFirst("Content-Type").toString().toLowerCase());
Order order2 = (Order) res.getEntity(Order.class);
Assert.assertEquals(order, order2);
consumeNext = MessageTestBase.getLinkByTitle(manager.getQueueManager().getLinkStrategy(), res, "consume-next");
Assert.assertNotNull(consumeNext);
}
// test that Accept header is used to set content-type
{
Order order = new Order();
order.setName("1");
order.setAmount("$5.00");
publish("testQueue", order, null);
ClientResponse res = consumeNext.request().accept("application/json").post(String.class);
Assert.assertEquals(200, res.getStatus());
Assert.assertEquals("application/json", res.getHeaders().getFirst("Content-Type").toString().toLowerCase());
Order order2 = (Order) res.getEntity(Order.class);
Assert.assertEquals(order, order2);
consumeNext = MessageTestBase.getLinkByTitle(manager.getQueueManager().getLinkStrategy(), res, "consume-next");
Assert.assertNotNull(consumeNext);
}
// test that message property is used to set content type
{
Order order = new Order();
order.setName("2");
order.setAmount("$15.00");
publish("testQueue", order, "application/xml");
ClientResponse res = consumeNext.request().post(String.class);
Assert.assertEquals(200, res.getStatus());
Assert.assertEquals("application/xml", res.getHeaders().getFirst("Content-Type").toString().toLowerCase());
Order order2 = (Order) res.getEntity(Order.class);
Assert.assertEquals(order, order2);
consumeNext = MessageTestBase.getLinkByTitle(manager.getQueueManager().getLinkStrategy(), res, "consume-next");