Search in sources :

Example 1 with TopicExpressionType

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

use of org.oasis_open.docs.wsn.b_2.TopicExpressionType in project cxf by apache.

the class NotificationBroker method getCurrentMessage.

public List<Object> getCurrentMessage(String topic) throws // CHECKSTYLE:OFF - WS-Notification spec throws a lot of faults
TopicNotSupportedFault, TopicExpressionDialectUnknownFault, MultipleTopicsSpecifiedFault, InvalidTopicExpressionFault, ResourceUnknownFault, NoCurrentMessageOnTopicFault {
    // CHECKSTYLE:ON
    GetCurrentMessage getCurrentMessageRequest = new GetCurrentMessage();
    if (topic != null) {
        TopicExpressionType topicExp = new TopicExpressionType();
        topicExp.getContent().add(topic);
        getCurrentMessageRequest.setTopic(topicExp);
    }
    GetCurrentMessageResponse response = getBroker().getCurrentMessage(getCurrentMessageRequest);
    return response.getAny();
}
Also used : GetCurrentMessageResponse(org.oasis_open.docs.wsn.b_2.GetCurrentMessageResponse) TopicExpressionType(org.oasis_open.docs.wsn.b_2.TopicExpressionType) GetCurrentMessage(org.oasis_open.docs.wsn.b_2.GetCurrentMessage)

Example 3 with TopicExpressionType

use of org.oasis_open.docs.wsn.b_2.TopicExpressionType in project cxf by apache.

the class AbstractSubscription method validateSubscription.

