001: package com.bostechcorp.cbesb.custom;
002:
003: import java.util.LinkedList;
004: import java.util.Map;
005: import java.util.HashMap;
006:
007: import javax.jbi.component.ComponentContext;
008: import javax.jbi.messaging.DeliveryChannel;
009: import javax.jbi.messaging.MessageExchange;
010: import javax.jbi.messaging.NormalizedMessage;
011: import javax.jbi.messaging.InOnly;
012:
013: import javax.xml.namespace.QName;
014: import javax.xml.transform.Source;
015: import javax.xml.transform.stream.StreamSource;
016: import java.io.StringReader;
017:
018: import org.apache.commons.logging.Log;
019:
020: import com.bostechcorp.cbesb.runtime.ccsl.lib.IScriptObject;
021: import com.bostechcorp.cbesb.runtime.ccsl.nmhandler.NormalizedMessageHandler;
022:
023: public class RequestProcessor implements IScriptObject {
024:
025: public void run(Log log, String rootDir, ComponentContext context,
026: DeliveryChannel channel, MessageExchange exchange)
027: throws Exception {
028: log.info("RequestProcessor - received message");
029:
030: NormalizedMessage inMsg = exchange.getMessage("in");
031: HashMap headers = (HashMap) inMsg
032: .getProperty("javax.jbi.messaging.protocol.headers");
033: NormalizedMessageHandler nmh1 = new NormalizedMessageHandler(
034: inMsg);
035: Source inSrc = nmh1.getRecordAtIndex(0);
036: log.info("Source type: " + inSrc.getClass().getName());
037:
038: //Create reply message
039: NormalizedMessage outMsg = exchange.getMessage("out");
040: outMsg.setProperty("javax.jbi.messaging.protocol.headers",
041: headers);
042: NormalizedMessageHandler nmh2 = new NormalizedMessageHandler(
043: outMsg);
044: nmh2.addRecord(createResponse());
045: nmh2.generateMessageContent();
046:
047: //Send a new InOnly exchange with the request data in it
048: InOnly newExchange = channel.createExchangeFactory()
049: .createInOnlyExchange();
050: NormalizedMessage newInMsg = newExchange.createMessage();
051: NormalizedMessageHandler nmh3 = new NormalizedMessageHandler(
052: newInMsg);
053: nmh3.addRecord(inSrc);
054: nmh3.generateMessageContent();
055: newExchange.setInMessage(newInMsg);
056: //Set the target service and interface
057: QName serviceName = new QName(
058: "http://bostechcorp.com/SU/LoanBroker_LoanBroker",
059: "LoanBroker_LoanBroker_Service");
060: QName interfaceName = new QName(
061: "http://bostechcorp.com/SU/LoanBroker_LoanBroker",
062: "LoanBroker_LoanBroker_Interface");
063: newExchange.setService(serviceName);
064: newExchange.setInterfaceName(interfaceName);
065: //Send the new exchange
066: channel.sendSync(newExchange);
067: }
068:
069: private Source createResponse() {
070: StringBuffer buffer = new StringBuffer();
071: buffer.append("<html>");
072: buffer.append("<head>");
073: buffer.append("<title>ChainBuilder ESB Loan Broker</title>");
074: buffer.append("</head>");
075: buffer.append("<body>");
076: buffer.append("<h3>ChainBuilder ESB Loan Broker</h3>");
077: buffer.append("Your request has been submitted.");
078: buffer.append("</body>");
079: buffer.append("</html>");
080:
081: StreamSource src = new StreamSource(new StringReader(buffer
082: .toString()));
083: return src;
084: }
085:
086: public void run(Log logger, String rootDir,
087: ComponentContext componentContext, DeliveryChannel channel,
088: MessageExchange exchange, Map<String, String> params)
089: throws Exception {
090:
091: }
092:
093: public void start(Log logger, String rootDir,
094: ComponentContext componentContext, DeliveryChannel channel,
095: Map<String, String> params) throws Exception {
096:
097: }
098:
099: public void stop(Log logger, String rootDir,
100: ComponentContext componentContext, DeliveryChannel channel,
101: Map<String, String> params) throws Exception {
102:
103: }
104:
105: public LinkedList time(Log logger, String rootDir,
106: ComponentContext componentContext, DeliveryChannel channel,
107: MessageExchange exchange, Map<String, String> params)
108: throws Exception {
109:
110: return null;
111: }
112: }
|