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