Search in sources :

Example 1 with SubscribeResponse

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

the class AbstractNotificationBroker method handleSubscribe.

public SubscribeResponse handleSubscribe(Subscribe subscribeRequest, EndpointManager manager) throws // CHECKSTYLE:OFF - WS-Notification spec throws a lot of faults
InvalidFilterFault, InvalidMessageContentExpressionFault, InvalidProducerPropertiesExpressionFault, InvalidTopicExpressionFault, SubscribeCreationFailedFault, TopicExpressionDialectUnknownFault, TopicNotSupportedFault, UnacceptableInitialTerminationTimeFault, UnsupportedPolicyRequestFault, UnrecognizedPolicyRequestFault {
    // CHECKSTYLE:ON
    AbstractSubscription subscription = null;
    boolean success = false;
    try {
        subscription = createSubscription(idGenerator.generateSanitizedId());
        subscription.setBroker(this);
        subscriptions.put(subscription.getAddress(), subscription);
        subscription.create(subscribeRequest);
        if (manager != null) {
            subscription.setManager(manager);
        }
        subscription.register();
        SubscribeResponse response = new SubscribeResponse();
        response.setSubscriptionReference(subscription.getEpr());
        success = true;
        return response;
    } catch (EndpointRegistrationException e) {
        LOGGER.log(Level.WARNING, "Unable to register new endpoint", e);
        SubscribeCreationFailedFaultType fault = new SubscribeCreationFailedFaultType();
        throw new SubscribeCreationFailedFault("Unable to register new endpoint", fault, e);
    } finally {
        if (!success && subscription != null) {
            if (subscription.getAddress() != null) {
                subscriptions.remove(subscription.getAddress());
            }
            try {
                subscription.unsubscribe();
            } catch (UnableToDestroySubscriptionFault e) {
                LOGGER.log(Level.INFO, "Error destroying subscription", e);
            }
        }
    }
}
Also used : SubscribeCreationFailedFault(org.oasis_open.docs.wsn.bw_2.SubscribeCreationFailedFault) UnableToDestroySubscriptionFault(org.oasis_open.docs.wsn.bw_2.UnableToDestroySubscriptionFault) SubscribeCreationFailedFaultType(org.oasis_open.docs.wsn.b_2.SubscribeCreationFailedFaultType) SubscribeResponse(org.oasis_open.docs.wsn.b_2.SubscribeResponse)

Example 2 with SubscribeResponse

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

Example 3 with SubscribeResponse

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

the class Publisher method subscribe.

public SubscribeResponse subscribe(@WebParam(partName = "SubscribeRequest", name = "Subscribe", targetNamespace = "http://docs.oasis-open.org/wsn/b-2") Subscribe subscribeRequest) throws // CHECKSTYLE:OFF - WS-Notification spec throws a lot of faults
InvalidTopicExpressionFault, ResourceUnknownFault, InvalidProducerPropertiesExpressionFault, UnrecognizedPolicyRequestFault, TopicExpressionDialectUnknownFault, NotifyMessageNotSupportedFault, InvalidFilterFault, UnsupportedPolicyRequestFault, InvalidMessageContentExpressionFault, SubscribeCreationFailedFault, TopicNotSupportedFault, UnacceptableInitialTerminationTimeFault {
    // CHECKSYTLE:ON
    TopicExpressionType topic = null;
    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;
            }
        }
    }
    if (topic == null) {
        InvalidFilterFaultType fault = new InvalidFilterFaultType();
        throw new InvalidFilterFault("Must specify a topic to subscribe on", fault);
    }
    PublisherSubscription pub = new PublisherSubscription(topic);
    SubscribeResponse response = new SubscribeResponse();
    response.setSubscriptionReference(pub.getEpr());
    callback.subscribe(topic);
    return response;
}
Also used : InvalidFilterFaultType(org.oasis_open.docs.wsn.b_2.InvalidFilterFaultType) TopicExpressionType(org.oasis_open.docs.wsn.b_2.TopicExpressionType) InvalidTopicExpressionFaultType(org.oasis_open.docs.wsn.b_2.InvalidTopicExpressionFaultType) JAXBElement(javax.xml.bind.JAXBElement) SubscribeResponse(org.oasis_open.docs.wsn.b_2.SubscribeResponse) InvalidTopicExpressionFault(org.oasis_open.docs.wsn.bw_2.InvalidTopicExpressionFault) InvalidFilterFault(org.oasis_open.docs.wsn.bw_2.InvalidFilterFault)

Example 4 with SubscribeResponse

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

the class JaxwsPublisher method startSubscription.

@Override
protected Object startSubscription(TopicExpressionType topic) {
    try {
        Subscribe subscribeRequest = new Subscribe();
        subscribeRequest.setConsumerReference(notificationBroker.getEpr());
        subscribeRequest.setFilter(new FilterType());
        subscribeRequest.getFilter().getAny().add(new JAXBElement<TopicExpressionType>(AbstractSubscription.QNAME_TOPIC_EXPRESSION, TopicExpressionType.class, topic));
        SubscribeResponse response = notificationProducer.subscribe(subscribeRequest);
        return WSNHelper.getInstance().getPort(response.getSubscriptionReference(), SubscriptionManager.class);
    } catch (Exception e) {
        LOGGER.log(Level.INFO, "Error while subscribing on-demand publisher", e);
        return null;
    }
}
Also used : FilterType(org.oasis_open.docs.wsn.b_2.FilterType) TopicExpressionType(org.oasis_open.docs.wsn.b_2.TopicExpressionType) Subscribe(org.oasis_open.docs.wsn.b_2.Subscribe) SubscribeResponse(org.oasis_open.docs.wsn.b_2.SubscribeResponse)

Aggregations

SubscribeResponse (org.oasis_open.docs.wsn.b_2.SubscribeResponse)4 TopicExpressionType (org.oasis_open.docs.wsn.b_2.TopicExpressionType)3 FilterType (org.oasis_open.docs.wsn.b_2.FilterType)2 Subscribe (org.oasis_open.docs.wsn.b_2.Subscribe)2 JAXBElement (javax.xml.bind.JAXBElement)1 InvalidFilterFaultType (org.oasis_open.docs.wsn.b_2.InvalidFilterFaultType)1 InvalidTopicExpressionFaultType (org.oasis_open.docs.wsn.b_2.InvalidTopicExpressionFaultType)1 QueryExpressionType (org.oasis_open.docs.wsn.b_2.QueryExpressionType)1 SubscribeCreationFailedFaultType (org.oasis_open.docs.wsn.b_2.SubscribeCreationFailedFaultType)1 UseRaw (org.oasis_open.docs.wsn.b_2.UseRaw)1 InvalidFilterFault (org.oasis_open.docs.wsn.bw_2.InvalidFilterFault)1 InvalidTopicExpressionFault (org.oasis_open.docs.wsn.bw_2.InvalidTopicExpressionFault)1 SubscribeCreationFailedFault (org.oasis_open.docs.wsn.bw_2.SubscribeCreationFailedFault)1 UnableToDestroySubscriptionFault (org.oasis_open.docs.wsn.bw_2.UnableToDestroySubscriptionFault)1