Search in sources :

Example 11 with NotificationMessageHolderType

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);
        }
    }
}
Also used : W3CEndpointReference(javax.xml.ws.wsaddressing.W3CEndpointReference) NotificationMessageHolderType(org.oasis_open.docs.wsn.b_2.NotificationMessageHolderType)

Example 12 with NotificationMessageHolderType

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;
}
Also used : GetMessagesResponse(org.oasis_open.docs.wsn.b_2.GetMessagesResponse) BigInteger(java.math.BigInteger) NotificationMessageHolderType(org.oasis_open.docs.wsn.b_2.NotificationMessageHolderType) WebMethod(javax.jws.WebMethod) WebResult(javax.jws.WebResult)

Example 13 with NotificationMessageHolderType

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);
            }
        }
    }
}
Also used : StringWriter(java.io.StringWriter) Message(javax.jms.Message) Notify(org.oasis_open.docs.wsn.b_2.Notify) JAXBException(javax.xml.bind.JAXBException) JMSException(javax.jms.JMSException) MessageProducer(javax.jms.MessageProducer) Topic(javax.jms.Topic) Session(javax.jms.Session)

Example 14 with NotificationMessageHolderType

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);
    }
}
Also used : StringWriter(java.io.StringWriter) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) Notify(org.oasis_open.docs.wsn.b_2.Notify) JAXBException(javax.xml.bind.JAXBException) JMSException(javax.jms.JMSException)

Example 15 with NotificationMessageHolderType

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();
}
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

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