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.component.jbi;
018
019 import org.apache.camel.CamelContext;
020 import org.apache.camel.Exchange;
021 import org.apache.camel.impl.DefaultExchange;
022
023 import javax.jbi.messaging.MessageExchange;
024 import javax.jbi.messaging.NormalizedMessage;
025
026 /**
027 * An {@link Exchange} working with JBI which exposes the underlying JBI features such as the
028 * JBI {@link #getMessageExchange()}, {@link #getInMessage()} and {@link #getOutMessage()}
029 *
030 * @version $Revision: 563665 $
031 */
032 public class JbiExchange extends DefaultExchange {
033 private final JbiBinding binding;
034 private MessageExchange messageExchange;
035
036 public JbiExchange(CamelContext context, JbiBinding binding) {
037 super(context);
038 this.binding = binding;
039 }
040
041 public JbiExchange(CamelContext context, JbiBinding binding, MessageExchange messageExchange) {
042 super(context);
043 this.binding = binding;
044 this.messageExchange = messageExchange;
045
046 // TODO we could maybe use the typesafe APIs of different derived APIs from JBI
047 setIn(new JbiMessage(messageExchange.getMessage("in")));
048 setOut(new JbiMessage(messageExchange.getMessage("out")));
049 setFault(new JbiMessage(messageExchange.getMessage("fault")));
050 }
051
052 @Override
053 public JbiMessage getIn() {
054 return (JbiMessage) super.getIn();
055 }
056
057 @Override
058 public JbiMessage getOut() {
059 return (JbiMessage) super.getOut();
060 }
061
062 @Override
063 public JbiMessage getOut(boolean lazyCreate) {
064 return (JbiMessage) super.getOut(lazyCreate);
065 }
066
067 @Override
068 public JbiMessage getFault() {
069 return (JbiMessage) super.getFault();
070 }
071
072 /**
073 * @return the Camel <-> JBI binding
074 */
075 public JbiBinding getBinding() {
076 return binding;
077 }
078
079 // Expose JBI features
080 //-------------------------------------------------------------------------
081
082 /**
083 * Returns the underlying JBI message exchange for an inbound exchange
084 * or null for outbound messages
085 *
086 * @return the inbound message exchange
087 */
088 public MessageExchange getMessageExchange() {
089 return messageExchange;
090 }
091
092 /**
093 * Returns the underlying In {@link NormalizedMessage}
094 *
095 * @return the In message
096 */
097 public NormalizedMessage getInMessage() {
098 return getIn().getNormalizedMessage();
099 }
100
101 /**
102 * Returns the underlying Out {@link NormalizedMessage}
103 *
104 * @return the Out message
105 */
106 public NormalizedMessage getOutMessage() {
107 return getOut().getNormalizedMessage();
108 }
109
110 /**
111 * Returns the underlying Fault {@link NormalizedMessage}
112 *
113 * @return the Fault message
114 */
115 public NormalizedMessage getFaultMessage() {
116 return getFault().getNormalizedMessage();
117 }
118
119 // Implementation methods
120 //-------------------------------------------------------------------------
121
122 @Override
123 protected JbiMessage createInMessage() {
124 return new JbiMessage();
125 }
126
127 @Override
128 protected JbiMessage createOutMessage() {
129 return new JbiMessage();
130 }
131 }