Search in sources :

Example 26 with Link

use of org.jboss.resteasy.spi.Link in project activemq-artemis by apache.

the class JMSTest method testJmsProducer.

@Test
public void testJmsProducer() throws Exception {
    String queueName = "testQueue";
    String prefixedQueueName = ActiveMQDestination.createQueueAddressFromName(queueName).toString();
    System.out.println("Queue name: " + prefixedQueueName);
    QueueDeployment deployment = new QueueDeployment();
    deployment.setDuplicatesAllowed(true);
    deployment.setDurableSend(false);
    deployment.setName(queueName);
    manager.getQueueManager().deploy(deployment);
    ClientRequest request = new ClientRequest(generateURL(Util.getUrlPath(queueName)));
    ClientResponse<?> response = request.head();
    response.releaseConnection();
    Assert.assertEquals(200, response.getStatus());
    Link sender = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "create");
    System.out.println("create: " + sender);
    Link consumers = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "pull-consumers");
    System.out.println("pull: " + consumers);
    response = Util.setAutoAck(consumers, true);
    Link consumeNext = 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(prefixedQueueName, order, null);
        ClientResponse<?> res = consumeNext.request().header("Accept-Wait", "2").accept("application/xml").post(String.class);
        Assert.assertEquals(200, res.getStatus());
        Assert.assertEquals("application/xml", res.getHeaders().getFirst("Content-Type").toString().toLowerCase());
        Order order2 = res.getEntity(Order.class);
        res.releaseConnection();
        Assert.assertEquals(order, order2);
        consumeNext = 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(prefixedQueueName, order, null);
        ClientResponse<?> res = consumeNext.request().header("Accept-Wait", "2").accept("application/json").post(String.class);
        Assert.assertEquals(200, res.getStatus());
        Assert.assertEquals("application/json", res.getHeaders().getFirst("Content-Type").toString().toLowerCase());
        Order order2 = res.getEntity(Order.class);
        res.releaseConnection();
        Assert.assertEquals(order, order2);
        consumeNext = 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(prefixedQueueName, order, "application/xml");
        ClientResponse<?> res = consumeNext.request().header("Accept-Wait", "2").post(String.class);
        Assert.assertEquals(200, res.getStatus());
        Assert.assertEquals("application/xml", res.getHeaders().getFirst("Content-Type").toString().toLowerCase());
        Order order2 = res.getEntity(Order.class);
        res.releaseConnection();
        Assert.assertEquals(order, order2);
        consumeNext = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), res, "consume-next");
        Assert.assertNotNull(consumeNext);
    }
}
Also used : ClientResponse(org.jboss.resteasy.client.ClientResponse) QueueDeployment(org.apache.activemq.artemis.rest.queue.QueueDeployment) ClientRequest(org.jboss.resteasy.client.ClientRequest) Link(org.jboss.resteasy.spi.Link) Test(org.junit.Test)

Example 27 with Link

use of org.jboss.resteasy.spi.Link in project activemq-artemis by apache.

the class PersistentPushQueueConsumerTest method testBridge.

@Test
public void testBridge() throws Exception {
    try {
        startup();
        String testName = "testBridge";
        deployBridgeQueues(testName);
        ClientRequest request = new ClientRequest(generateURL("/queues/" + testName));
        ClientResponse<?> response = request.head();
        response.releaseConnection();
        Assert.assertEquals(200, response.getStatus());
        Link sender = MessageTestBase.getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "create");
        System.out.println("create: " + sender);
        Link pushSubscriptions = MessageTestBase.getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "push-consumers");
        System.out.println("push subscriptions: " + pushSubscriptions);
        request = new ClientRequest(generateURL("/queues/" + testName + "forwardQueue"));
        response = request.head();
        response.releaseConnection();
        Assert.assertEquals(200, response.getStatus());
        Link consumers = MessageTestBase.getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "pull-consumers");
        System.out.println("pull: " + consumers);
        response = Util.setAutoAck(consumers, true);
        Link consumeNext = MessageTestBase.getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "consume-next");
        System.out.println("poller: " + consumeNext);
        PushRegistration reg = new PushRegistration();
        reg.setDurable(true);
        reg.setDisableOnFailure(true);
        XmlLink target = new XmlLink();
        target.setHref(generateURL("/queues/" + testName + "forwardQueue"));
        target.setRelationship("destination");
        reg.setTarget(target);
        response = pushSubscriptions.request().body("application/xml", reg).post();
        response.releaseConnection();
        Assert.assertEquals(201, response.getStatus());
        shutdown();
        startup();
        deployBridgeQueues(testName);
        ClientResponse<?> res = sender.request().body("text/plain", Integer.toString(1)).post();
        res.releaseConnection();
        Assert.assertEquals(201, res.getStatus());
        res = consumeNext.request().header("Accept-Wait", "2").post(String.class);
        Assert.assertEquals(200, res.getStatus());
        Assert.assertEquals("1", res.getEntity(String.class));
        res.releaseConnection();
        Link session = MessageTestBase.getLinkByTitle(manager.getQueueManager().getLinkStrategy(), res, "consumer");
        res = session.request().delete();
        res.releaseConnection();
        Assert.assertEquals(204, res.getStatus());
        manager.getQueueManager().getPushStore().removeAll();
    } finally {
        shutdown();
    }
}
Also used : PushRegistration(org.apache.activemq.artemis.rest.queue.push.xml.PushRegistration) XmlLink(org.apache.activemq.artemis.rest.queue.push.xml.XmlLink) ClientRequest(org.jboss.resteasy.client.ClientRequest) XmlLink(org.apache.activemq.artemis.rest.queue.push.xml.XmlLink) Link(org.jboss.resteasy.spi.Link) Test(org.junit.Test)

