try {
if (!isEnabled(mc, ENABLE_SUBSCRIBE)) {
log.warn("Subscribe operation is disabled");
return;
}
Subscription subscription = null;
SubscribeCommandBuilder builder = new SubscribeCommandBuilder(mc);
try {
subscription = builder.toSubscription(mc.getEnvelope());
subscription.setOwner(EventBrokerUtils.getLoggedInUserName());
} catch (InvalidExpirationTimeException e) {
if (log.isDebugEnabled()) {
log.debug(e.getMessage());
}
SOAPEnvelope soapEnvelope = BuilderUtils.genFaultResponse(
EventingConstants.WSE_FAULT_CODE_RECEIVER, "InvalidExpirationTime",
e.getMessage(), "", mc.isSOAP11());
dispatchResponse(soapEnvelope, EventingConstants.WSA_FAULT, mc, true);
} catch (InvalidMessageException e) {
if (log.isDebugEnabled()) {
log.debug(e.getMessage());
}
SOAPEnvelope soapEnvelope = BuilderUtils.genFaultResponse(
EventingConstants.WSE_FAULT_CODE_RECEIVER, "InvalidMessage",
e.getMessage(), "", mc.isSOAP11());
dispatchResponse(soapEnvelope, EventingConstants.WSA_FAULT, mc, true);
}
if (subscription != null) {
// set the topic name using the url
String toAddress = mc.getOptions().getTo().getAddress();
String topicName = subscription.getEventFilter().getValue();
if ((topicName == null) || (topicName.equals(""))) {
// we take string after the service name as the topic name
if (toAddress.indexOf(EventingConstants.BROKER_SERVICE_NAME + "/") > 0) {
topicName = toAddress.substring(
toAddress.indexOf(EventingConstants.BROKER_SERVICE_NAME + "/")
+ EventingConstants.BROKER_SERVICE_NAME.length() + 1);
}
}
subscription.setTopicName(topicName);
if (log.isDebugEnabled()) {
log.debug("Subscription request recieved : " + subscription.getId());
}
if (subscription.getEventSinkURL().startsWith("sqs://")){
subscription.setEventDispatcherName(EventBrokerConstants.EVENT_SINK_DISPATCHER_NAME);
} else {
subscription.setEventDispatcherName(EventBrokerConstants.WS_EVENT_DISPATCHER_NAME);
}
String subID = WSEventBrokerHolder.getInstance().getEventBroker().subscribe(subscription);
subscription.setId(subID);
if (subID != null) {
if (log.isDebugEnabled()) {
log.debug("Sending subscription response for Subscription ID : " +
subscription.getId());
}
SOAPEnvelope soapEnvelope = builder.fromSubscription(subscription);
dispatchResponse(soapEnvelope, EventingConstants.WSE_SUBSCRIBE_RESPONSE, mc, false);
} else {
log.debug("Subscription Failed, sending fault response");