Package org.apache.cxf.wsn.client

Examples of org.apache.cxf.wsn.client.Consumer$Callback


        System.clearProperty("javax.xml.ws.spi.Provider");
    }

    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.getWSAAddress(subscription.getEpr()),
                     WSNHelper.getWSAAddress(message.getSubscriptionReference()));

        subscription.unsubscribe();
        consumer.stop();
    }
View Full Code Here


        pullPoint.destroy();
    }

    public void testPublisher() throws Exception {
        TestConsumer consumerCallback = new TestConsumer();
        Consumer consumer = new Consumer(consumerCallback, "http://localhost:" + port2 + "/test/consumer");

        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 JAXBElement<String>(new QName("urn:test:org", "foo"),
                                                      String.class, "bar"));
            consumerCallback.notifications.wait(1000000);
        }
        assertEquals(1, consumerCallback.notifications.size());
        NotificationMessageHolderType message = consumerCallback.notifications.get(0);
        assertEquals(WSNHelper.getWSAAddress(subscription.getEpr()),
                     WSNHelper.getWSAAddress(message.getSubscriptionReference()));
        assertEquals(WSNHelper.getWSAAddress(publisher.getEpr()),
                     WSNHelper.getWSAAddress(message.getProducerReference()));

        subscription.unsubscribe();
        registration.destroy();
        publisher.stop();
        consumer.stop();
    }
View Full Code Here

        consumer.stop();
    }

    public void testPublisherOnDemand() throws Exception {
        TestConsumer consumerCallback = new TestConsumer();
        Consumer consumer = new Consumer(consumerCallback, "http://localhost:" + port2 + "/test/consumer");

        PublisherCallback publisherCallback = new PublisherCallback();
        Publisher publisher = new Publisher(publisherCallback, "http://localhost:"
            + port2 + "/test/publisher");
        Registration registration = notificationBroker.registerPublisher(publisher,
                                                                         Arrays.asList("myTopic1",
                                                                                       "myTopic2"), true);

        Subscription subscription = notificationBroker.subscribe(consumer, "myTopic1");
        assertTrue(publisherCallback.subscribed.await(5, TimeUnit.SECONDS));

        synchronized (consumerCallback.notifications) {
            notificationBroker.notify(publisher, "myTopic1",
                                      new JAXBElement<String>(new QName("urn:test:org", "foo"),
                                                      String.class, "bar"));
            consumerCallback.notifications.wait(1000000);
        }

        subscription.unsubscribe();

        assertTrue(publisherCallback.unsubscribed.await(5, TimeUnit.SECONDS));

        registration.destroy();
        publisher.stop();
        consumer.stop();
    }
View Full Code Here

            wsnPort = args[0];
        }

        // Start a consumer that will listen for notification messages
        // We'll print the email fields out.
        Consumer consumer = new Consumer(new Consumer.Callback() {
            public void notify(NotificationMessageHolderType message) {
                Object o = message.getMessage().getAny();

                if (o instanceof Element) {
                    Element e = (Element)o;
                    System.out.println();
                    System.out.println("From: "+e.getElementsByTagNameNS(mailNs,"from").item(0).getTextContent());
                    System.out.println("To: "+e.getElementsByTagNameNS(mailNs,"to").item(0).getTextContent());
                    System.out.println("Subject: "+e.getElementsByTagNameNS(mailNs,"subject").item(0).getTextContent());
                    System.out.println("Body: "+e.getElementsByTagNameNS(mailNs,"body").item(0).getTextContent());
                    System.out.println();
                }else {
                    System.out.println(o);
                }
            }
        }, "http://localhost:9001/MyConsumer");


        // Create a subscription for a Topic on the broker
        NotificationBroker notificationBroker
                = new NotificationBroker("http://localhost:" + wsnPort + "/wsn/NotificationBroker",Email.class);
        Subscription subscription = notificationBroker.subscribe(consumer, topic);

        // Create new email object to send
        Email mail =  new Email("standalone@client.com","you@gotmail.com","This is the standalone client speaking","This thing works!");

        // Send a notification on the Topic
        notificationBroker.notify(topic,mail);

        // 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);
    }
