use of org.oasis_open.docs.wsn.b_2.NotificationMessageHolderType in project cxf by apache.
the class NotificationBroker method notify.
public void notify(Referencable publisher, String topic, Object msg) {
getBroker();
if (this.context != null) {
try {
DOMResult result = new DOMResult();
context.createMarshaller().marshal(msg, result);
msg = result.getNode();
if (msg instanceof Document) {
msg = ((Document) msg).getDocumentElement();
}
} catch (JAXBException e) {
// ignore, we'll try and let the runtime handle it as is
}
}
Notify notify = new Notify();
NotificationMessageHolderType holder = new NotificationMessageHolderType();
if (publisher != null) {
holder.setProducerReference(publisher.getEpr());
}
if (topic != null) {
TopicExpressionType topicExp = new TopicExpressionType();
topicExp.getContent().add(topic);
holder.setTopic(topicExp);
}
holder.setMessage(new NotificationMessageHolderType.Message());
holder.getMessage().setAny(msg);
notify.getNotificationMessage().add(holder);
getBroker().notify(notify);
}
use of org.oasis_open.docs.wsn.b_2.NotificationMessageHolderType in project cxf by apache.
the class PullPoint method getMessages.
public List<NotificationMessageHolderType> getMessages(long max) throws UnableToGetMessagesFault, ResourceUnknownFault {
GetMessages getMessages = new GetMessages();
getMessages.setMaximumNumber(BigInteger.valueOf(max));
GetMessagesResponse response = pullPoint.getMessages(getMessages);
return response.getNotificationMessage();
}
use of org.oasis_open.docs.wsn.b_2.NotificationMessageHolderType in project cxf by apache.
the class JmsPullPoint method getMessages.
@Override
protected List<NotificationMessageHolderType> getMessages(int max) throws ResourceUnknownFault, UnableToGetMessagesFault {
try {
if (max == 0) {
max = 256;
}
initSession();
List<NotificationMessageHolderType> messages = new ArrayList<>();
for (int i = 0; i < max; i++) {
Message msg = null;
synchronized (consumerSession) {
msg = consumer.receiveNoWait();
}
if (msg == null) {
break;
}
TextMessage txtMsg = (TextMessage) msg;
StringReader reader = new StringReader(txtMsg.getText());
XMLStreamReader xreader = StaxUtils.createXMLStreamReader(reader);
Notify notify = (Notify) jaxbContext.createUnmarshaller().unmarshal(xreader);
try {
xreader.close();
} catch (XMLStreamException e) {
// ignoreable
}
messages.addAll(notify.getNotificationMessage());
}
return messages;
} catch (JMSException e) {
LOGGER.log(Level.INFO, "Error retrieving messages", e);
closeSession();
UnableToGetMessagesFaultType fault = new UnableToGetMessagesFaultType();
throw new UnableToGetMessagesFault("Unable to retrieve messages", fault, e);
} catch (JAXBException e) {
LOGGER.log(Level.INFO, "Error retrieving messages", e);
UnableToGetMessagesFaultType fault = new UnableToGetMessagesFaultType();
throw new UnableToGetMessagesFault("Unable to retrieve messages", fault, e);
}
}
use of org.oasis_open.docs.wsn.b_2.NotificationMessageHolderType in project cxf by apache.
the class JmsSubscription method onMessage.
public void onMessage(Message jmsMessage) {
try {
TextMessage text = (TextMessage) jmsMessage;
XMLStreamReader reader = StaxUtils.createXMLStreamReader(new StringReader(text.getText()));
Notify notify = (Notify) jaxbContext.createUnmarshaller().unmarshal(reader);
reader.close();
for (Iterator<NotificationMessageHolderType> ith = notify.getNotificationMessage().iterator(); ith.hasNext(); ) {
NotificationMessageHolderType h = ith.next();
Object content = h.getMessage().getAny();
if (!(content instanceof Element)) {
DocumentFragment doc = DOMUtils.getEmptyDocument().createDocumentFragment();
jaxbContext.createMarshaller().marshal(content, doc);
content = DOMUtils.getFirstElement(doc);
}
if (!doFilter((Element) content)) {
ith.remove();
} else {
h.setTopic(topic);
h.setSubscriptionReference(getEpr());
}
}
if (!notify.getNotificationMessage().isEmpty()) {
doNotify(notify);
}
} catch (Exception e) {
LOGGER.log(Level.WARNING, "Error notifying consumer", e);
}
}
use of org.oasis_open.docs.wsn.b_2.NotificationMessageHolderType in project cxf by apache.
the class WsnBrokerTest method testPullPoint.
@Test
public void testPullPoint() throws Exception {
PullPoint pullPoint = createPullPoint.create();
Subscription subscription = notificationBroker.subscribe(pullPoint, "myTopic");
notificationBroker.notify("myTopic", new JAXBElement<String>(new QName("urn:test:org", "foo"), String.class, "bar"));
boolean received = false;
for (int i = 0; i < 50; i++) {
List<NotificationMessageHolderType> messages = pullPoint.getMessages(10);
if (!messages.isEmpty()) {
received = true;
break;
}
Thread.sleep(100);
}
assertTrue(received);
subscription.unsubscribe();
pullPoint.destroy();
}
Aggregations