Example 28 with Link

use of org.jboss.resteasy.spi.Link in project activemq-artemis by apache.

the class PushQueueConsumerTest method testUriWithMultipleSessions.

@Test
public void testUriWithMultipleSessions() throws Exception {
    Link pushSubscription = null;
    String messageContent = "1";
    final int CONCURRENT = 10;
    try {
        // The name of the queue used for the test should match the name of the test
        String queue = "testUriWithMultipleSessions";
        String queueToPushTo = "pushedFrom-" + queue;
        System.out.println("\n" + queue);
        deployQueue(queue);
        deployQueue(queueToPushTo);
        server.getJaxrsServer().getDeployment().getRegistry().addPerRequestResource(MyConcurrentResource.class);
        ClientResponse queueResponse = Util.head(new ClientRequest(generateURL(Util.getUrlPath(queue))));
        Link destinationForSend = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), queueResponse, "create");
        Link pushSubscriptions = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), queueResponse, "push-consumers");
        pushSubscription = createPushRegistration(generateURL("/myConcurrent"), pushSubscriptions, PushRegistrationType.URI, CONCURRENT);
        for (int i = 0; i < CONCURRENT; i++) {
            sendMessage(destinationForSend, messageContent);
        }
        // wait until all the invocations have completed
        while (MyConcurrentResource.concurrentInvocations.get() > 0) {
            Thread.sleep(100);
        }
        Assert.assertEquals(CONCURRENT, MyConcurrentResource.maxConcurrentInvocations.get());
    } finally {
        cleanupSubscription(pushSubscription);
    }
}
Also used : ClientResponse(org.jboss.resteasy.client.ClientResponse) XmlLink(org.apache.activemq.artemis.rest.queue.push.xml.XmlLink) Link(org.jboss.resteasy.spi.Link) ClientRequest(org.jboss.resteasy.client.ClientRequest) Test(org.junit.Test)

Example 29 with Link

use of org.jboss.resteasy.spi.Link in project activemq-artemis by apache.

the class RepostingTopicTest method testPostOnOldAcknowledgeNextAndAck.

@Test
public void testPostOnOldAcknowledgeNextAndAck() throws Exception {
    ClientRequest request = new ClientRequest(generateURL("/topics/testTopic"));
    ClientResponse<?> response = request.head();
    response.releaseConnection();
    Assert.assertEquals(200, response.getStatus());
    Link sender = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "create");
    System.out.println("create: " + sender);
    Link consumers = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "pull-subscriptions");
    System.out.println("pull: " + consumers);
    response = Util.setAutoAck(consumers, false);
    Link consumeNext = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "acknowledge-next");
    System.out.println("resource acknowledge-next: " + consumeNext);
    response = sender.request().body("text/plain", Integer.toString(1)).post();
    response.releaseConnection();
    Assert.assertEquals(201, response.getStatus());
    response = consumeNext.request().header(Constants.WAIT_HEADER, "1").post(String.class);
    Assert.assertEquals(200, response.getStatus());
    Assert.assertEquals("1", response.getEntity(String.class));
    response.releaseConnection();
    Link session = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "consumer");
    System.out.println("session: " + session);
    Link ack = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "acknowledgement");
    Link oldAck = ack;
    System.out.println("ack: " + ack);
    response = ack.request().formParameter("acknowledge", "true").post();
    response.releaseConnection();
    Assert.assertEquals(204, response.getStatus());
    consumeNext = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "acknowledge-next");
    System.out.println("session 1st acknowledge-next: " + consumeNext);
    Link firstConsumeNext = consumeNext;
    response = sender.request().body("text/plain", Integer.toString(2)).post();
    response.releaseConnection();
    Assert.assertEquals(201, response.getStatus());
    response = consumeNext.request().header(Constants.WAIT_HEADER, "10").post(String.class);
    response.releaseConnection();
    Assert.assertEquals(200, response.getStatus());
    ack = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "acknowledgement");
    System.out.println("ack: " + ack);
    response = oldAck.request().formParameter("acknowledge", "true").post();
    Assert.assertEquals(412, response.getStatus());
    System.out.println(response.getEntity(String.class));
    response.releaseConnection();
    consumeNext = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "acknowledge-next");
    response = ack.request().formParameter("acknowledge", "true").post();
    response.releaseConnection();
    Assert.assertEquals(204, response.getStatus());
    consumeNext = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "acknowledge-next");
    response = consumeNext.request().post(String.class);
    response.releaseConnection();
    Assert.assertEquals(503, response.getStatus());
    response = session.request().delete();
    response.releaseConnection();
    Assert.assertEquals(204, response.getStatus());
}
Also used : ClientRequest(org.jboss.resteasy.client.ClientRequest) Link(org.jboss.resteasy.spi.Link) Test(org.junit.Test)