protected void validateSubscription(Subscribe subscribeRequest) throws // CHECKSTYLE:OFF - WS-Notification spec throws a lot of faults
InvalidFilterFault, InvalidMessageContentExpressionFault, InvalidProducerPropertiesExpressionFault, InvalidTopicExpressionFault, SubscribeCreationFailedFault, TopicExpressionDialectUnknownFault, TopicNotSupportedFault, UnacceptableInitialTerminationTimeFault, UnrecognizedPolicyRequestFault, UnsupportedPolicyRequestFault {
    // CHECKSTYLE:ON
    // Check consumer reference
    consumerReference = subscribeRequest.getConsumerReference();
    // Check terminationTime
    if (subscribeRequest.getInitialTerminationTime() != null && !subscribeRequest.getInitialTerminationTime().isNil() && subscribeRequest.getInitialTerminationTime().getValue() != null) {
        String strTerminationTime = subscribeRequest.getInitialTerminationTime().getValue();
        terminationTime = validateInitialTerminationTime(strTerminationTime.trim());
    }
    // Check filter
    if (subscribeRequest.getFilter() != null) {
        for (Object f : subscribeRequest.getFilter().getAny()) {
            JAXBElement<?> e = null;
            if (f instanceof JAXBElement) {
                e = (JAXBElement<?>) f;
                f = e.getValue();
            }
            if (f instanceof TopicExpressionType) {
                if (!e.getName().equals(QNAME_TOPIC_EXPRESSION)) {
                    InvalidTopicExpressionFaultType fault = new InvalidTopicExpressionFaultType();
                    throw new InvalidTopicExpressionFault("Unrecognized TopicExpression: " + e, fault);
                }
                topic = (TopicExpressionType) f;
            } else if (f instanceof QueryExpressionType) {
                if (e != null && e.getName().equals(QNAME_PRODUCER_PROPERTIES)) {
                    InvalidProducerPropertiesExpressionFaultType fault = new InvalidProducerPropertiesExpressionFaultType();
                    throw new InvalidProducerPropertiesExpressionFault("ProducerProperties are not supported", fault);
                } else if (e != null && e.getName().equals(QNAME_MESSAGE_CONTENT)) {
                    if (contentFilter != null) {
                        InvalidMessageContentExpressionFaultType fault = new InvalidMessageContentExpressionFaultType();
                        throw new InvalidMessageContentExpressionFault("Only one MessageContent filter can be specified", fault);
                    }
                    contentFilter = (QueryExpressionType) f;
                    // Defaults to XPath 1.0
                    if (contentFilter.getDialect() == null) {
                        contentFilter.setDialect(XPATH1_URI);
                    }
                } else {
                    InvalidFilterFaultType fault = new InvalidFilterFaultType();
                    throw new InvalidFilterFault("Unrecognized filter: " + (e != null ? e.getName() : f), fault);
                }
            } else {
                InvalidFilterFaultType fault = new InvalidFilterFaultType();
                throw new InvalidFilterFault("Unrecognized filter: " + (e != null ? e.getName() : f), fault);
            }
        }
    }
    // Check policy
    if (subscribeRequest.getSubscriptionPolicy() != null) {
        for (Object p : subscribeRequest.getSubscriptionPolicy().getAny()) {
            JAXBElement<?> e = null;
            if (p instanceof JAXBElement) {
                e = (JAXBElement<?>) p;
                p = e.getValue();
            }
            if (p instanceof UseRaw) {
                useRaw = true;
            } else {
                UnrecognizedPolicyRequestFaultType fault = new UnrecognizedPolicyRequestFaultType();
                throw new UnrecognizedPolicyRequestFault("Unrecognized policy: " + p, fault);
            }
        }
    }
    // Check all parameters
    if (consumerReference == null) {
        SubscribeCreationFailedFaultType fault = new SubscribeCreationFailedFaultType();
        throw new SubscribeCreationFailedFault("Invalid ConsumerReference: null", fault);
    }
    // TODO check we can resolve endpoint
    if (topic == null) {
        InvalidFilterFaultType fault = new InvalidFilterFaultType();
        throw new InvalidFilterFault("Must specify a topic to subscribe on", fault);
    }
    if (contentFilter != null && !contentFilter.getDialect().equals(XPATH1_URI)) {
        InvalidMessageContentExpressionFaultType fault = new InvalidMessageContentExpressionFaultType();
        throw new InvalidMessageContentExpressionFault("Unsupported MessageContent dialect: '" + contentFilter.getDialect() + "'", fault);
    }
}
Also used : UnrecognizedPolicyRequestFaultType(org.oasis_open.docs.wsn.b_2.UnrecognizedPolicyRequestFaultType) UnrecognizedPolicyRequestFault(org.oasis_open.docs.wsn.bw_2.UnrecognizedPolicyRequestFault) SubscribeCreationFailedFault(org.oasis_open.docs.wsn.bw_2.SubscribeCreationFailedFault) InvalidMessageContentExpressionFaultType(org.oasis_open.docs.wsn.b_2.InvalidMessageContentExpressionFaultType) SubscribeCreationFailedFaultType(org.oasis_open.docs.wsn.b_2.SubscribeCreationFailedFaultType) QueryExpressionType(org.oasis_open.docs.wsn.b_2.QueryExpressionType) JAXBElement(javax.xml.bind.JAXBElement) InvalidFilterFault(org.oasis_open.docs.wsn.bw_2.InvalidFilterFault) UseRaw(org.oasis_open.docs.wsn.b_2.UseRaw) InvalidProducerPropertiesExpressionFaultType(org.oasis_open.docs.wsn.b_2.InvalidProducerPropertiesExpressionFaultType) InvalidFilterFaultType(org.oasis_open.docs.wsn.b_2.InvalidFilterFaultType) TopicExpressionType(org.oasis_open.docs.wsn.b_2.TopicExpressionType) InvalidProducerPropertiesExpressionFault(org.oasis_open.docs.wsn.bw_2.InvalidProducerPropertiesExpressionFault) InvalidTopicExpressionFaultType(org.oasis_open.docs.wsn.b_2.InvalidTopicExpressionFaultType) InvalidTopicExpressionFault(org.oasis_open.docs.wsn.bw_2.InvalidTopicExpressionFault) InvalidMessageContentExpressionFault(org.oasis_open.docs.wsn.bw_2.InvalidMessageContentExpressionFault)

Example 4 with TopicExpressionType

use of org.oasis_open.docs.wsn.b_2.TopicExpressionType in project cxf by apache.

the class JmsPublisher method start.

@Override
protected void start() throws PublisherRegistrationFailedFault {
    if (demand) {
        try {
            producers = new HashMap<>();
            advisories = new ArrayList<>();
            for (TopicExpressionType topic : this.topic) {
                ConsumerEventSource advisory = new ConsumerEventSource(connection, topicConverter.toActiveMQTopic(topic));
                advisory.setConsumerListener(this);
                advisory.start();
                advisories.add(advisory);
            }
        } catch (Exception e) {
            PublisherRegistrationFailedFaultType fault = new PublisherRegistrationFailedFaultType();
            throw new PublisherRegistrationFailedFault("Error starting demand-based publisher", fault, e);
        }
    }
}
Also used : PublisherRegistrationFailedFaultType(org.oasis_open.docs.wsn.br_2.PublisherRegistrationFailedFaultType) TopicExpressionType(org.oasis_open.docs.wsn.b_2.TopicExpressionType) ConsumerEventSource(org.apache.activemq.advisory.ConsumerEventSource) PublisherRegistrationFailedFault(org.oasis_open.docs.wsn.brw_2.PublisherRegistrationFailedFault) JMSException(javax.jms.JMSException) JAXBException(javax.xml.bind.JAXBException)

Example 5 with TopicExpressionType

use of org.oasis_open.docs.wsn.b_2.TopicExpressionType in project cxf by apache.

