Search in sources :

Example 46 with Link

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

the class JMSTest method testJmsConsumer.

@Test
public void testJmsConsumer() throws Exception {
    String queueName = "testQueue2";
    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);
    Connection conn = connectionFactory.createConnection();
    try {
        Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Destination destination = createDestination(prefixedQueueName);
        MessageConsumer consumer = session.createConsumer(destination);
        consumer.setMessageListener(new Listener());
        conn.start();
        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 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");
            response = sender.request().body("application/xml", order).post();
            response.releaseConnection();
            Assert.assertEquals(201, response.getStatus());
            Listener.latch.await(1, TimeUnit.SECONDS);
            Assert.assertNotNull(Listener.order);
            Assert.assertEquals(order, Listener.order);
            Assert.assertNotNull(Listener.messageID);
        }
    } finally {
        conn.close();
    }
}
Also used : ActiveMQDestination(org.apache.activemq.artemis.jms.client.ActiveMQDestination) Destination(javax.jms.Destination) MessageConsumer(javax.jms.MessageConsumer) MessageListener(javax.jms.MessageListener) QueueDeployment(org.apache.activemq.artemis.rest.queue.QueueDeployment) Connection(javax.jms.Connection) ClientRequest(org.jboss.resteasy.client.ClientRequest) Link(org.jboss.resteasy.spi.Link) Session(javax.jms.Session) Test(org.junit.Test)

Example 47 with Link

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

the class PersistentPushQueueConsumerTest method testFailure.

@Test
public void testFailure() throws Exception {
    try {
        startup();
        String testName = "testFailure";
        QueueDeployment deployment = new QueueDeployment();
        deployment.setDuplicatesAllowed(true);
        deployment.setDurableSend(false);
        deployment.setName(testName);
        manager.getQueueManager().deploy(deployment);
        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);
        PushRegistration reg = new PushRegistration();
        reg.setDurable(true);
        XmlLink target = new XmlLink();
        target.setHref("http://localhost:3333/error");
        target.setRelationship("uri");
        reg.setTarget(target);
        reg.setDisableOnFailure(true);
        reg.setMaxRetries(3);
        reg.setRetryWaitMillis(10);
        response = pushSubscriptions.request().body("application/xml", reg).post();
        Assert.assertEquals(201, response.getStatus());
        Link pushSubscription = response.getLocationLink();
        response.releaseConnection();
        ClientResponse<?> res = sender.request().body("text/plain", Integer.toString(1)).post();
        res.releaseConnection();
        Assert.assertEquals(201, res.getStatus());
        Thread.sleep(5000);
        response = pushSubscription.request().get();
        PushRegistration reg2 = response.getEntity(PushRegistration.class);
        Assert.assertEquals(reg.isDurable(), reg2.isDurable());
        Assert.assertEquals(reg.getTarget().getHref(), reg2.getTarget().getHref());
        // make sure the failure disables the PushRegistration
        Assert.assertFalse(reg2.isEnabled());
        response.releaseConnection();
        manager.getQueueManager().getPushStore().removeAll();
    } finally {
        shutdown();
    }
}
Also used : QueueDeployment(org.apache.activemq.artemis.rest.queue.QueueDeployment) 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 48 with Link

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

the class PushQueueConsumerTest method testBridge.

@Test
public void testBridge() throws Exception {
    Link destinationForConsumption = null;
    ClientResponse consumerResponse = null;
    Link pushSubscription = null;
    String messageContent = "1";
    try {
        // The name of the queue used for the test should match the name of the test
        String queue = "testBridge";
        String queueToPushTo = "pushedFrom-" + queue;
        System.out.println("\n" + queue);
        deployQueue(queue);
        deployQueue(queueToPushTo);
        ClientResponse queueResponse = Util.head(new ClientRequest(generateURL(Util.getUrlPath(queue))));
        Link destination = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), queueResponse, "create");
        Link pushSubscriptions = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), queueResponse, "push-consumers");
        ClientResponse queueToPushToResponse = Util.head(new ClientRequest(generateURL(Util.getUrlPath(queueToPushTo))));
        ClientResponse autoAckResponse = setAutoAck(queueToPushToResponse, true);
        destinationForConsumption = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), autoAckResponse, "consume-next");
        pushSubscription = createPushRegistration(queueToPushTo, pushSubscriptions, PushRegistrationType.BRIDGE);
        sendMessage(destination, messageContent);
        consumerResponse = consume(destinationForConsumption, messageContent);
    } finally {
        cleanupConsumer(consumerResponse);
        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 49 with Link

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

the class PushQueueConsumerTest method testUri.

@Test
public void testUri() throws Exception {
    Link pushSubscription = null;
    String messageContent = "1";
    try {
        // The name of the queue used for the test should match the name of the test
        String queue = "testUri";
        String queueToPushTo = "pushedFrom-" + queue;
        System.out.println("\n" + queue);
        deployQueue(queue);
        deployQueue(queueToPushTo);
        server.getJaxrsServer().getDeployment().getRegistry().addPerRequestResource(MyResource.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("/my"), pushSubscriptions, PushRegistrationType.URI);
        sendMessage(destinationForSend, messageContent);
        Thread.sleep(100);
        Assert.assertEquals(messageContent, MyResource.got_it);
    } 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 50 with Link

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

the class PushQueueConsumerTest method testClass.

@Test
public void testClass() throws Exception {
    Link destinationForConsumption = null;
    ClientResponse consumerResponse = null;
    Link pushSubscription = null;
    String messageContent = "1";
    try {
        // The name of the queue used for the test should match the name of the test
        String queue = "testClass";
        String queueToPushTo = "pushedFrom-" + queue;
        System.out.println("\n" + queue);
        deployQueue(queue);
        deployQueue(queueToPushTo);
        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");
        ClientResponse queueToPushToResponse = Util.head(new ClientRequest(generateURL(Util.getUrlPath(queueToPushTo))));
        ClientResponse autoAckResponse = setAutoAck(queueToPushToResponse, true);
        destinationForConsumption = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), autoAckResponse, "consume-next");
        pushSubscription = createPushRegistration(queueToPushTo, pushSubscriptions, PushRegistrationType.CLASS);
        sendMessage(destinationForSend, messageContent);
        consumerResponse = consume(destinationForConsumption, messageContent);
    } finally {
        cleanupConsumer(consumerResponse);
        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)

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