001: package com.bostech.corporation.component.echo.processors;
002:
003: import java.util.Iterator;
004: import java.util.Set;
005:
006: import javax.jbi.messaging.MessageExchange;
007: import javax.jbi.messaging.MessagingException;
008: import javax.jbi.messaging.NormalizedMessage;
009: import javax.xml.namespace.QName;
010:
011: import org.apache.commons.logging.Log;
012: import org.apache.commons.logging.LogFactory;
013:
014: import com.bostech.corporation.component.echo.EchoEndpoint;
015: import com.bostech.corporation.component.echo.wsdl.EchoProviderExtension;
016: import com.bostechcorp.cbesb.common.util.ErrorUtil;
017: import com.bostechcorp.cbesb.runtime.ccsl.jbi.messaging.CbProviderProcessor;
018: import com.bostechcorp.cbesb.runtime.ccsl.lib.DumpNormalizedMessage;
019:
020: public class EchoProviderProcessor extends CbProviderProcessor {
021:
022: protected final transient static Log logger = LogFactory
023: .getLog(EchoProviderProcessor.class);
024:
025: private EchoEndpoint endpoint;
026:
027: //private MessageExchangeFactory messageExchangeFactory;
028: //private DeliveryChannel channel;
029:
030: public EchoProviderProcessor(EchoEndpoint endpoint) {
031: super (endpoint);
032: this .endpoint = endpoint;
033: }
034:
035: @Override
036: public void processInMessage(QName service, QName operation,
037: NormalizedMessage in, MessageExchange exchange)
038: throws Exception {
039: try {
040: if (Boolean.parseBoolean(endpoint.getOutput_to_Log())) {
041: String myEndpoint = exchange.getEndpoint().toString();
042: String messageString = "";
043: NormalizedMessage m = exchange.getMessage("in");
044: if (m != null) {
045: if (endpoint
046: .getOutput_Style()
047: .equals(
048: EchoProviderExtension.Output_Style_Detailed)) {
049: messageString = DumpNormalizedMessage.dump(m)
050: + "\n";
051:
052: messageString = messageString
053: .concat("\nMessage Exchange PROPERTIES:\n");
054: Set propertyNames = exchange.getPropertyNames();
055: for (Iterator i = propertyNames.iterator(); i
056: .hasNext();) {
057: String name = (String) i.next();
058: messageString = messageString
059: .concat(" ["
060: + name
061: + "]"
062: + exchange
063: .getProperty(name)
064: + "\n");
065: }
066:
067: logger
068: .info("\n\n\nEcho Component- Detailed\n"
069: + myEndpoint
070: + "\n"
071: + messageString
072: + "\nEcho Component (endprint) ---->\n");
073: } else {
074: messageString = DumpNormalizedMessage
075: .dumpBrief(m)
076: + "\n";
077: logger
078: .info("\n\n\nEcho Component- Brief \n"
079: + myEndpoint
080: + "\n"
081: + messageString
082: + "\nEcho Component (endprint) ---->\n");
083: }
084: }
085:
086: }
087:
088: } catch (Exception e) {
089: ErrorUtil.printError("Exception in process(): ", e);
090: throw new MessagingException(e);
091: }
092:
093: }
094:
095: /*
096: * (non-Javadoc)
097: *
098: * @see com.bostechcorp.cbesb.runtime.ccsl.jbi.messaging.BaseProviderProcessor#processInOutMessage(javax.xml.namespace.QName,
099: * javax.xml.namespace.QName, javax.jbi.messaging.NormalizedMessage,
100: * javax.jbi.messaging.NormalizedMessage, boolean)
101: */
102: @SuppressWarnings("unchecked")
103: public boolean processInOutMessage(QName service, QName operation,
104: NormalizedMessage in, NormalizedMessage out,
105: boolean optionalOut, MessageExchange exchange)
106: throws Exception {
107:
108: processInMessage(service, operation, in, exchange);
109: // NormalizedMessageHandler dest = new NormalizedMessageHandler(out);
110: // NormalizedMessageHandler source = new NormalizedMessageHandler(in);
111: // for (int i=0; i<source.getRecordCount(); i++)
112: // dest.addRecord(source.getRecordAtIndex(i));
113: out.setContent(in.getContent());
114: Set<String> propertyNames = in.getPropertyNames();
115: for (String propertyName : propertyNames) {
116: out.setProperty(propertyName, in.getProperty(propertyName));
117: }
118: Set<String> attNames = in.getAttachmentNames();
119: for (String attName : attNames) {
120: out.addAttachment(attName, in.getAttachment(attName));
121: }
122: // dest.generateMessageContent();
123: exchange.setMessage(out, "out");
124: return true;
125: }
126: }
|