the class NotificationBroker method subscribe.

public Subscription subscribe(Referencable consumer, String topic, String xpath, boolean raw, String initialTerminationTime) throws // CHECKSTYLE:OFF - WS-Notification spec throws a lot of faults
TopicNotSupportedFault, InvalidFilterFault, TopicExpressionDialectUnknownFault, UnacceptableInitialTerminationTimeFault, SubscribeCreationFailedFault, InvalidMessageContentExpressionFault, InvalidTopicExpressionFault, UnrecognizedPolicyRequestFault, UnsupportedPolicyRequestFault, ResourceUnknownFault, NotifyMessageNotSupportedFault, InvalidProducerPropertiesExpressionFault {
    // CHECKSTYLE:ON
    Subscribe subscribeRequest = new Subscribe();
    if (initialTerminationTime != null) {
        subscribeRequest.setInitialTerminationTime(new JAXBElement<String>(QNAME_INITIAL_TERMINATION_TIME, String.class, initialTerminationTime));
    }
    subscribeRequest.setConsumerReference(consumer.getEpr());
    subscribeRequest.setFilter(new FilterType());
    if (topic != null) {
        TopicExpressionType topicExp = new TopicExpressionType();
        topicExp.getContent().add(topic);
        subscribeRequest.getFilter().getAny().add(new JAXBElement<TopicExpressionType>(QNAME_TOPIC_EXPRESSION, TopicExpressionType.class, topicExp));
    }
    if (xpath != null) {
        QueryExpressionType xpathExp = new QueryExpressionType();
        xpathExp.setDialect(XPATH1_URI);
        xpathExp.getContent().add(xpath);
        subscribeRequest.getFilter().getAny().add(new JAXBElement<QueryExpressionType>(QNAME_MESSAGE_CONTENT, QueryExpressionType.class, xpathExp));
    }
    if (raw) {
        subscribeRequest.setSubscriptionPolicy(new Subscribe.SubscriptionPolicy());
        subscribeRequest.getSubscriptionPolicy().getAny().add(new UseRaw());
    }
    SubscribeResponse response = getBroker().subscribe(subscribeRequest);
    return new Subscription(response.getSubscriptionReference());
}
Also used : FilterType(org.oasis_open.docs.wsn.b_2.FilterType) TopicExpressionType(org.oasis_open.docs.wsn.b_2.TopicExpressionType) QueryExpressionType(org.oasis_open.docs.wsn.b_2.QueryExpressionType) Subscribe(org.oasis_open.docs.wsn.b_2.Subscribe) SubscribeResponse(org.oasis_open.docs.wsn.b_2.SubscribeResponse) UseRaw(org.oasis_open.docs.wsn.b_2.UseRaw)

Aggregations

TopicExpressionType (org.oasis_open.docs.wsn.b_2.TopicExpressionType)9 SubscribeResponse (org.oasis_open.docs.wsn.b_2.SubscribeResponse)3 JAXBElement (javax.xml.bind.JAXBElement)2 JAXBException (javax.xml.bind.JAXBException)2 FilterType (org.oasis_open.docs.wsn.b_2.FilterType)2 InvalidFilterFaultType (org.oasis_open.docs.wsn.b_2.InvalidFilterFaultType)2 InvalidTopicExpressionFaultType (org.oasis_open.docs.wsn.b_2.InvalidTopicExpressionFaultType)2 QueryExpressionType (org.oasis_open.docs.wsn.b_2.QueryExpressionType)2 Subscribe (org.oasis_open.docs.wsn.b_2.Subscribe)2 UseRaw (org.oasis_open.docs.wsn.b_2.UseRaw)2 InvalidFilterFault (org.oasis_open.docs.wsn.bw_2.InvalidFilterFault)2 InvalidTopicExpressionFault (org.oasis_open.docs.wsn.bw_2.InvalidTopicExpressionFault)2 JMSException (javax.jms.JMSException)1 DOMResult (javax.xml.transform.dom.DOMResult)1 ConsumerEventSource (org.apache.activemq.advisory.ConsumerEventSource)1 GetCurrentMessage (org.oasis_open.docs.wsn.b_2.GetCurrentMessage)1 GetCurrentMessageResponse (org.oasis_open.docs.wsn.b_2.GetCurrentMessageResponse)1 InvalidMessageContentExpressionFaultType (org.oasis_open.docs.wsn.b_2.InvalidMessageContentExpressionFaultType)1 InvalidProducerPropertiesExpressionFaultType (org.oasis_open.docs.wsn.b_2.InvalidProducerPropertiesExpressionFaultType)1 NotificationMessageHolderType (org.oasis_open.docs.wsn.b_2.NotificationMessageHolderType)1