Search in sources :

Example 1 with Link

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

the class PushQueueConsumerTest method createPushRegistration.

private Link createPushRegistration(String queueToPushTo, Link pushSubscriptions, PushRegistrationType pushRegistrationType, int sessionCount) throws Exception {
    PushRegistration reg = new PushRegistration();
    reg.setDurable(false);
    XmlLink target = new XmlLink();
    if (pushRegistrationType == PushRegistrationType.CLASS) {
        target.setHref(generateURL(Util.getUrlPath(queueToPushTo)));
        target.setClassName(ActiveMQPushStrategy.class.getName());
    } else if (pushRegistrationType == PushRegistrationType.BRIDGE) {
        target.setHref(generateURL(Util.getUrlPath(queueToPushTo)));
        target.setRelationship("destination");
    } else if (pushRegistrationType == PushRegistrationType.TEMPLATE) {
        target.setHref(queueToPushTo);
        target.setRelationship("template");
    } else if (pushRegistrationType == PushRegistrationType.URI) {
        target.setMethod("put");
        target.setHref(queueToPushTo);
    }
    reg.setTarget(target);
    reg.setSessionCount(sessionCount);
    ClientResponse pushRegistrationResponse = pushSubscriptions.request().body("application/xml", reg).post();
    pushRegistrationResponse.releaseConnection();
    Assert.assertEquals(201, pushRegistrationResponse.getStatus());
    Link pushSubscription = pushRegistrationResponse.getLocationLink();
    return pushSubscription;
}
Also used : ActiveMQPushStrategy(org.apache.activemq.artemis.rest.queue.push.ActiveMQPushStrategy) ClientResponse(org.jboss.resteasy.client.ClientResponse) PushRegistration(org.apache.activemq.artemis.rest.queue.push.xml.PushRegistration) XmlLink(org.apache.activemq.artemis.rest.queue.push.xml.XmlLink) XmlLink(org.apache.activemq.artemis.rest.queue.push.xml.XmlLink) Link(org.jboss.resteasy.spi.Link)

Example 2 with Link

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

the class PushQueueConsumerTest method setAutoAck.

private ClientResponse setAutoAck(ClientResponse response, boolean ack) throws Exception {
    Link pullConsumers = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "pull-consumers");
    ClientResponse autoAckResponse = pullConsumers.request().formParameter("autoAck", Boolean.toString(ack)).post();
    autoAckResponse.releaseConnection();
    Assert.assertEquals(201, autoAckResponse.getStatus());
    return autoAckResponse;
}
Also used : ClientResponse(org.jboss.resteasy.client.ClientResponse) XmlLink(org.apache.activemq.artemis.rest.queue.push.xml.XmlLink) Link(org.jboss.resteasy.spi.Link)

Example 3 with Link

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

the class PushQueueConsumerTest method cleanupConsumer.

private void cleanupConsumer(ClientResponse consumerResponse) throws Exception {
    if (consumerResponse != null) {
        Link consumer = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), consumerResponse, "consumer");
        ClientResponse<?> response = consumer.request().delete();
        response.releaseConnection();
        Assert.assertEquals(204, response.getStatus());
    }
}
Also used : XmlLink(org.apache.activemq.artemis.rest.queue.push.xml.XmlLink) Link(org.jboss.resteasy.spi.Link)

Example 4 with Link

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

the class PersistentPushTopicConsumerTest method testSuccessFirst.

