public static boolean generateEvent(OMElement payload, OMElement topic,
EventBrokerService brokerService, int tenantId)
throws EventBrokerException {
if (payload == null) {
throw new EventBrokerException("Unable to generate event. No payload was given.");
}
CarbonEventingMessageReceiver dummyReceiver = new CarbonEventingMessageReceiver();
if (brokerService != null) {
dummyReceiver.setBrokerService(brokerService);
}
MessageContext mc = new MessageContext();
SuperTenantCarbonContext.getCurrentContext(mc).setTenantId(tenantId);
SOAPFactory soapFactory = new SOAP12Factory();
SOAPEnvelope envelope = soapFactory.getDefaultEnvelope();
envelope.getBody().addChild(payload);
if (topic != null) {
envelope.getHeader().addChild(topic);
}
try {
mc.setEnvelope(envelope);
dummyReceiver.processMessage(mc);
} catch (Exception e) {
if (e instanceof EventBrokerException) {
throw (EventBrokerException)e;
}
throw new EventBrokerException("Unable to generate event.", e);
}
return true;
}