Search in sources :

Example 1 with UnableToGetMessagesFaultType

use of org.oasis_open.docs.wsn.b_2.UnableToGetMessagesFaultType 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)

Aggregations

StringReader (java.io.StringReader)1 ArrayList (java.util.ArrayList)1 JMSException (javax.jms.JMSException)1 Message (javax.jms.Message)1 TextMessage (javax.jms.TextMessage)1 JAXBException (javax.xml.bind.JAXBException)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 XMLStreamReader (javax.xml.stream.XMLStreamReader)1 AbstractPullPoint (org.apache.cxf.wsn.AbstractPullPoint)1 NotificationMessageHolderType (org.oasis_open.docs.wsn.b_2.NotificationMessageHolderType)1 Notify (org.oasis_open.docs.wsn.b_2.Notify)1 UnableToGetMessagesFaultType (org.oasis_open.docs.wsn.b_2.UnableToGetMessagesFaultType)1 UnableToGetMessagesFault (org.oasis_open.docs.wsn.bw_2.UnableToGetMessagesFault)1