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;
018
019 import java.util.Map;
020
021 import org.apache.camel.spi.Synchronization;
022 import org.apache.camel.spi.UnitOfWork;
023
024 /**
025 * The base message exchange interface providing access to the request, response
026 * and fault {@link Message} instances. Different providers such as JMS, JBI,
027 * CXF and HTTP can provide their own derived API to expose the underlying
028 * transport semantics to avoid the leaky abstractions of generic APIs.
029 *
030 * @version $Revision: 801278 $
031 */
032 public interface Exchange {
033
034 String ACCEPT_CONTENT_TYPE = "CamelAcceptContentType";
035
036 String AGGREGATED_INDEX = "CamelAggregatedIndex";
037 String AGGREGATED_SIZE = "CamelAggregatedSize";
038
039 String ASYNC_WAIT = "CamelAsyncWait";
040
041 String BATCH_INDEX = "CamelBatchIndex";
042 String BATCH_SIZE = "CamelBatchSize";
043 String BATCH_COMPLETE = "CamelBatchComplete";
044
045 String BEAN_METHOD_NAME = "CamelBeanMethodName";
046 String BEAN_HOLDER = "CamelBeanHolder";
047 String BEAN_MULTI_PARAMETER_ARRAY = "CamelBeanMultiParameterArray";
048
049 String BINDING = "CamelBinding";
050
051 String CHARSET_NAME = "CamelCharsetName";
052 String CONTENT_ENCODING = "Content-Encoding";
053 String CONTENT_TYPE = "Content-Type";
054 String CORRELATION_ID = "CamelCorrelationId";
055
056 String DATASET_INDEX = "CamelDataSetIndex";
057
058 String EXCEPTION_CAUGHT = "CamelExceptionCaught";
059 String ERRORHANDLER_HANDLED = "CamelErrorHandlerHandled";
060 String FAILURE_HANDLED = "CamelFailureHandled";
061
062 String FILE_LOCAL_WORK_PATH = "CamelFileLocalWorkPath";
063 String FILE_NAME = "CamelFileName";
064 String FILE_NAME_ONLY = "CamelFileNameOnly";
065 String FILE_NAME_PRODUCED = "CamelFileNameProduced";
066 String FILE_PATH = "CamelFilePath";
067 String FILE_PARENT = "CamelFileParent";
068 String FILTERED = "CamelFiltered";
069
070 String GROUPED_EXCHANGE = "CamelGroupedExchange";
071
072 String HTTP_BASE_URI = "CamelHttpBaseUri";
073 String HTTP_CHARACTER_ENCODING = "CamelHttpCharacterEncoding";
074 String HTTP_METHOD = "CamelHttpMethod";
075 String HTTP_PATH = "CamelHttpPath";
076 String HTTP_QUERY = "CamelHttpQuery";
077 String HTTP_RESPONSE_CODE = "CamelHttpResponseCode";
078 String HTTP_URI = "CamelHttpUri";
079 String HTTP_URL = "CamelHttpUrl";
080
081 String INTERCEPTED_ENDPOINT = "CamelInterceptedEndpoint";
082
083 String LOG_DEBUG_BODY_MAX_CHARS = "CamelLogDebugBodyMaxChars";
084 String LOOP_INDEX = "CamelLoopIndex";
085 String LOOP_SIZE = "CamelLoopSize";
086
087 String MULTICAST_INDEX = "CamelMulticastIndex";
088
089 String ON_COMPLETION = "CamelOnCompletion";
090
091 String ROUTE_STOP = "CamelRouteStop";
092 String REDELIVERED = "CamelRedelivered";
093 String REDELIVERY_COUNTER = "CamelRedeliveryCounter";
094 String ROLLBACK_ONLY = "CamelRollbackOnly";
095
096 String SPLIT_INDEX = "CamelSplitIndex";
097 String SPLIT_SIZE = "CamelSplitSize";
098
099 String TIMER_FIRED_TIME = "CamelTimerFiredTime";
100 String TIMER_NAME = "CamelTimerName";
101 String TIMER_PERIOD = "CamelTimerPeriod";
102 String TIMER_TIME = "CamelTimerTime";
103
104 String TRANSACTED = "CamelTransacted";
105
106 String TRACE_EVENT = "CamelTraceEvent";
107 String TRACE_EVENT_NODE_ID = "CamelTraceEventNodeId";
108 String TRACE_EVENT_TIMESTAMP = "CamelTraceEventTimestamp";
109 String TRACE_EVENT_EXCHANGE = "CamelTraceEventExchange";
110
111 /**
112 * Returns the {@link ExchangePattern} (MEP) of this exchange.
113 *
114 * @return the message exchange pattern of this exchange
115 */
116 ExchangePattern getPattern();
117
118 /**
119 * Allows the {@link ExchangePattern} (MEP) of this exchange to be customized.
120 *
121 * This typically won't be required as an exchange can be created with a specific MEP
122 * by calling {@link Endpoint#createExchange(ExchangePattern)} but it is here just in case
123 * it is needed.
124 *
125 * @param pattern the pattern
126 */
127 void setPattern(ExchangePattern pattern);
128
129 /**
130 * Returns a property associated with this exchange by name
131 *
132 * @param name the name of the property
133 * @return the value of the given header or null if there is no property for
134 * the given name
135 */
136 Object getProperty(String name);
137
138 /**
139 * Returns a property associated with this exchange by name and specifying
140 * the type required
141 *
142 * @param name the name of the property
143 * @param type the type of the property
144 * @return the value of the given header or null if there is no property for
145 * the given name or null if it cannot be converted to the given
146 * type
147 */
148 <T> T getProperty(String name, Class<T> type);
149
150 /**
151 * Sets a property on the exchange
152 *
153 * @param name of the property
154 * @param value to associate with the name
155 */
156 void setProperty(String name, Object value);
157
158 /**
159 * Removes the given property on the exchange
160 *
161 * @param name of the property
162 * @return the old value of the property
163 */
164 Object removeProperty(String name);
165
166 /**
167 * Returns all of the properties associated with the exchange
168 *
169 * @return all the headers in a Map
170 */
171 Map<String, Object> getProperties();
172
173 /**
174 * Returns whether any properties has been set
175 *
176 * @return <tt>true</tt> if any properties has been set
177 */
178 boolean hasProperties();
179
180 /**
181 * Returns the inbound request message
182 *
183 * @return the message
184 */
185 Message getIn();
186
187 /**
188 * Sets the inbound message instance
189 *
190 * @param in the inbound message
191 */
192 void setIn(Message in);
193
194 /**
195 * Returns the outbound message, lazily creating one if one has not already
196 * been associated with this exchange.
197 * <p/>
198 * If you want to test whether an OUT message have been set or not, use the {@link #hasOut()} method.
199 *
200 * @return the response
201 */
202 Message getOut();
203
204 /**
205 * Returns whether an OUT message has been set or not.
206 *
207 * @return <tt>true</tt> if an OUT message exists, <tt>false</tt> otherwise.
208 */
209 boolean hasOut();
210
211 /**
212 * Sets the outbound message
213 *
214 * @param out the outbound message
215 */
216 void setOut(Message out);
217
218 /**
219 * Returns the exception associated with this exchange
220 *
221 * @return the exception (or null if no faults)
222 */
223 Exception getException();
224
225 /**
226 * Returns the exception associated with this exchange.
227 * <p/>
228 * Is used to get the caused exception that typically have been wrapped in some sort
229 * of Camel wrapper exception
230 * <p/>
231 * The stategy is to look in the exception hieracy to find the first given cause that matches the type.
232 * Will start from the bottom (the real cause) and walk upwards.
233 *
234 * @param type the exception type
235 * @return the exception (or null if no faults or if no caused exception matched)
236 */
237 <T> T getException(Class<T> type);
238
239 /**
240 * Sets the exception associated with this exchange
241 *
242 * @param e the caused exception
243 */
244 void setException(Exception e);
245
246 /**
247 * Returns true if this exchange failed due to either an exception or fault
248 *
249 * @return true if this exchange failed due to either an exception or fault
250 * @see Exchange#getException()
251 * @see Exchange#getFault()
252 */
253 boolean isFailed();
254
255 /**
256 * Returns true if this exchange is transacted
257 */
258 boolean isTransacted();
259
260 /**
261 * Returns true if this exchange is marked for rollback
262 */
263 boolean isRollbackOnly();
264
265 /**
266 * Returns the container so that a processor can resolve endpoints from URIs
267 *
268 * @return the container which owns this exchange
269 */
270 CamelContext getContext();
271
272 /**
273 * Creates a copy of the current message exchange so that it can be
274 * forwarded to another destination
275 */
276 Exchange copy();
277
278 /**
279 * Returns the endpoint which originated this message exchange if a consumer on an endpoint created the message exchange
280 * otherwise this property will be null
281 */
282 Endpoint getFromEndpoint();
283
284 /**
285 * Sets the endpoint which originated this message exchange. This method
286 * should typically only be called by {@link org.apache.camel.Endpoint} implementations
287 *
288 * @param fromEndpoint the endpoint which is originating this message exchange
289 */
290 void setFromEndpoint(Endpoint fromEndpoint);
291
292 /**
293 * Returns the unit of work that this exchange belongs to; which may map to
294 * zero, one or more physical transactions
295 */
296 UnitOfWork getUnitOfWork();
297
298 /**
299 * Sets the unit of work that this exchange belongs to; which may map to
300 * zero, one or more physical transactions
301 */
302 void setUnitOfWork(UnitOfWork unitOfWork);
303
304 /**
305 * Returns the exchange id (unique)
306 */
307 String getExchangeId();
308
309 /**
310 * Set the exchange id
311 */
312 void setExchangeId(String id);
313
314 /**
315 * Adds a {@link org.apache.camel.spi.Synchronization} to be invoked as callback when
316 * this exchange is completed.
317 *
318 * @param onCompletion the callback to invoke on completion of this exchange
319 */
320 void addOnCompletion(Synchronization onCompletion);
321
322 }