001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017 package org.apache.camel.jms;
018
019 import org.apache.camel.CamelContext;
020 import org.apache.camel.InvalidHeaderTypeException;
021 import org.apache.camel.Exchange;
022 import org.apache.camel.impl.DefaultExchange;
023
024 import javax.jms.JMSException;
025 import javax.jms.Message;
026 import javax.jms.Session;
027 import java.util.Enumeration;
028 import java.util.HashMap;
029 import java.util.Map;
030
031 /**
032 * @version $Revision: 520502 $
033 */
034 public class DefaultJmsExchange extends DefaultExchange implements JmsExchange {
035
036 public DefaultJmsExchange(CamelContext container) {
037 super(container);
038 }
039
040 public DefaultJmsExchange(CamelContext container, Message message) {
041 super(container);
042 setIn(new DefaultJmsMessage(message));
043 }
044
045 @Override
046 public Exchange newInstance() {
047 return new DefaultJmsExchange(getContext());
048 }
049
050 public Message createMessage(Session session) throws JMSException {
051 Message request = getInMessage();
052 if (request == null) {
053 request = session.createMessage();
054
055 /** TODO
056 if (lazyHeaders != null) {
057 // lets add any lazy headers
058 for (Map.Entry<String, Object> entry : lazyHeaders.entrySet()) {
059 request.setObjectProperty(entry.getKey(), entry.getValue());
060 }
061 }
062 */
063 }
064 return request;
065 }
066
067 public Message getInMessage() {
068 JmsMessage jmsMessage = (JmsMessage) getIn();
069 if (jmsMessage != null) {
070 return jmsMessage.getJmsMessage();
071 }
072 return null;
073 }
074
075 @Override
076 protected org.apache.camel.Message createInMessage() {
077 return new DefaultJmsMessage();
078 }
079
080 @Override
081 protected org.apache.camel.Message createOutMessage() {
082 return new DefaultJmsMessage();
083 }
084 }