001: package com.bostechcorp.cbesb.custom;
002:
003: import java.util.LinkedList;
004: import java.util.Map;
005: import java.util.Set;
006:
007: import javax.jbi.JBIException;
008: import javax.jbi.component.ComponentContext;
009: import javax.jbi.messaging.DeliveryChannel;
010: import javax.jbi.messaging.MessageExchange;
011: import javax.jbi.messaging.NormalizedMessage;
012:
013: import org.apache.commons.logging.Log;
014:
015: import com.bostechcorp.cbesb.runtime.ccsl.lib.DumpNormalizedMessage;
016: import com.bostechcorp.cbesb.runtime.ccsl.lib.IScriptObject;
017: import com.bostechcorp.cbesb.runtime.ccsl.nmhandler.NormalizedMessageHandler;
018:
019: public class EchoToLog implements IScriptObject {
020:
021: /**
022: * The run method is called when an exchange is sent to the endpoint.
023: *
024: * @param logger - the loggger object
025: * @param rootDir - the root direcory of the SU
026: * @param componentContext - the componentContext object
027: * @param channel - the delivery channel object
028: * @param exchange - the MessageExchange object passed in
029: * @param params - the user paramaters in name/value pair
030: * @throws Exception
031: */
032:
033: public void run(Log logger, String rootDir,
034: ComponentContext componentContext, DeliveryChannel channel,
035: MessageExchange exchange, Map<String, String> params)
036: throws Exception {
037:
038: String myEndpoint = exchange.getEndpoint().toString();
039: String messageString = "";
040: NormalizedMessage m;
041: if ((m = exchange.getMessage("in")) != null) {
042: messageString = DumpNormalizedMessage.dump(m) + "\n";
043: }
044: logger.info("\n\n\nScript Component EchoToLog\n" + myEndpoint
045: + "\n" + messageString + "\n\n");
046: }
047:
048: /**
049: * Start mode can be used for initialization. Consumer endpoints
050: * that do not use timed mode should set up a thread to generate
051: * exchanges in start mode.
052: *
053: * @param logger - the loggger object
054: * @param rootDir - the root direcory of the SU
055: * @param componentContext - the componentContext object
056: * @param channel - the delivery channel object
057: * @param exchange - the MessageExchange object passed in
058: * @param params - the user paramaters in name/value pair
059: * @throws Exception
060: */
061:
062: public void start(Log logger, String rootDir,
063: ComponentContext componentContext, DeliveryChannel channel,
064: Map<String, String> params) throws Exception {
065:
066: // nothing to do for startup
067:
068: }
069:
070: /**
071: * The stop method should clean up resources
072: *
073: * @param logger - the loggger object
074: * @param rootDir - the root direcory of the SU
075: * @param componentContext - the componentContext object
076: * @param channel - the delivery channel object
077: * @param params - the user paramaters in name/value pair
078: * @throws Exception
079: */
080: public void stop(Log logger, String rootDir,
081: ComponentContext componentContext, DeliveryChannel channel,
082: Map<String, String> params) throws Exception {
083:
084: // nothing to do for stop
085: }
086:
087: /**
088: * The time method is called for a timed mode consumer endpoint.
089: * It returns a linked list of exchanges to be sent from the
090: * endpoint.
091: *
092: * @param logger - the loggger object
093: * @param rootDir - the root direcory of the SU
094: * @param componentContext - the componentContext object
095: * @param channel - the delivery channel object
096: * @param exchange - the MessageExchange object passed in
097: * @param params - the user paramaters in name/value pair
098: * @return - the LinkList containning one of many MessageExchange objects
099: * @throws Exception
100: */
101: public LinkedList time(Log logger, String rootDir,
102: ComponentContext componentContext, DeliveryChannel channel,
103: MessageExchange exchange, Map<String, String> params)
104: throws Exception {
105:
106: // This component cannot run as a consumer so throw an exception
107: JBIException e = new JBIException(
108: "cannot run Echo component in time mode");
109: throw e;
110: }
111: }
|