Search in sources :

Example 1 with NotificationBroker

use of org.apache.cxf.wsn.client.NotificationBroker 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 2 with NotificationBroker

use of org.apache.cxf.wsn.client.NotificationBroker in project cxf by apache.

the class WsnBrokerTest method setUp.

@Before
public void setUp() throws Exception {
    loader = Thread.currentThread().getContextClassLoader();
    String impl = getProviderImpl();
    Thread.currentThread().setContextClassLoader(new FakeClassLoader(impl));
    WSNHelper.getInstance().setClassLoader(false);
    System.setProperty("javax.xml.ws.spi.Provider", impl);
    port2 = getFreePort();
    if (!useExternal) {
        port1 = getFreePort();
        int brokerPort = getFreePort();
        activemq = new ActiveMQConnectionFactory("vm:(broker:(tcp://localhost:" + brokerPort + ")?persistent=false)");
        notificationBrokerServer = new JaxwsNotificationBroker("WSNotificationBroker", activemq);
        notificationBrokerServer.setAddress("http://localhost:" + port1 + "/wsn/NotificationBroker");
        notificationBrokerServer.init();
        createPullPointServer = new JaxwsCreatePullPoint("CreatePullPoint", activemq);
        createPullPointServer.setAddress("http://localhost:" + port1 + "/wsn/CreatePullPoint");
        createPullPointServer.init();
    }
    notificationBroker = new NotificationBroker("http://localhost:" + port1 + "/wsn/NotificationBroker");
    createPullPoint = new CreatePullPoint("http://localhost:" + port1 + "/wsn/CreatePullPoint");
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) JaxwsCreatePullPoint(org.apache.cxf.wsn.services.JaxwsCreatePullPoint) JaxwsNotificationBroker(org.apache.cxf.wsn.services.JaxwsNotificationBroker) JaxwsCreatePullPoint(org.apache.cxf.wsn.services.JaxwsCreatePullPoint) PullPoint(org.apache.cxf.wsn.client.PullPoint) CreatePullPoint(org.apache.cxf.wsn.client.CreatePullPoint) JaxwsNotificationBroker(org.apache.cxf.wsn.services.JaxwsNotificationBroker) NotificationBroker(org.apache.cxf.wsn.client.NotificationBroker) JaxwsCreatePullPoint(org.apache.cxf.wsn.services.JaxwsCreatePullPoint) CreatePullPoint(org.apache.cxf.wsn.client.CreatePullPoint) Before(org.junit.Before)

Aggregations

NotificationBroker (org.apache.cxf.wsn.client.NotificationBroker)2 JAXBElement (javax.xml.bind.JAXBElement)1 QName (javax.xml.namespace.QName)1 ActiveMQConnectionFactory (org.apache.activemq.ActiveMQConnectionFactory)1 Consumer (org.apache.cxf.wsn.client.Consumer)1 CreatePullPoint (org.apache.cxf.wsn.client.CreatePullPoint)1 PullPoint (org.apache.cxf.wsn.client.PullPoint)1 Subscription (org.apache.cxf.wsn.client.Subscription)1 JaxwsCreatePullPoint (org.apache.cxf.wsn.services.JaxwsCreatePullPoint)1 JaxwsNotificationBroker (org.apache.cxf.wsn.services.JaxwsNotificationBroker)1 Before (org.junit.Before)1 NotificationMessageHolderType (org.oasis_open.docs.wsn.b_2.NotificationMessageHolderType)1 Element (org.w3c.dom.Element)1