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    /**
022     * Template (named like Spring's TransactionTemplate & JmsTemplate
023     * et al) for working with Camel and sending {@link Message} instances in an
024     * {@link Exchange} to an {@link Endpoint}.
025     *
026     * @version $Revision: 41776 $
027     */
028    public interface ProducerTemplate<E extends Exchange> extends Service {
029    
030        /**
031         * Sends the exchange to the default endpoint
032         *
033         * @param exchange the exchange to send
034         */
035        E send(E exchange);
036    
037        /**
038         * Sends an exchange to the default endpoint using a supplied
039         *
040         * @param processor the transformer used to populate the new exchange
041         * {@link Processor} to populate the exchange
042         */
043        E send(Processor processor);
044    
045        /**
046         * Sends the body to the default endpoint and returns the result content
047         *
048         * @param body the body to send
049         * @return the returned message body
050         */
051        Object sendBody(Object body);
052    
053        /**
054         * Sends the body to the default endpoint with a specified header and header
055         * value
056         *
057         * @param body        the payload send
058         * @param header      the header name
059         * @param headerValue the header value
060         * @return the result
061         */
062        Object sendBodyAndHeader(Object body, String header, Object headerValue);
063    
064        /**
065         * Sends the body to the default endpoint with the specified headers and
066         * header values
067         *
068         * @param body the payload send
069         * @return the result
070         */
071        Object sendBodyAndHeaders(Object body, Map<String, Object> headers);
072    
073        // Allow sending to arbitrary endpoints
074        // -----------------------------------------------------------------------
075    
076        /**
077         * Sends the exchange to the given endpoint
078         *
079         * @param endpointUri the endpoint URI to send the exchange to
080         * @param exchange    the exchange to send
081         */
082        E send(String endpointUri, E exchange);
083    
084        /**
085         * Sends an exchange to an endpoint using a supplied processor
086         *
087         * @param endpointUri the endpoint URI to send the exchange to
088         * @param processor   the transformer used to populate the new exchange
089         * {@link Processor} to populate the exchange
090         */
091        E send(String endpointUri, Processor processor);
092    
093        /**
094         * Sends an exchange to an endpoint using a supplied processor
095         *
096         * @param endpointUri the endpoint URI to send the exchange to
097         * @param pattern     the message {@link ExchangePattern} such as
098         *                    {@link ExchangePattern#InOnly} or {@link ExchangePattern#InOut}
099         * @param processor   the transformer used to populate the new exchange
100         * {@link Processor} to populate the exchange
101         */
102        E send(String endpointUri, ExchangePattern pattern, Processor processor);
103    
104        /**
105         * Sends an exchange to an endpoint using a supplied processor
106         *
107         * @param endpointUri the endpoint URI to send the exchange to
108         * @param processor   the transformer used to populate the new exchange
109         * {@link Processor} to populate the exchange.
110         * @param callback    the callback will be called when the exchange is completed.
111         */
112        E send(String endpointUri, Processor processor, AsyncCallback callback);
113    
114        /**
115         * Sends the exchange to the given endpoint
116         *
117         * @param endpoint the endpoint to send the exchange to
118         * @param exchange the exchange to send
119         */
120        E send(Endpoint<E> endpoint, E exchange);
121    
122        /**
123         * Sends an exchange to an endpoint using a supplied processor
124         *
125         * @param endpoint  the endpoint to send the exchange to
126         * @param processor the transformer used to populate the new exchange
127         * {@link Processor} to populate the exchange
128         */
129        E send(Endpoint<E> endpoint, Processor processor);
130    
131        /**
132         * Sends an exchange to an endpoint using a supplied processor
133         *
134         * @param endpoint  the endpoint to send the exchange to
135         * @param pattern   the message {@link ExchangePattern} such as
136         *                  {@link ExchangePattern#InOnly} or {@link ExchangePattern#InOut}
137         * @param processor the transformer used to populate the new exchange
138         * {@link Processor} to populate the exchange
139         */
140        E send(Endpoint<E> endpoint, ExchangePattern pattern, Processor processor);
141    
142        /**
143         * Sends an exchange to an endpoint using a supplied processor
144         *
145         * @param endpoint  the endpoint to send the exchange to
146         * @param processor the transformer used to populate the new exchange
147         * {@link Processor} to populate the exchange.
148         * @param callback  the callback will be called when the exchange is completed.
149         */
150        E send(Endpoint<E> endpoint, Processor processor, AsyncCallback callback);
151    
152        /**
153         * Send the body to an endpoint returning any result output body
154         *
155         * @param endpoint   the endpoint to send the exchange to
156         * @param body       the payload
157         * @return the result
158         */
159        Object sendBody(Endpoint<E> endpoint, Object body);
160    
161        /**
162         * Send the body to an endpoint returning any result output body
163         *
164         * @param endpointUri   the endpoint URI to send the exchange to
165         * @param body          the payload
166         * @return the result
167         */
168        Object sendBody(String endpointUri, Object body);
169    
170        /**
171         * Send the body to an endpoint with the given {@link ExchangePattern}
172         * returning any result output body
173         *
174         * @param endpoint      the endpoint to send the exchange to
175         * @param body          the payload
176         * @param pattern       the message {@link ExchangePattern} such as
177         *   {@link ExchangePattern#InOnly} or {@link ExchangePattern#InOut}
178         * @return the result
179         */
180        Object sendBody(Endpoint<E> endpoint, ExchangePattern pattern, Object body);
181    
182        /**
183         * Send the body to an endpoint returning any result output body
184         *
185         * @param endpointUri   the endpoint URI to send the exchange to
186         * @param pattern       the message {@link ExchangePattern} such as
187         *   {@link ExchangePattern#InOnly} or {@link ExchangePattern#InOut}
188         * @param body          the payload
189         * @return the result
190         */
191        Object sendBody(String endpointUri, ExchangePattern pattern, Object body);
192    
193        /**
194         * Sends the body to an endpoint with a specified header and header value
195         *
196         * @param endpointUri the endpoint URI to send to
197         * @param body the payload send
198         * @param header the header name
199         * @param headerValue the header value
200         * @return the result
201         */
202        Object sendBodyAndHeader(String endpointUri, Object body, String header,
203                                        Object headerValue);
204    
205        /**
206         * Sends the body to an endpoint with a specified header and header value
207         *
208         * @param endpoint the Endpoint to send to
209         * @param body the payload send
210         * @param header the header name
211         * @param headerValue the header value
212         * @return the result
213         */
214        Object sendBodyAndHeader(Endpoint endpoint, Object body, String header,
215                                        Object headerValue);
216    
217        /**
218         * Sends the body to an endpoint with a specified header and header value
219         *
220         * @param endpoint the Endpoint to send to
221         * @param pattern the message {@link ExchangePattern} such as
222         *   {@link ExchangePattern#InOnly} or {@link ExchangePattern#InOut}
223         * @param body the payload send
224         * @param header the header name
225         * @param headerValue the header value
226         * @return the result
227         */
228        Object sendBodyAndHeader(Endpoint endpoint, ExchangePattern pattern, Object body, String header,
229                                        Object headerValue);
230    
231        /**
232         * Sends the body to an endpoint with a specified header and header value
233         *
234         * @param endpoint the Endpoint URI to send to
235         * @param pattern the message {@link ExchangePattern} such as
236         *   {@link ExchangePattern#InOnly} or {@link ExchangePattern#InOut}
237         * @param body the payload send
238         * @param header the header name
239         * @param headerValue the header value
240         * @return the result
241         */
242        Object sendBodyAndHeader(String endpoint, ExchangePattern pattern, Object body, String header,
243                                        Object headerValue);
244    
245        /**
246         * Sends the body to an endpoint with the specified headers and header
247         * values
248         *
249         * @param endpointUri the endpoint URI to send to
250         * @param body the payload send
251         * @return the result
252         */
253        Object sendBodyAndHeaders(String endpointUri, Object body, Map<String, Object> headers);
254    
255        /**
256         * Sends the body to an endpoint with the specified headers and header
257         * values
258         *
259         * @param endpoint the endpoint URI to send to
260         * @param body the payload send
261         * @return the result
262         */
263        Object sendBodyAndHeaders(Endpoint endpoint, Object body, Map<String, Object> headers);
264    
265    
266        // Methods using an InOut ExchangePattern
267        // -----------------------------------------------------------------------
268    
269        /**
270         * Send the body to an endpoint returning any result output body.
271         * Uses an {@link ExchangePattern#InOut} message exchange pattern.
272         *
273         * @param endpoint  the Endpoint to send to
274         * @param processor the processor which will populate the exchange before sending
275         * @return the result
276         */
277        E request(Endpoint<E> endpoint, Processor processor);
278    
279        /**
280         * Send the body to an endpoint returning any result output body.
281         * Uses an {@link ExchangePattern#InOut} message exchange pattern.
282         *
283         * @param endpoint the Endpoint to send to
284         * @param body     the payload
285         * @return the result
286         */
287        Object requestBody(Endpoint<E> endpoint, Object body);
288    
289        /**
290         * Send the body to an endpoint returning any result output body.
291         * Uses an {@link ExchangePattern#InOut} message exchange pattern.
292         *
293         * @param endpoint    the Endpoint to send to
294         * @param body        the payload
295         * @param header      the header name
296         * @param headerValue the header value
297         * @return the result
298         */
299        Object requestBodyAndHeader(Endpoint<E> endpoint, Object body, String header, Object headerValue);
300    
301        /**
302         * Send the body to an endpoint returning any result output body.
303         * Uses an {@link ExchangePattern#InOut} message exchange pattern.
304         *
305         * @param endpointUri the endpoint URI to send to
306         * @param processor the processor which will populate the exchange before sending
307         * @return the result
308         */
309        E request(String endpointUri, Processor processor);
310    
311        /**
312         * Send the body to an endpoint returning any result output body.
313         * Uses an {@link ExchangePattern#InOut} message exchange pattern.
314         *
315         * @param endpointUri the endpoint URI to send to
316         * @param body        the payload
317         * @return the result
318         */
319        Object requestBody(String endpointUri, Object body);
320    
321        /**
322         * Send the body to an endpoint returning any result output body.
323         * Uses an {@link ExchangePattern#InOut} message exchange pattern.
324         *
325         * @param endpointUri the endpoint URI to send to
326         * @param body        the payload
327         * @param header      the header name
328         * @param headerValue the header value
329         * @return the result
330         */
331        Object requestBodyAndHeader(String endpointUri, Object body, String header, Object headerValue);
332    
333    }