Search in sources :

Example 6 with NotificationMessageHolderType

use of org.oasis_open.docs.wsn.b_2.NotificationMessageHolderType in project cxf by apache.

the class WsnBrokerTest method testRenew.

@Test
public void testRenew() throws Exception {
    TestConsumer callback = new TestConsumer();
    Consumer consumer = new Consumer(callback, "http://localhost:" + port2 + "/test/consumer");
    // create subscription with InitialTerminationTime 2 sec, so that the
    // subscription would be expired after 2 sec
    Subscription subscription = notificationBroker.subscribe(consumer, "myTopic", null, false, "PT02S");
    Thread.sleep(5000);
    synchronized (callback.notifications) {
        System.out.println("send notify");
        notificationBroker.notify("myTopic", new JAXBElement<String>(new QName("urn:test:org", "foo"), String.class, "bar"));
        callback.notifications.wait(2000);
    }
    // the subscription is expired so can't get the notification
    assertEquals(0, callback.notifications.size());
    // renew another 60 sec to resend the notification
    subscription.renew("PT60S");
    synchronized (callback.notifications) {
        notificationBroker.notify("myTopic", new JAXBElement<String>(new QName("urn:test:org", "foo"), String.class, "bar"));
        callback.notifications.wait(10000);
    }
    // the subscription is expired so can't get the notification
    assertEquals(1, callback.notifications.size());
    NotificationMessageHolderType message = callback.notifications.get(0);
    assertEquals(WSNHelper.getInstance().getWSAAddress(subscription.getEpr()), WSNHelper.getInstance().getWSAAddress(message.getSubscriptionReference()));
    subscription.unsubscribe();
    consumer.stop();
}
Also used : Consumer(org.apache.cxf.wsn.client.Consumer) QName(javax.xml.namespace.QName) Subscription(org.apache.cxf.wsn.client.Subscription) NotificationMessageHolderType(org.oasis_open.docs.wsn.b_2.NotificationMessageHolderType) Test(org.junit.Test)

Example 7 with NotificationMessageHolderType

use of org.oasis_open.docs.wsn.b_2.NotificationMessageHolderType in project cxf by apache.

the class WsnBrokerTest method testBroker.

@Test
public void testBroker() throws Exception {
    TestConsumer callback = new TestConsumer();
    Consumer consumer = new Consumer(callback, "http://localhost:" + port2 + "/test/consumer");
    Subscription subscription = notificationBroker.subscribe(consumer, "myTopic");
    synchronized (callback.notifications) {
        notificationBroker.notify("myTopic", new JAXBElement<String>(new QName("urn:test:org", "foo"), String.class, "bar"));
        callback.notifications.wait(1000000);
    }
    assertEquals(1, callback.notifications.size());
    NotificationMessageHolderType message = callback.notifications.get(0);
    assertEquals(WSNHelper.getInstance().getWSAAddress(subscription.getEpr()), WSNHelper.getInstance().getWSAAddress(message.getSubscriptionReference()));
    subscription.unsubscribe();
    consumer.stop();
}
Also used : Consumer(org.apache.cxf.wsn.client.Consumer) QName(javax.xml.namespace.QName) Subscription(org.apache.cxf.wsn.client.Subscription) NotificationMessageHolderType(org.oasis_open.docs.wsn.b_2.NotificationMessageHolderType) Test(org.junit.Test)

Example 8 with NotificationMessageHolderType

use of org.oasis_open.docs.wsn.b_2.NotificationMessageHolderType in project cxf by apache.

the class WsnBrokerTest method testPublisherCustomType.

@Test
public void testPublisherCustomType() throws Exception {
    notificationBroker.setExtraClasses(CustomType.class);
    TestConsumer consumerCallback = new TestConsumer();
    Consumer consumer = new Consumer(consumerCallback, "http://localhost:" + port2 + "/test/consumer", CustomType.class);
    Subscription subscription = notificationBroker.subscribe(consumer, "myTopic");
    PublisherCallback publisherCallback = new PublisherCallback();
    Publisher publisher = new Publisher(publisherCallback, "http://localhost:" + port2 + "/test/publisher");
    Registration registration = notificationBroker.registerPublisher(publisher, "myTopic");
    synchronized (consumerCallback.notifications) {
        notificationBroker.notify(publisher, "myTopic", new CustomType(1, 2));
        consumerCallback.notifications.wait(1000000);
    }
    assertEquals(1, consumerCallback.notifications.size());
    NotificationMessageHolderType message = consumerCallback.notifications.get(0);
    assertEquals(WSNHelper.getInstance().getWSAAddress(subscription.getEpr()), WSNHelper.getInstance().getWSAAddress(message.getSubscriptionReference()));
    assertEquals(WSNHelper.getInstance().getWSAAddress(publisher.getEpr()), WSNHelper.getInstance().getWSAAddress(message.getProducerReference()));
    assertNotNull(message.getMessage().getAny());
    assertTrue(message.getMessage().getAny().getClass().getName(), message.getMessage().getAny() instanceof CustomType);
    subscription.unsubscribe();
    registration.destroy();
    publisher.stop();
    consumer.stop();
}
Also used : CustomType(org.apache.cxf.wsn.types.CustomType) Consumer(org.apache.cxf.wsn.client.Consumer) Registration(org.apache.cxf.wsn.client.Registration) Publisher(org.apache.cxf.wsn.client.Publisher) Subscription(org.apache.cxf.wsn.client.Subscription) NotificationMessageHolderType(org.oasis_open.docs.wsn.b_2.NotificationMessageHolderType) Test(org.junit.Test)

