use of org.oasis_open.docs.wsn.b_2.NotificationMessageHolderType in project cxf by apache.
the class AbstractNotificationBroker method handleNotify.
protected void handleNotify(Notify notify) {
for (NotificationMessageHolderType messageHolder : notify.getNotificationMessage()) {
W3CEndpointReference producerReference = messageHolder.getProducerReference();
AbstractPublisher publisher = getPublisher(producerReference);
if (publisher != null) {
publisher.notify(messageHolder);
}
}
}
use of org.oasis_open.docs.wsn.b_2.NotificationMessageHolderType in project cxf by apache.
the class AbstractPullPoint method getMessages.
/**
* @param getMessagesRequest
* @return returns org.oasis_open.docs.wsn.b_1.GetMessagesResponse
* @throws ResourceUnknownFault
* @throws UnableToGetMessagesFault
*/
@WebMethod(operationName = "GetMessages")
@WebResult(name = "GetMessagesResponse", targetNamespace = "http://docs.oasis-open.org/wsn/b-1", partName = "GetMessagesResponse")
public GetMessagesResponse getMessages(@WebParam(name = "GetMessages", targetNamespace = "http://docs.oasis-open.org/wsn/b-1", partName = "GetMessagesRequest") GetMessages getMessagesRequest) throws ResourceUnknownFault, UnableToGetMessagesFault {
LOGGER.finest("GetMessages");
BigInteger max = getMessagesRequest.getMaximumNumber();
List<NotificationMessageHolderType> messages = getMessages(max != null ? max.intValue() : 0);
GetMessagesResponse response = new GetMessagesResponse();
response.getNotificationMessage().addAll(messages);
return response;
}
use of org.oasis_open.docs.wsn.b_2.NotificationMessageHolderType in project cxf by apache.
the class JmsPublisher method notify.
@Override
public void notify(NotificationMessageHolderType messageHolder) {
Session session = null;
try {
Topic topic = topicConverter.toActiveMQTopic(messageHolder.getTopic());
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = session.createProducer(topic);
Notify notify = new Notify();
notify.getNotificationMessage().add(messageHolder);
StringWriter writer = new StringWriter();
jaxbContext.createMarshaller().marshal(notify, writer);
Message message = session.createTextMessage(writer.toString());
producer.send(message);
} catch (JMSException e) {
LOGGER.log(Level.WARNING, "Error dispatching message", e);
} catch (JAXBException e) {
LOGGER.log(Level.WARNING, "Error dispatching message", e);
} catch (InvalidTopicException e) {
LOGGER.log(Level.WARNING, "Error dispatching message", e);
} finally {
if (session != null) {
try {
session.close();
} catch (JMSException e) {
LOGGER.log(Level.FINE, "Error closing session", e);
}
}
}
}
use of org.oasis_open.docs.wsn.b_2.NotificationMessageHolderType in project cxf by apache.
the class JmsPullPoint method store.
@Override
protected void store(NotificationMessageHolderType messageHolder) {
try {
initSession();
Notify notify = new Notify();
notify.getNotificationMessage().add(messageHolder);
StringWriter writer = new StringWriter();
jaxbContext.createMarshaller().marshal(notify, writer);
synchronized (producerSession) {
Message message = producerSession.createTextMessage(writer.toString());
producer.send(message);
}
} catch (JMSException e) {
LOGGER.log(Level.WARNING, "Error storing message", e);
closeSession();
} catch (JAXBException e) {
LOGGER.log(Level.WARNING, "Error storing message", e);
}
}
use of org.oasis_open.docs.wsn.b_2.NotificationMessageHolderType 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