1 10 11 package org.mule.components.builder; 12 13 import org.apache.commons.logging.Log; 14 import org.apache.commons.logging.LogFactory; 15 import org.mule.config.MuleProperties; 16 import org.mule.impl.MuleMessage; 17 import org.mule.impl.UMODescriptorAware; 18 import org.mule.umo.UMODescriptor; 19 import org.mule.umo.UMOEventContext; 20 import org.mule.umo.UMOMessage; 21 import org.mule.umo.endpoint.UMOEndpoint; 22 import org.mule.umo.lifecycle.Callable; 23 import org.mule.umo.routing.UMOOutboundRouter; 24 import org.mule.util.StringMessageUtils; 25 26 import java.util.ArrayList ; 27 import java.util.Iterator ; 28 import java.util.List ; 29 30 37 public abstract class AbstractMessageBuilder implements UMODescriptorAware, Callable, MessageBuilder 38 { 39 40 43 protected transient Log logger = LogFactory.getLog(getClass()); 44 45 protected UMODescriptor descriptor; 46 47 public void setDescriptor(UMODescriptor descriptor) 48 { 49 this.descriptor = descriptor; 50 } 51 52 public Object onCall(UMOEventContext eventContext) throws Exception 53 { 54 55 UMOMessage requestMessage = new MuleMessage(eventContext.getTransformedMessage(), 56 eventContext.getMessage()); 57 58 UMOMessage responseMessage = requestMessage; 59 Object builtMessage; 60 61 if (descriptor.getOutboundRouter().hasEndpoints()) 62 { 63 List endpoints = new ArrayList (); 64 for (Iterator iterator = descriptor.getOutboundRouter().getRouters().iterator(); iterator.hasNext();) 65 { 66 UMOOutboundRouter router = (UMOOutboundRouter)iterator.next(); 67 endpoints.addAll(router.getEndpoints()); 68 } 69 for (Iterator iterator = endpoints.iterator(); iterator.hasNext();) 70 { 71 UMOEndpoint endpoint = (UMOEndpoint)iterator.next(); 72 boolean rsync = eventContext.getMessage().getBooleanProperty( 73 MuleProperties.MULE_REMOTE_SYNC_PROPERTY, endpoint.isRemoteSync()); 74 if (!rsync) 75 { 76 logger.info("Endpoint: " + endpoint 77 + " is not remoteSync enabled. Message builder finishing"); 78 if (eventContext.isSynchronous()) 79 { 80 responseMessage = eventContext.sendEvent(requestMessage, endpoint); 81 } 82 else 83 { 84 eventContext.dispatchEvent(requestMessage, endpoint); 85 responseMessage = null; 86 } 87 break; 88 } 89 else 90 { 91 responseMessage = eventContext.sendEvent(requestMessage, endpoint); 92 if (logger.isDebugEnabled()) 93 { 94 logger.debug("Response Message Received from: " + endpoint.getEndpointURI()); 95 } 96 if (logger.isTraceEnabled()) 97 { 98 try 99 { 100 logger.trace("Message Payload: \n" 101 + StringMessageUtils.truncate( 102 StringMessageUtils.toString(responseMessage.getPayload()), 200, 103 false)); 104 } 105 catch (Exception e) 106 { 107 } 109 } 110 builtMessage = buildMessage(requestMessage, responseMessage); 111 responseMessage = new MuleMessage(builtMessage, responseMessage); 112 requestMessage = responseMessage; 113 } 114 } 115 } 116 else 117 { 118 logger.info("There are currently no endpoints configured on component: " + descriptor.getName()); 119 } 120 eventContext.setStopFurtherProcessing(true); 121 return responseMessage; 122 } 123 } 124 | Popular Tags |