View Full Code Here

            .setContextClassLoader(loader);
    }

    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.getWSAAddress(subscription.getEpr()),
                     WSNHelper.getWSAAddress(message.getSubscriptionReference()));

        subscription.unsubscribe();
        consumer.stop();
    }
View Full Code Here

        pullPoint.destroy();
    }

    public void testPublisher() throws Exception {
        TestConsumer consumerCallback = new TestConsumer();
        Consumer consumer = new Consumer(consumerCallback, "http://localhost:" + port2 + "/test/consumer");

        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 JAXBElement<String>(new QName("urn:test:org", "foo"),
                                                      String.class, "bar"));
            consumerCallback.notifications.wait(1000000);
        }
        assertEquals(1, consumerCallback.notifications.size());
        NotificationMessageHolderType message = consumerCallback.notifications.get(0);
        assertEquals(WSNHelper.getWSAAddress(subscription.getEpr()),
                     WSNHelper.getWSAAddress(message.getSubscriptionReference()));
        assertEquals(WSNHelper.getWSAAddress(publisher.getEpr()),
                     WSNHelper.getWSAAddress(message.getProducerReference()));

        subscription.unsubscribe();
        registration.destroy();
        publisher.stop();
        consumer.stop();
    }
View Full Code Here

        publisher.stop();
        consumer.stop();
    }
    public void testNullPublisherReference() throws Exception {
        TestConsumer consumerCallback = new TestConsumer();
        Consumer consumer = new Consumer(consumerCallback, "http://localhost:" + port2 + "/test/consumer");

        Subscription subscription = notificationBroker.subscribe(consumer, "myTopicNullEPR");

        Publisher publisher = new Publisher(null, null);
        Registration registration = notificationBroker.registerPublisher(publisher, "myTopicNullEPR", false);

        synchronized (consumerCallback.notifications) {
            notificationBroker.notify(publisher, "myTopicNullEPR",
                                      new JAXBElement<String>(new QName("urn:test:org", "foo"),
                                                      String.class, "bar"));
            consumerCallback.notifications.wait(1000000);
        }
        assertEquals(1, consumerCallback.notifications.size());
        NotificationMessageHolderType message = consumerCallback.notifications.get(0);
        assertEquals(WSNHelper.getWSAAddress(subscription.getEpr()),
                     WSNHelper.getWSAAddress(message.getSubscriptionReference()));

        subscription.unsubscribe();
        registration.destroy();
        publisher.stop();
        consumer.stop();
    }
View Full Code Here

        publisher.stop();
        consumer.stop();
    }
    public void testPublisherOnDemand() throws Exception {
        TestConsumer consumerCallback = new TestConsumer();
        Consumer consumer = new Consumer(consumerCallback, "http://localhost:" + port2 + "/test/consumer");

        PublisherCallback publisherCallback = new PublisherCallback();
        Publisher publisher = new Publisher(publisherCallback, "http://localhost:"
            + port2 + "/test/publisher");
        Registration registration = notificationBroker.registerPublisher(publisher,
                                                                         Arrays.asList("myTopic1",
                                                                                       "myTopic2"), true);

        Subscription subscription = notificationBroker.subscribe(consumer, "myTopic1");
        assertTrue(publisherCallback.subscribed.await(5, TimeUnit.SECONDS));

        synchronized (consumerCallback.notifications) {
            notificationBroker.notify(publisher, "myTopic1",
                                      new JAXBElement<String>(new QName("urn:test:org", "foo"),
                                                      String.class, "bar"));
            consumerCallback.notifications.wait(1000000);
        }

        subscription.unsubscribe();

        assertTrue(publisherCallback.unsubscribed.await(5, TimeUnit.SECONDS));

        registration.destroy();
        publisher.stop();
        consumer.stop();
    }
View Full Code Here

            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);
    }
View Full Code Here

        System.clearProperty("javax.xml.ws.spi.Provider");
    }

    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.getWSAAddress(subscription.getEpr()),
                     WSNHelper.getWSAAddress(message.getSubscriptionReference()));

        subscription.unsubscribe();
        consumer.stop();
    }
View Full Code Here

TOP

Related Classes of org.apache.cxf.wsn.client.Consumer$Callback

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.