@Test
public void testSuccessFirst() throws Exception {
    try {
        String testName = "testSuccessFirst";
        startup();
        deployTopic(testName);
        ClientRequest request = new ClientRequest(generateURL("/topics/" + testName));
        ClientResponse<?> response = request.head();
        response.releaseConnection();
        Assert.assertEquals(200, response.getStatus());
        Link sender = MessageTestBase.getLinkByTitle(manager.getTopicManager().getLinkStrategy(), response, "create");
        System.out.println("create: " + sender);
        Link pushSubscriptions = MessageTestBase.getLinkByTitle(manager.getTopicManager().getLinkStrategy(), response, "push-subscriptions");
        System.out.println("push subscriptions: " + pushSubscriptions);
        String sub1 = generateURL("/subscribers/1");
        String sub2 = generateURL("/subscribers/2");
        PushTopicRegistration reg = new PushTopicRegistration();
        reg.setDurable(true);
        XmlLink target = new XmlLink();
        target.setHref(sub1);
        reg.setTarget(target);
        response = pushSubscriptions.request().body("application/xml", reg).post();
        response.releaseConnection();
        Assert.assertEquals(201, response.getStatus());
        reg = new PushTopicRegistration();
        reg.setDurable(true);
        target = new XmlLink();
        target.setHref(sub2);
        reg.setTarget(target);
        response = pushSubscriptions.request().body("application/xml", reg).post();
        response.releaseConnection();
        Assert.assertEquals(201, response.getStatus());
        shutdown();
        startup();
        deployTopic(testName);
        ClientResponse<?> res = sender.request().body("text/plain", Integer.toString(1)).post();
        res.releaseConnection();
        Assert.assertEquals(201, res.getStatus());
        Receiver.latch.await(1, TimeUnit.SECONDS);
        Assert.assertEquals("1", Receiver.subscriber1);
        Assert.assertEquals("1", Receiver.subscriber2);
        manager.getTopicManager().getPushStore().removeAll();
    } finally {
        shutdown();
    }
}
Also used : PushTopicRegistration(org.apache.activemq.artemis.rest.topic.PushTopicRegistration) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) 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 5 with Link

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

the class PushTopicConsumerTest method testTemplate.

@Test
public void testTemplate() throws Exception {
    TopicDeployment deployment = new TopicDeployment();
    deployment.setDuplicatesAllowed(true);
    deployment.setDurableSend(false);
    deployment.setName("testTemplate");
    manager.getTopicManager().deploy(deployment);
    QueueDeployment deployment2 = new QueueDeployment();
    deployment2.setDuplicatesAllowed(true);
    deployment2.setDurableSend(false);
    deployment2.setName("testTemplateForwardQueue");
    manager.getQueueManager().deploy(deployment2);
    ClientRequest request = new ClientRequest(generateURL("/topics/testTemplate"));
    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 pushSubscriptions = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "push-subscriptions");
    System.out.println("push subscriptions: " + pushSubscriptions);
    request = new ClientRequest(generateURL("/queues/testTemplateForwardQueue"));
    response = request.head();
    response.releaseConnection();
    Assert.assertEquals(200, response.getStatus());
    Link consumers = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "pull-consumers");
    Link createWithId = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "create-with-id");
    response = Util.setAutoAck(consumers, true);
    Link consumeNext = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "consume-next");
    PushTopicRegistration reg = new PushTopicRegistration();
    reg.setDurable(false);
    XmlLink target = new XmlLink();
    target.setRelationship("template");
    target.setHref(createWithId.getHref());
    reg.setTarget(target);
    response = pushSubscriptions.request().body("application/xml", reg).post();
    Assert.assertEquals(201, response.getStatus());
    Link pushSubscription = response.getLocationLink();
    response.releaseConnection();
    response = sender.request().body("text/plain", Integer.toString(1)).post();
    response.releaseConnection();
    Assert.assertEquals(201, response.getStatus());
    response = consumeNext.request().header("Accept-Wait", "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");
    response = session.request().delete();
    response.releaseConnection();
    Assert.assertEquals(204, response.getStatus());
    response = pushSubscription.request().delete();
    response.releaseConnection();
    Assert.assertEquals(204, response.getStatus());
}
Also used : PushTopicRegistration(org.apache.activemq.artemis.rest.topic.PushTopicRegistration) TopicDeployment(org.apache.activemq.artemis.rest.topic.TopicDeployment) QueueDeployment(org.apache.activemq.artemis.rest.queue.QueueDeployment) 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)

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