1 10 11 package org.mule.tck.functional; 12 13 import org.apache.commons.logging.Log; 14 import org.apache.commons.logging.LogFactory; 15 import org.mule.MuleException; 16 import org.mule.MuleManager; 17 import org.mule.config.i18n.Message; 18 import org.mule.impl.RequestContext; 19 import org.mule.umo.UMOEventContext; 20 import org.mule.umo.lifecycle.Callable; 21 import org.mule.util.StringMessageUtils; 22 23 30 31 public class FunctionalTestComponent implements Callable 32 { 33 protected transient Log logger = LogFactory.getLog(getClass()); 34 35 private EventCallback eventCallback; 36 private String returnMessage = null; 37 private boolean throwException = false; 38 39 public Object onCall(UMOEventContext context) throws Exception 40 { 41 String contents = context.getTransformedMessageAsString(); 42 String msg = null; 43 msg = StringMessageUtils.getBoilerPlate("Message Received in component: " 44 + context.getComponentDescriptor().getName() 45 + ". Content is: " 46 + StringMessageUtils.truncate(contents, 100, true), '*', 80); 47 logger.info(msg); 48 49 if (eventCallback != null) 50 { 51 eventCallback.eventReceived(context, this); 52 } 53 String replyMessage; 54 if (returnMessage != null) 55 { 56 replyMessage = returnMessage; 57 } 58 else 59 { 60 replyMessage = contents + " Received"; 61 } 62 63 MuleManager.getInstance().fireNotification( 64 new FunctionalTestNotification(context, replyMessage, FunctionalTestNotification.EVENT_RECEIVED)); 65 66 if (throwException) 67 { 68 throw new MuleException(Message.createStaticMessage("Functional Test Component Exception")); 69 } 70 return replyMessage; 71 } 72 73 public Object onReceive(Object data) throws Exception 74 { 75 String contents = data.toString(); 76 UMOEventContext context = RequestContext.getEventContext(); 77 78 String msg = null; 79 msg = StringMessageUtils.getBoilerPlate("Message Received in component: " 80 + context.getComponentDescriptor().getName() 81 + ". Content is: " 82 + StringMessageUtils.truncate(contents, 100, true), '*', 80); 83 logger.info(msg); 84 85 if (eventCallback != null) 86 { 87 eventCallback.eventReceived(context, this); 88 } 89 90 String replyMessage; 91 92 if (returnMessage != null) 93 { 94 replyMessage = returnMessage; 95 } 96 else 97 { 98 replyMessage = contents + " Received"; 99 } 100 101 MuleManager.getInstance().fireNotification( 102 new FunctionalTestNotification(context, replyMessage, FunctionalTestNotification.EVENT_RECEIVED)); 103 104 if (throwException) 105 { 106 throw new MuleException(Message.createStaticMessage("Functional Test Component Exception")); 107 } 108 109 return replyMessage; 110 } 111 112 public EventCallback getEventCallback() 113 { 114 return eventCallback; 115 } 116 117 public void setEventCallback(EventCallback eventCallback) 118 { 119 this.eventCallback = eventCallback; 120 } 121 122 public String getReturnMessage() 123 { 124 return returnMessage; 125 } 126 127 public void setReturnMessage(String returnMessage) 128 { 129 this.returnMessage = returnMessage; 130 } 131 132 public boolean isThrowException() 133 { 134 return throwException; 135 } 136 137 public void setThrowException(boolean throwException) 138 { 139 this.throwException = throwException; 140 } 141 142 } 143 | Popular Tags |