Example 9 with NotificationMessageHolderType

use of org.oasis_open.docs.wsn.b_2.NotificationMessageHolderType in project cxf by apache.

the class Client method main.

/**
 * @param args
 */
public static void main(String[] args) throws Exception {
    String wsnPort = "9000";
    if (args.length > 0) {
        wsnPort = args[0];
    }
    // Start a consumer that will listen for notification messages
    // We'll just print the text content out for now.
    Consumer consumer = new Consumer(new Consumer.Callback() {

        public void notify(NotificationMessageHolderType message) {
            Object o = message.getMessage().getAny();
            System.out.println(message.getMessage().getAny());
            if (o instanceof Element) {
                System.out.println(((Element) o).getTextContent());
            }
        }
    }, "http://localhost:9001/MyConsumer");
    // Create a subscription for a Topic on the broker
    NotificationBroker notificationBroker = new NotificationBroker("http://localhost:" + wsnPort + "/wsn/NotificationBroker");
    Subscription subscription = notificationBroker.subscribe(consumer, "MyTopic");
    // Send a notification on the Topic
    notificationBroker.notify("MyTopic", new JAXBElement<String>(new QName("urn:test:org", "foo"), String.class, "Hello World!"));
    // Just sleep for a bit to make sure the notification gets delivered
    Thread.sleep(5000);
    // Cleanup and exit
    subscription.unsubscribe();
    consumer.stop();
    System.exit(0);
}
Also used : Consumer(org.apache.cxf.wsn.client.Consumer) QName(javax.xml.namespace.QName) Element(org.w3c.dom.Element) JAXBElement(javax.xml.bind.JAXBElement) NotificationMessageHolderType(org.oasis_open.docs.wsn.b_2.NotificationMessageHolderType) Subscription(org.apache.cxf.wsn.client.Subscription) NotificationBroker(org.apache.cxf.wsn.client.NotificationBroker)

Example 10 with NotificationMessageHolderType

use of org.oasis_open.docs.wsn.b_2.NotificationMessageHolderType in project cxf by apache.

the class Consumer method notify.

public void notify(@WebParam(partName = "Notify", name = "Notify", targetNamespace = "http://docs.oasis-open.org/wsn/b-2") Notify notify) {
    for (NotificationMessageHolderType message : notify.getNotificationMessage()) {
        if (context != null) {
            Object o = message.getMessage().getAny();
            if (o instanceof Element) {
                try {
                    o = context.createUnmarshaller().unmarshal((Element) o);
                    message.getMessage().setAny(o);
                } catch (JAXBException e) {
                // ignore, leave as a DOM
                }
            }
        }
        this.callback.notify(message);
    }
}
Also used : Element(org.w3c.dom.Element) JAXBException(javax.xml.bind.JAXBException) NotificationMessageHolderType(org.oasis_open.docs.wsn.b_2.NotificationMessageHolderType)

Aggregations

NotificationMessageHolderType (org.oasis_open.docs.wsn.b_2.NotificationMessageHolderType)14 Subscription (org.apache.cxf.wsn.client.Subscription)8 QName (javax.xml.namespace.QName)7 Test (org.junit.Test)7 JAXBException (javax.xml.bind.JAXBException)6 Consumer (org.apache.cxf.wsn.client.Consumer)6 Notify (org.oasis_open.docs.wsn.b_2.Notify)5 JMSException (javax.jms.JMSException)4 Message (javax.jms.Message)3 TextMessage (javax.jms.TextMessage)3 Publisher (org.apache.cxf.wsn.client.Publisher)3 Registration (org.apache.cxf.wsn.client.Registration)3 Element (org.w3c.dom.Element)3 StringReader (java.io.StringReader)2 StringWriter (java.io.StringWriter)2 XMLStreamReader (javax.xml.stream.XMLStreamReader)2 CreatePullPoint (org.apache.cxf.wsn.client.CreatePullPoint)2 PullPoint (org.apache.cxf.wsn.client.PullPoint)2 JaxwsCreatePullPoint (org.apache.cxf.wsn.services.JaxwsCreatePullPoint)2 GetMessagesResponse (org.oasis_open.docs.wsn.b_2.GetMessagesResponse)2