Search in sources :

Example 1 with Registration

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

use of org.apache.cxf.wsn.client.Registration 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();
}
Also used : Consumer(org.apache.cxf.wsn.client.Consumer) Registration(org.apache.cxf.wsn.client.Registration) QName(javax.xml.namespace.QName) 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 3 with Registration

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

the class WsnBrokerTest method testPublisherOnDemand.

@Test
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();
}
Also used : Consumer(org.apache.cxf.wsn.client.Consumer) Registration(org.apache.cxf.wsn.client.Registration) QName(javax.xml.namespace.QName) Publisher(org.apache.cxf.wsn.client.Publisher) Subscription(org.apache.cxf.wsn.client.Subscription) Test(org.junit.Test)

Example 4 with Registration

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

the class WsnBrokerTest method testNullPublisherReference.

@Test
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.getInstance().getWSAAddress(subscription.getEpr()), WSNHelper.getInstance().getWSAAddress(message.getSubscriptionReference()));
    subscription.unsubscribe();
    registration.destroy();
    publisher.stop();
    consumer.stop();
}
Also used : Consumer(org.apache.cxf.wsn.client.Consumer) Registration(org.apache.cxf.wsn.client.Registration) QName(javax.xml.namespace.QName) 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)

Aggregations

Consumer (org.apache.cxf.wsn.client.Consumer)4 Publisher (org.apache.cxf.wsn.client.Publisher)4 Registration (org.apache.cxf.wsn.client.Registration)4 Subscription (org.apache.cxf.wsn.client.Subscription)4 Test (org.junit.Test)4 QName (javax.xml.namespace.QName)3 NotificationMessageHolderType (org.oasis_open.docs.wsn.b_2.NotificationMessageHolderType)3 CustomType (org.apache.cxf.wsn.types.CustomType)1