/** * Will dispatch an application event through Mule * * @param applicationEvent the Spring event to be dispatched * @throws ApplicationEventException if the event cannot be dispatched i.e. if the underlying * transport throws an exception */ protected void dispatchEvent(MuleApplicationEvent applicationEvent) throws ApplicationEventException { UMOEndpoint endpoint = null; try { endpoint = MuleEndpoint.getOrCreateEndpointForUri( applicationEvent.getEndpoint(), UMOEndpoint.ENDPOINT_TYPE_SENDER); } catch (UMOException e) { throw new ApplicationEventException( "Failed to get endpoint for endpointUri: " + applicationEvent.getEndpoint(), e); } if (endpoint != null) { try { // if (applicationEvent.getEndpoint() != null) { // endpoint.setEndpointURI(applicationEvent.getEndpoint()); // } MuleMessage message = new MuleMessage(applicationEvent.getSource(), applicationEvent.getProperties()); // has dispatch been triggered using beanFactory.publish() // without a current event if (applicationEvent.getMuleEventContext() != null) { // tell mule not to try and route this event itself applicationEvent.getMuleEventContext().setStopFurtherProcessing(true); applicationEvent.getMuleEventContext().dispatchEvent(message, endpoint); } else { UMOSession session = new MuleSession( message, ((AbstractConnector) endpoint.getConnector()).getSessionHandler(), component); RequestContext.setEvent(new MuleEvent(message, endpoint, session, false)); // transform if necessary if (endpoint.getTransformer() != null) { message = new MuleMessage( endpoint.getTransformer().transform(applicationEvent.getSource()), applicationEvent.getProperties()); } endpoint.dispatch(new MuleEvent(message, endpoint, session, false)); } } catch (Exception e1) { throw new ApplicationEventException("Failed to dispatch event: " + e1.getMessage(), e1); } } else { throw new ApplicationEventException( "Failed endpoint using name: " + applicationEvent.getEndpoint()); } }
protected Object invokeAction(AdminNotification action, UMOEventContext context) throws UMOException { String destComponent = null; UMOMessage result = null; String endpoint = action.getResourceIdentifier(); if (action.getResourceIdentifier().startsWith("mule:")) { destComponent = endpoint.substring(endpoint.lastIndexOf("/") + 1); } else { destComponent = endpoint; } if (destComponent != null) { UMOSession session = MuleManager.getInstance().getModel().getComponentSession(destComponent); // Need to do this otherise when the event is invoked the // transformer associated with the Mule Admin queue will be invoked, but // the // message will not be of expected type UMOEndpoint ep = new MuleEndpoint(RequestContext.getEvent().getEndpoint()); ep.setTransformer(null); UMOEvent event = new MuleEvent(action.getMessage(), ep, context.getSession(), context.isSynchronous()); RequestContext.setEvent(event); if (context.isSynchronous()) { result = session.getComponent().sendEvent(event); ByteArrayOutputStream out = new ByteArrayOutputStream(); wireFormat.write(out, result); return out.toByteArray(); } else { session.getComponent().dispatchEvent(event); return null; } } else { return handleException( result, new MuleException( new Message( Messages.COULD_NOT_DETERMINE_DESTINATION_COMPONENT_FROM_ENDPOINT_X, endpoint))); } }