public synchronized UMOMessage catchMessage( UMOMessage message, UMOSession session, boolean synchronous) throws RoutingException { UMOEvent event = RequestContext.getEvent(); try { event = new MuleEvent(message, event.getEndpoint(), session.getComponent(), event); if (synchronous) { statistics.incrementRoutedMessage(event.getEndpoint()); logger.info( "Event being routed from catch all strategy for endpoint: " + RequestContext.getEvent().getEndpoint()); return session.getComponent().sendEvent(event); } else { statistics.incrementRoutedMessage(event.getEndpoint()); session.getComponent().dispatchEvent(event); return null; } } catch (UMOException e) { throw new ComponentRoutingException( event.getMessage(), event.getEndpoint(), session.getComponent(), e); } }
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))); } }
/** * 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 UMOStreamMessageAdapter sendStream(String uri, UMOStreamMessageAdapter sa) throws UMOException { UMOEndpoint ep = MuleEndpoint.getOrCreateEndpointForUri(uri, UMOEndpoint.ENDPOINT_TYPE_SENDER); ep.setStreaming(true); UMOMessage message = new MuleMessage(sa); UMOEvent event = new MuleEvent(message, ep, RequestContext.getEventContext().getSession(), true); UMOMessage result = ep.send(event); if (result != null) { if (result.getAdapter() instanceof UMOStreamMessageAdapter) { return (UMOStreamMessageAdapter) result.getAdapter(); } else { // TODO i18n (though this case should never happen...) throw new IllegalStateException( "Mismatch of stream states. A stream was used for outbound channel, but a stream was not used for the response"); } } return null; }
public Object onReceive(Object data) throws Exception { UMOEventContext context = RequestContext.getEventContext(); String contents = data.toString(); String msg = StringMessageUtils.getBoilerPlate( "Message Received in component: " + context.getComponentDescriptor().getName() + ". Content is: " + StringMessageUtils.truncate(contents, 100, true), '*', 80); logger.info(msg); if (eventCallback != null) { eventCallback.eventReceived(context, this); } Object replyMessage; if (returnMessage != null) { replyMessage = returnMessage; } else { replyMessage = contents + " Received"; } MuleManager.getInstance() .fireNotification( new FunctionalTestNotification( context, replyMessage, FunctionalTestNotification.EVENT_RECEIVED)); if (throwException) { throw new MuleException(Message.createStaticMessage("Functional Test Component Exception")); } return replyMessage; }
private void sendViaClient(final MessageContext context, final OutMessage message) throws Exception { OutputHandler handler = new OutputHandler() { public void write(UMOEvent event, OutputStream out) throws IOException { try { Attachments atts = message.getAttachments(); if (atts != null && atts.size() > 0) { atts.write(out); } else { XMLStreamWriter writer = STAXUtils.createXMLStreamWriter(out, message.getEncoding(), context); message.getSerializer().writeMessage(message, writer, context); try { writer.flush(); } catch (XMLStreamException e) { logger.error(e); throw new XFireException("Couldn't send message.", e); } } } catch (XFireException e) { logger.error("Couldn't send message.", e); throw new IOException(e.getMessage()); } } public Map getHeaders(UMOEvent event) { Map headers = new HashMap(); headers.put(HttpConstants.HEADER_CONTENT_TYPE, getSoapMimeType(message)); headers.put(SoapConstants.SOAP_ACTION, message.getProperty(SoapConstants.SOAP_ACTION)); UMOMessage msg = event.getMessage(); for (Iterator iterator = msg.getPropertyNames().iterator(); iterator.hasNext(); ) { String headerName = (String) iterator.next(); Object headerValue = msg.getStringProperty(headerName, null); // let us filter only MULE properties except MULE_USER, // Content-Type and Content-Lenght; all other properties are // allowed through including custom headers if ((!headerName.startsWith(MuleProperties.PROPERTY_PREFIX) || (MuleProperties.MULE_USER_PROPERTY.compareTo(headerName) == 0)) && (!HttpConstants.HEADER_CONTENT_TYPE.equalsIgnoreCase(headerName)) && (!HttpConstants.HEADER_CONTENT_LENGTH.equalsIgnoreCase(headerName))) { headers.put(headerName, headerValue); } } return headers; } }; // We can create a generic StreamMessageAdapter here as the underlying // transport will create one specific to the transport UMOStreamMessageAdapter sp = new StreamMessageAdapter(handler); sp.setProperty(HttpConnector.HTTP_METHOD_PROPERTY, HttpConstants.METHOD_POST); // set all properties on the message adapter UMOMessage msg = RequestContext.getEvent().getMessage(); for (Iterator i = msg.getPropertyNames().iterator(); i.hasNext(); ) { String propertyName = (String) i.next(); sp.setProperty(propertyName, msg.getProperty(propertyName)); } UMOStreamMessageAdapter result = null; try { result = sendStream(getUri(), sp); if (result != null) { InMessage inMessage; String contentType = sp.getStringProperty(HttpConstants.HEADER_CONTENT_TYPE, "text/xml"); InputStream in = result.getInputStream(); if (contentType.toLowerCase().indexOf("multipart/related") != -1) { try { Attachments atts = new JavaMailAttachments(in, contentType); InputStream msgIs = atts.getSoapMessage().getDataHandler().getInputStream(); inMessage = new InMessage( STAXUtils.createXMLStreamReader(msgIs, message.getEncoding(), context), getUri()); inMessage.setAttachments(atts); } catch (MessagingException e) { throw new IOException(e.getMessage()); } } else { inMessage = new InMessage( STAXUtils.createXMLStreamReader(in, message.getEncoding(), context), getUri()); } getEndpoint().onReceive(context, inMessage); } } finally { sp.release(); if (result != null) { result.release(); } } }