Search in sources :

Example 1 with NotificationMessageHolderType

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);
}
Also used : DOMResult(javax.xml.transform.dom.DOMResult) Notify(org.oasis_open.docs.wsn.b_2.Notify) TopicExpressionType(org.oasis_open.docs.wsn.b_2.TopicExpressionType) JAXBException(javax.xml.bind.JAXBException) Document(org.w3c.dom.Document) NotificationMessageHolderType(org.oasis_open.docs.wsn.b_2.NotificationMessageHolderType)

Example 2 with NotificationMessageHolderType

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();
}
Also used : GetMessagesResponse(org.oasis_open.docs.wsn.b_2.GetMessagesResponse) GetMessages(org.oasis_open.docs.wsn.b_2.GetMessages)

Example 3 with NotificationMessageHolderType

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);
    }
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) Notify(org.oasis_open.docs.wsn.b_2.Notify) JAXBException(javax.xml.bind.JAXBException) ArrayList(java.util.ArrayList) JMSException(javax.jms.JMSException) NotificationMessageHolderType(org.oasis_open.docs.wsn.b_2.NotificationMessageHolderType) AbstractPullPoint(org.apache.cxf.wsn.AbstractPullPoint) UnableToGetMessagesFaultType(org.oasis_open.docs.wsn.b_2.UnableToGetMessagesFaultType) XMLStreamException(javax.xml.stream.XMLStreamException) StringReader(java.io.StringReader) UnableToGetMessagesFault(org.oasis_open.docs.wsn.bw_2.UnableToGetMessagesFault) TextMessage(javax.jms.TextMessage)

Example 4 with NotificationMessageHolderType

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);
    }
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) Notify(org.oasis_open.docs.wsn.b_2.Notify) Element(org.w3c.dom.Element) StringReader(java.io.StringReader) NotificationMessageHolderType(org.oasis_open.docs.wsn.b_2.NotificationMessageHolderType) TextMessage(javax.jms.TextMessage) DocumentFragment(org.w3c.dom.DocumentFragment) XPathExpressionException(javax.xml.xpath.XPathExpressionException) JMSException(javax.jms.JMSException) JAXBException(javax.xml.bind.JAXBException)

Example 5 with NotificationMessageHolderType

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();
}
Also used : QName(javax.xml.namespace.QName) JaxwsCreatePullPoint(org.apache.cxf.wsn.services.JaxwsCreatePullPoint) PullPoint(org.apache.cxf.wsn.client.PullPoint) CreatePullPoint(org.apache.cxf.wsn.client.CreatePullPoint) Subscription(org.apache.cxf.wsn.client.Subscription) NotificationMessageHolderType(org.oasis_open.docs.wsn.b_2.NotificationMessageHolderType) JaxwsCreatePullPoint(org.apache.cxf.wsn.services.JaxwsCreatePullPoint) PullPoint(org.apache.cxf.wsn.client.PullPoint) CreatePullPoint(org.apache.cxf.wsn.client.CreatePullPoint) Test(org.junit.Test)

Aggregations

NotificationMessageHolderType (org.oasis_open.docs.wsn.b_2.NotificationMessageHolderType)14 Subscription (org.apache.cxf.wsn.client.Subscription)8 QName (javax.xml.namespace.QName)7 Test (org.junit.Test)7 JAXBException (javax.xml.bind.JAXBException)6 Consumer (org.apache.cxf.wsn.client.Consumer)6 Notify (org.oasis_open.docs.wsn.b_2.Notify)5 JMSException (javax.jms.JMSException)4 Message (javax.jms.Message)3 TextMessage (javax.jms.TextMessage)3 Publisher (org.apache.cxf.wsn.client.Publisher)3 Registration (org.apache.cxf.wsn.client.Registration)3 Element (org.w3c.dom.Element)3 StringReader (java.io.StringReader)2 StringWriter (java.io.StringWriter)2 XMLStreamReader (javax.xml.stream.XMLStreamReader)2 CreatePullPoint (org.apache.cxf.wsn.client.CreatePullPoint)2 PullPoint (org.apache.cxf.wsn.client.PullPoint)2 JaxwsCreatePullPoint (org.apache.cxf.wsn.services.JaxwsCreatePullPoint)2 GetMessagesResponse (org.oasis_open.docs.wsn.b_2.GetMessagesResponse)2