public void publishEvent(ConfigurationContext configurationContext, Event event) throws NotificationException {
try {
if (getExecutor() == null) {
String msg = "Notification Dispatcher not initialized";
log.error(msg);
throw new NotificationException(msg);
}
if (event == null || event.getMessage() == null) {
String msg = "Unable to Dispatch Notification. The incoming event was null, or did " +
"not contain a message.";
log.error(msg);
throw new NotificationException(msg);
}
if(event.getMessage() instanceof MessageContext){
SOAPEnvelope envelope = ((MessageContext)event.getMessage()).getEnvelope();
envelope.build();
envelope.getBody().build();
} else if(event.getMessage() instanceof OMElement){
((OMElement)event.getMessage()).build();
}
SubscriptionManager subManager = broker.getSubscriptionManager();
List<Subscription> subscriptions = subManager.getMatchingSubscriptions(event);
for (Subscription subscription : subscriptions) {
try {
EventDispatcher dispatcher = subscription.getEventDispatcher();
if (dispatcher == null){
for (String key : customDispatchers.keySet()) {
if (subscription.getFilterDesc().getFilterValue() != null &&
subscription.getFilterDesc().getFilterValue().startsWith(key)) {
dispatcher = customDispatchers.get(key);
break;
}
}
if (dispatcher == null) {
dispatcher = new CarbonEventDispatcher();
if (configurationContext != null) {
((CarbonEventDispatcher) dispatcher).init(configurationContext);
}
}
}
getExecutor().submit(new Worker(dispatcher, event, subscription));
} catch (Exception e) {
//errors should not happen here, but just in case
log.warn("Unable to dispatch event of type " + event.getClass().getName() +
e.getMessage(), e);
}
}
} catch (EventException e) {
if (e instanceof NotificationException) {
throw (NotificationException)e;
}
throw new NotificationException("Failed publishing the event "+ e.getMessage(),e);
}
}