use of org.apache.cxf.wsn.client.Consumer 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();
}
use of org.apache.cxf.wsn.client.Consumer 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();
}
use of org.apache.cxf.wsn.client.Consumer 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();
}
use of org.apache.cxf.wsn.client.Consumer 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);
}
use of org.apache.cxf.wsn.client.Consumer in project cxf by apache.
the class WsnBrokerTest method testPublisher.
@Test
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.getInstance().getWSAAddress(subscription.getEpr()), WSNHelper.getInstance().getWSAAddress(message.getSubscriptionReference()));
assertEquals(WSNHelper.getInstance().getWSAAddress(publisher.getEpr()), WSNHelper.getInstance().getWSAAddress(message.getProducerReference()));
subscription.unsubscribe();
registration.destroy();
publisher.stop();
consumer.stop();
}
Aggregations