Example 30 with Link

use of org.jboss.resteasy.spi.Link in project activemq-artemis by apache.

the class RepostingTopicTest method testRestartOnDurableNamedSubscriber.

@Test
public void testRestartOnDurableNamedSubscriber() throws Exception {
    ClientRequest request = new ClientRequest(generateURL("/topics/testTopic"));
    ClientResponse<?> response = request.head();
    response.releaseConnection();
    Assert.assertEquals(200, response.getStatus());
    Link sender = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "create");
    System.out.println("create: " + sender);
    Link consumers = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "pull-subscriptions");
    System.out.println("pull: " + consumers);
    response = consumers.request().formParameter("name", "bill").formParameter("durable", "true").post();
    response.releaseConnection();
    response = sender.request().body("text/plain", Integer.toString(1)).post();
    response.releaseConnection();
    Assert.assertEquals(201, response.getStatus());
    response = sender.request().body("text/plain", Integer.toString(2)).post();
    response.releaseConnection();
    Assert.assertEquals(201, response.getStatus());
    manager.getTopicManager().getDestination().findTopic("testTopic").getSubscriptions().stop();
    // recreate subscription a second time as named.  Should pick up old one.
    response = consumers.request().formParameter("name", "bill").formParameter("durable", "true").post();
    response.releaseConnection();
    Link consumeNext = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "consume-next");
    System.out.println("resource consume-next: " + consumeNext);
    response = consumeNext.request().header("Accept-Wait", "2").post(String.class);
    Assert.assertEquals(200, response.getStatus());
    Assert.assertEquals("1", response.getEntity(String.class));
    response.releaseConnection();
    consumeNext = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "consume-next");
    response = consumeNext.request().header("Accept-Wait", "2").post(String.class);
    Assert.assertEquals(200, response.getStatus());
    Assert.assertEquals("2", response.getEntity(String.class));
    response.releaseConnection();
    Link session = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "consumer");
    response = session.request().delete();
    response.releaseConnection();
    Assert.assertEquals(204, response.getStatus());
}
Also used : ClientRequest(org.jboss.resteasy.client.ClientRequest) Link(org.jboss.resteasy.spi.Link) Test(org.junit.Test)

Aggregations

Link (org.jboss.resteasy.spi.Link)86 ClientRequest (org.jboss.resteasy.client.ClientRequest)81 Test (org.junit.Test)68 ClientResponse (org.jboss.resteasy.client.ClientResponse)25 XmlLink (org.apache.activemq.artemis.rest.queue.push.xml.XmlLink)20 QueueDeployment (org.apache.activemq.artemis.rest.queue.QueueDeployment)11 PushTopicRegistration (org.apache.activemq.artemis.rest.topic.PushTopicRegistration)8 TopicDeployment (org.apache.activemq.artemis.rest.topic.TopicDeployment)7 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)4 PushRegistration (org.apache.activemq.artemis.rest.queue.push.xml.PushRegistration)4 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)2 AddressInfo (org.apache.activemq.artemis.core.server.impl.AddressInfo)2 ActiveMQPushStrategy (org.apache.activemq.artemis.rest.queue.push.ActiveMQPushStrategy)2 Connection (javax.jms.Connection)1 Destination (javax.jms.Destination)1 MessageConsumer (javax.jms.MessageConsumer)1 MessageListener (javax.jms.MessageListener)1 Session (javax.jms.Session)1 SecurityConfiguration (org.apache.activemq.artemis.core.config.impl.SecurityConfiguration)1 ActiveMQDestination (org.apache.activemq.artemis.jms.client.ActiveMQDestination)1