001: /*
002: * BEGIN_HEADER - DO NOT EDIT
003: *
004: * The contents of this file are subject to the terms
005: * of the Common Development and Distribution License
006: * (the "License"). You may not use this file except
007: * in compliance with the License.
008: *
009: * You can obtain a copy of the license at
010: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011: * See the License for the specific language governing
012: * permissions and limitations under the License.
013: *
014: * When distributing Covered Code, include this CDDL
015: * HEADER in each file and include the License file at
016: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017: * If applicable add the following below this CDDL HEADER,
018: * with the fields enclosed by brackets "[]" replaced with
019: * your own identifying information: Portions Copyright
020: * [year] [name of copyright owner]
021: */
022:
023: /*
024: * @(#)JMSMessageProcessor.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: package com.sun.jbi.binding.jms.mq;
030:
031: import com.sun.jbi.StringTranslator;
032:
033: import com.sun.jbi.binding.jms.EndpointBean;
034: import com.sun.jbi.binding.jms.EndpointStatus;
035: import com.sun.jbi.binding.jms.JMSBindingContext;
036: import com.sun.jbi.binding.jms.JMSBindingResources;
037: import com.sun.jbi.binding.jms.MessageRegistry;
038:
039: import com.sun.jbi.binding.jms.deploy.EndpointRegistry;
040:
041: import com.sun.jbi.binding.jms.handler.InboundMessageHandler;
042: import com.sun.jbi.binding.jms.handler.MessageHandler;
043: import com.sun.jbi.binding.jms.handler.OutboundMessageHandler;
044:
045: import java.util.logging.Logger;
046:
047: import javax.jbi.messaging.MessageExchange;
048:
049: import javax.jms.JMSException;
050: import javax.jms.Message;
051:
052: /**
053: * Processes messages from the MQ.
054: *
055: * @author Sun Microsystems Inc.
056: */
057: public class JMSMessageProcessor implements JMSBindingResources {
058: /**
059: * Logger.
060: */
061: private Logger mLogger;
062: /**
063: * Translator.
064: */
065: private StringTranslator mStringTranslator;
066:
067: /**
068: * Creates a new instance of JMSMessageProcessor.
069: */
070: public JMSMessageProcessor() {
071: mLogger = JMSBindingContext.getInstance().getLogger();
072: mStringTranslator = JMSBindingContext.getInstance()
073: .getStringTranslator();
074: }
075:
076: /**
077: * Process.
078: *
079: * @param name name.
080: * @param msg JMS msg.
081: *
082: * @return message handler.
083: */
084: public MessageHandler process(String name, Message msg) {
085: MessageHandler handler = null;
086:
087: if (msg == null) {
088: return null;
089: }
090: mLogger
091: .finest("JMS Message processer started prcessing message");
092:
093: if (name == null) {
094: //this should be some out response
095: handler = new OutboundMessageHandler();
096:
097: MessageRegistry mreg = JMSBindingContext.getInstance()
098: .getMessageRegistry();
099: String cor = null;
100:
101: try {
102: cor = msg.getJMSCorrelationID();
103: } catch (JMSException je) {
104: ;
105: }
106:
107: if (cor == null) {
108: mLogger.severe(mStringTranslator.getString(
109: JMS_NO_CORRELATION_ID, msg.toString()));
110:
111: return null;
112: }
113:
114: MessageExchange me = (MessageExchange) mreg.getObject(cor);
115: handler.setNMSMessage(me);
116: handler.setJMSMessage(msg);
117: } else {
118: handler = new InboundMessageHandler();
119:
120: EndpointRegistry ereg = JMSBindingContext.getInstance()
121: .getRegistry();
122: EndpointBean eb = null;
123:
124: try {
125: eb = (EndpointBean) ereg.getEndpoint(name);
126: } catch (Exception e) {
127: ;
128: }
129:
130: if (eb == null) {
131: mLogger.severe(mStringTranslator
132: .getString(JMS_NO_ENDPOINT));
133:
134: return null;
135: }
136: if (!eb.getStatus().equals(EndpointStatus.STARTED)) {
137: mLogger.severe(mStringTranslator
138: .getString(JMS_ENDPOINT_NOT_STARTED));
139:
140: return null;
141: }
142: mLogger.info("JMS MSG RCVD " + msg);
143: handler.setJMSMessage(msg);
144: handler.setBean(eb);
145: }
146:
147: return handler;
148: }
149: }
|