01: package com.bostechcorp.cbesb.custom;
02:
03: import java.util.LinkedList;
04: import java.util.Map;
05:
06: import javax.jbi.component.ComponentContext;
07: import javax.jbi.messaging.DeliveryChannel;
08: import javax.jbi.messaging.MessageExchange;
09: import javax.jbi.messaging.NormalizedMessage;
10: import javax.xml.parsers.DocumentBuilder;
11: import javax.xml.parsers.DocumentBuilderFactory;
12: import javax.xml.transform.dom.DOMSource;
13:
14: import org.apache.commons.logging.Log;
15: import org.w3c.dom.Document;
16: import org.w3c.dom.Element;
17: import org.w3c.dom.Node;
18:
19: import com.bostechcorp.cbesb.runtime.ccsl.lib.IScriptObject;
20: import com.bostechcorp.cbesb.runtime.ccsl.nmhandler.NormalizedMessageHandler;
21:
22: public class WrapWithSoapRequest implements IScriptObject {
23:
24: public void run(Log log, String rootDir, ComponentContext context,
25: DeliveryChannel channel, MessageExchange exchange,
26: Map<String, String> params) throws Exception {
27: log.debug("Wrapping message in SoapRequest");
28: NormalizedMessage inMsg = exchange.getMessage("in");
29: NormalizedMessageHandler nmh = new NormalizedMessageHandler(
30: inMsg);
31: DOMSource domSrc = (DOMSource) nmh.getRecordAtIndex(0);
32: Document doc;
33: Node node = domSrc.getNode();
34: if (node instanceof Document) {
35: doc = (Document) node;
36: } else {
37: doc = node.getOwnerDocument();
38: }
39: Element requestRoot = doc.getDocumentElement();
40:
41: DocumentBuilderFactory dbf = DocumentBuilderFactory
42: .newInstance();
43: dbf.setNamespaceAware(true);
44: DocumentBuilder db = dbf.newDocumentBuilder();
45: Document newDoc = db.newDocument();
46: Element soapRequest = newDoc.createElementNS(
47: "http://cbesb.bostechcorp.com/soap/1.0", "SoapRequest");
48: newDoc.appendChild(soapRequest);
49: Element soapBody = newDoc.createElementNS(
50: "http://cbesb.bostechcorp.com/soap/1.0", "SoapBody");
51: soapRequest.appendChild(soapBody);
52: Element sendMessage = newDoc.createElementNS(
53: "http://cbesb.bostechcorp.com/soap/sendmessage/1.0",
54: "sendMessage");
55: soapBody.appendChild(sendMessage);
56: Element messageType = newDoc.createElementNS(
57: "http://cbesb.bostechcorp.com/soap/sendmessage/1.0",
58: "messageType");
59: sendMessage.appendChild(messageType);
60: messageType.setTextContent("XML");
61: Element message = newDoc.createElementNS(
62: "http://cbesb.bostechcorp.com/soap/sendmessage/1.0",
63: "message");
64: sendMessage.appendChild(message);
65: newDoc.adoptNode(requestRoot);
66: message.appendChild(requestRoot);
67: DOMSource newDomSrc = new DOMSource(newDoc);
68:
69: NormalizedMessage outMsg = exchange.getMessage("out");
70: nmh = new NormalizedMessageHandler(outMsg);
71: nmh.addRecord(newDomSrc);
72: nmh.generateMessageContent();
73:
74: }
75:
76: public void start(Log logger, String rootDir,
77: ComponentContext context, DeliveryChannel channel,
78: Map<String, String> params) throws Exception {
79:
80: }
81:
82: public void stop(Log logger, String rootDir,
83: ComponentContext context, DeliveryChannel channel,
84: Map<String, String> params) throws Exception {
85:
86: }
87:
88: public LinkedList time(Log logger, String rootDir,
89: ComponentContext componentContext, DeliveryChannel channel,
90: MessageExchange exchange, Map<String, String> params)
91: throws Exception {
92:
93: return null;
94: }
95:
96: }
|