org.apache.camel
Class CamelTemplate<E extends Exchange>

java.lang.Object
  extended by org.apache.camel.impl.ServiceSupport
      extended by org.apache.camel.CamelTemplate<E>
All Implemented Interfaces:
ProducerTemplate<E>, Service

public class CamelTemplate<E extends Exchange>
extends ServiceSupport
implements ProducerTemplate<E>

A client helper object (named like Spring's TransactionTemplate & JmsTemplate et al) for working with Camel and sending Message instances in an Exchange to an Endpoint.

Version:
$Revision: 40987 $

Constructor Summary
CamelTemplate(CamelContext context)
           
CamelTemplate(CamelContext context, Endpoint defaultEndpoint)
           
 
Method Summary
protected  Processor createBodyAndHeaderProcessor(Object body, String header, Object headerValue)
           
protected  Processor createSetBodyProcessor(Object body)
           
protected  void doStart()
           
protected  void doStop()
           
protected  Object extractResultBody(E result)
           
 CamelContext getContext()
           
 Endpoint<E> getDefaultEndpoint()
           
protected  Endpoint<E> getMandatoryDefaultEndpoint()
           
 Producer<E> getProducer(Endpoint<E> endpoint)
           
<T extends Endpoint<?>>
T
getResolvedEndpoint(String endpointUri, Class<T> expectedClass)
           
 boolean isUseEndpointCache()
           
 E request(Endpoint<E> endpoint, Processor processor)
          Send the body to an endpoint returning any result output body
 E request(String endpoint, Processor processor)
          Send the body to an endpoint returning any result output body
 Object requestBody(Endpoint<E> endpoint, Object body)
          Send the body to an endpoint returning any result output body
 Object requestBody(String endpoint, Object body)
          Send the body to an endpoint returning any result output body
 Object requestBodyAndHeader(Endpoint<E> endpoint, Object body, String header, Object headerValue)
          Send the body to an endpoint returning any result output body
 Object requestBodyAndHeader(String endpoint, Object body, String header, Object headerValue)
          Send the body to an endpoint returning any result output body
protected  Endpoint resolveMandatoryEndpoint(String endpointUri)
           
 E send(E exchange)
          Sends the exchange to the default endpoint
 E send(Endpoint<E> endpoint, E exchange)
          Sends the exchange to the given endpoint
 E send(Endpoint<E> endpoint, ExchangePattern pattern, Processor processor)
          Sends an exchange to an endpoint using a supplied
 E send(Endpoint<E> endpoint, Processor processor)
          Sends an exchange to an endpoint using a supplied
 E send(Endpoint<E> endpoint, Processor processor, AsyncCallback callback)
          Sends an exchange to an endpoint using a supplied
 E send(Processor processor)
          Sends an exchange to the default endpoint using a supplied
 E send(String endpointUri, E exchange)
          Sends the exchange to the given endpoint
 E send(String endpointUri, ExchangePattern pattern, Processor processor)
          Sends an exchange to an endpoint using a supplied
 E send(String endpointUri, Processor processor)
          Sends an exchange to an endpoint using a supplied
 E send(String endpointUri, Processor processor, AsyncCallback callback)
          Sends an exchange to an endpoint using a supplied
 Object sendBody(Endpoint<E> endpoint, ExchangePattern pattern, Object body)
          Send the body to an endpoint with the given ExchangePattern returning any result output body
 Object sendBody(Endpoint<E> endpoint, Object body)
          Send the body to an endpoint returning any result output body
 Object sendBody(Object body)
          Sends the body to the default endpoint and returns the result content
 Object sendBody(String endpointUri, ExchangePattern pattern, Object body)
          Send the body to an endpoint
 Object sendBody(String endpointUri, Object body)
          Send the body to an endpoint
 Object sendBodyAndHeader(Endpoint endpoint, ExchangePattern pattern, Object body, String header, Object headerValue)
          Sends the body to an endpoint with a specified header and header value
 Object sendBodyAndHeader(Endpoint endpoint, Object body, String header, Object headerValue)
          Sends the body to an endpoint with a specified header and header value
 Object sendBodyAndHeader(Object body, String header, Object headerValue)
          Sends the body to the default endpoint with a specified header and header value
 Object sendBodyAndHeader(String endpoint, ExchangePattern pattern, Object body, String header, Object headerValue)
          Sends the body to an endpoint with a specified header and header value
 Object sendBodyAndHeader(String endpointUri, Object body, String header, Object headerValue)
          Sends the body to an endpoint with a specified header and header value
 Object sendBodyAndHeaders(Endpoint endpoint, Object body, Map<String,Object> headers)
          Sends the body to an endpoint with the specified headers and header values
 Object sendBodyAndHeaders(Object body, Map<String,Object> headers)
          Sends the body to the default endpoint with the specified headers and header values
 Object sendBodyAndHeaders(String endpointUri, Object body, Map<String,Object> headers)
          Sends the body to an endpoint with the specified headers and header values
 void setDefaultEndpoint(Endpoint<E> defaultEndpoint)
           
 void setDefaultEndpointUri(String endpointUri)
          Sets the default endpoint to use if none is specified
 void setUseEndpointCache(boolean useEndpointCache)
           
 
Methods inherited from class org.apache.camel.impl.ServiceSupport
addChildService, getThreadName, isRunAllowed, isStarted, isStarting, isStopped, isStopping, nextThreadCounter, removeChildService, start, stop
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.camel.Service
start, stop
 

Constructor Detail

CamelTemplate

public CamelTemplate(CamelContext context)

CamelTemplate

public CamelTemplate(CamelContext context,
                     Endpoint defaultEndpoint)
Method Detail

send

public E send(String endpointUri,
              E exchange)
Sends the exchange to the given endpoint

Specified by:
send in interface ProducerTemplate<E extends Exchange>
Parameters:
endpointUri - the endpoint URI to send the exchange to
exchange - the exchange to send

send

public E send(String endpointUri,
              Processor processor)
Sends an exchange to an endpoint using a supplied

Specified by:
send in interface ProducerTemplate<E extends Exchange>
Parameters:
endpointUri - the endpoint URI to send the exchange to
processor - the transformer used to populate the new exchange Processor to populate the exchange

send

public E send(String endpointUri,
              Processor processor,
              AsyncCallback callback)
Sends an exchange to an endpoint using a supplied

Parameters:
endpointUri - the endpoint URI to send the exchange to
processor - the transformer used to populate the new exchange Processor to populate the exchange. The callback will be called when the exchange is completed.

send

public E send(String endpointUri,
              ExchangePattern pattern,
              Processor processor)
Sends an exchange to an endpoint using a supplied

Specified by:
send in interface ProducerTemplate<E extends Exchange>
Parameters:
endpointUri - the endpoint URI to send the exchange to
pattern - the message ExchangePattern such as ExchangePattern.InOnly or ExchangePattern.InOut
processor - the transformer used to populate the new exchange Processor to populate the exchange

send

public E send(Endpoint<E> endpoint,
              E exchange)
Sends the exchange to the given endpoint

Specified by:
send in interface ProducerTemplate<E extends Exchange>
Parameters:
endpoint - the endpoint to send the exchange to
exchange - the exchange to send

send

public E send(Endpoint<E> endpoint,
              Processor processor)
Sends an exchange to an endpoint using a supplied

Specified by:
send in interface ProducerTemplate<E extends Exchange>
Parameters:
endpoint - the endpoint to send the exchange to
processor - the transformer used to populate the new exchange Processor to populate the exchange

send

public E send(Endpoint<E> endpoint,
              Processor processor,
              AsyncCallback callback)
Sends an exchange to an endpoint using a supplied

Parameters:
endpoint - the endpoint to send the exchange to
processor - the transformer used to populate the new exchange Processor to populate the exchange. The callback will be called when the exchange is completed.

send

public E send(Endpoint<E> endpoint,
              ExchangePattern pattern,
              Processor processor)
Sends an exchange to an endpoint using a supplied

Specified by:
send in interface ProducerTemplate<E extends Exchange>
Parameters:
endpoint - the endpoint to send the exchange to
pattern - the message ExchangePattern such as ExchangePattern.InOnly or ExchangePattern.InOut
processor - the transformer used to populate the new exchange Processor to populate the exchange

sendBody

public Object sendBody(Endpoint<E> endpoint,
                       ExchangePattern pattern,
                       Object body)
Send the body to an endpoint with the given ExchangePattern returning any result output body

Specified by:
sendBody in interface ProducerTemplate<E extends Exchange>
Parameters:
endpoint -
body - = the payload
pattern - the message ExchangePattern such as ExchangePattern.InOnly or ExchangePattern.InOut
Returns:
the result

sendBody

public Object sendBody(Endpoint<E> endpoint,
                       Object body)
Send the body to an endpoint returning any result output body

Specified by:
sendBody in interface ProducerTemplate<E extends Exchange>
Parameters:
endpoint -
body - = the payload
Returns:
the result

sendBody

public Object sendBody(String endpointUri,
                       Object body)
Send the body to an endpoint

Specified by:
sendBody in interface ProducerTemplate<E extends Exchange>
Parameters:
endpointUri -
body - = the payload
Returns:
the result

sendBody

public Object sendBody(String endpointUri,
                       ExchangePattern pattern,
                       Object body)
Send the body to an endpoint

Specified by:
sendBody in interface ProducerTemplate<E extends Exchange>
Parameters:
endpointUri -
pattern - the message ExchangePattern such as ExchangePattern.InOnly or ExchangePattern.InOut
body - = the payload
Returns:
the result

sendBodyAndHeader

public Object sendBodyAndHeader(String endpointUri,
                                Object body,
                                String header,
                                Object headerValue)
Sends the body to an endpoint with a specified header and header value

Specified by:
sendBodyAndHeader in interface ProducerTemplate<E extends Exchange>
Parameters:
endpointUri - the endpoint URI to send to
body - the payload send
header - the header name
headerValue - the header value
Returns:
the result

sendBodyAndHeader

public Object sendBodyAndHeader(Endpoint endpoint,
                                Object body,
                                String header,
                                Object headerValue)
Sends the body to an endpoint with a specified header and header value

Specified by:
sendBodyAndHeader in interface ProducerTemplate<E extends Exchange>
Parameters:
endpoint - the Endpoint to send to
body - the payload send
header - the header name
headerValue - the header value
Returns:
the result

sendBodyAndHeader

public Object sendBodyAndHeader(Endpoint endpoint,
                                ExchangePattern pattern,
                                Object body,
                                String header,
                                Object headerValue)
Sends the body to an endpoint with a specified header and header value

Specified by:
sendBodyAndHeader in interface ProducerTemplate<E extends Exchange>
Parameters:
endpoint - the Endpoint to send to
pattern - the message ExchangePattern such as ExchangePattern.InOnly or ExchangePattern.InOut
body - the payload send
header - the header name
headerValue - the header value
Returns:
the result

sendBodyAndHeader

public Object sendBodyAndHeader(String endpoint,
                                ExchangePattern pattern,
                                Object body,
                                String header,
                                Object headerValue)
Sends the body to an endpoint with a specified header and header value

Specified by:
sendBodyAndHeader in interface ProducerTemplate<E extends Exchange>
Parameters:
endpoint - the Endpoint URI to send to
pattern - the message ExchangePattern such as ExchangePattern.InOnly or ExchangePattern.InOut
body - the payload send
header - the header name
headerValue - the header value
Returns:
the result

sendBodyAndHeaders

public Object sendBodyAndHeaders(String endpointUri,
                                 Object body,
                                 Map<String,Object> headers)
Sends the body to an endpoint with the specified headers and header values

Specified by:
sendBodyAndHeaders in interface ProducerTemplate<E extends Exchange>
Parameters:
endpointUri - the endpoint URI to send to
body - the payload send
Returns:
the result

sendBodyAndHeaders

public Object sendBodyAndHeaders(Endpoint endpoint,
                                 Object body,
                                 Map<String,Object> headers)
Sends the body to an endpoint with the specified headers and header values

Specified by:
sendBodyAndHeaders in interface ProducerTemplate<E extends Exchange>
Parameters:
endpoint - the endpoint URI to send to
body - the payload send
Returns:
the result

request

public E request(Endpoint<E> endpoint,
                 Processor processor)
Send the body to an endpoint returning any result output body

Specified by:
request in interface ProducerTemplate<E extends Exchange>
Parameters:
endpoint -
processor - the processor which will populate the exchange before sending
Returns:
the result

requestBody

public Object requestBody(Endpoint<E> endpoint,
                          Object body)
Send the body to an endpoint returning any result output body

Specified by:
requestBody in interface ProducerTemplate<E extends Exchange>
Parameters:
endpoint -
body - = the payload
Returns:
the result

requestBodyAndHeader

public Object requestBodyAndHeader(Endpoint<E> endpoint,
                                   Object body,
                                   String header,
                                   Object headerValue)
Send the body to an endpoint returning any result output body

Specified by:
requestBodyAndHeader in interface ProducerTemplate<E extends Exchange>
Parameters:
endpoint -
body - = the payload
header -
headerValue -
Returns:
the result

request

public E request(String endpoint,
                 Processor processor)
Send the body to an endpoint returning any result output body

Specified by:
request in interface ProducerTemplate<E extends Exchange>
Parameters:
endpoint -
processor - the processor which will populate the exchange before sending
Returns:
the result

requestBody

public Object requestBody(String endpoint,
                          Object body)
Send the body to an endpoint returning any result output body

Specified by:
requestBody in interface ProducerTemplate<E extends Exchange>
Parameters:
endpoint -
body - = the payload
Returns:
the result

requestBodyAndHeader

public Object requestBodyAndHeader(String endpoint,
                                   Object body,
                                   String header,
                                   Object headerValue)
Send the body to an endpoint returning any result output body

Specified by:
requestBodyAndHeader in interface ProducerTemplate<E extends Exchange>
Parameters:
endpoint -
body - = the payload
header -
headerValue -
Returns:
the result

sendBody

public Object sendBody(Object body)
Sends the body to the default endpoint and returns the result content

Specified by:
sendBody in interface ProducerTemplate<E extends Exchange>
Parameters:
body - the body to send
Returns:
the returned message body

send

public E send(E exchange)
Sends the exchange to the default endpoint

Specified by:
send in interface ProducerTemplate<E extends Exchange>
Parameters:
exchange - the exchange to send

send

public E send(Processor processor)
Sends an exchange to the default endpoint using a supplied

Specified by:
send in interface ProducerTemplate<E extends Exchange>
Parameters:
processor - the transformer used to populate the new exchange Processor to populate the exchange

sendBodyAndHeader

public Object sendBodyAndHeader(Object body,
                                String header,
                                Object headerValue)
Description copied from interface: ProducerTemplate
Sends the body to the default endpoint with a specified header and header value

Specified by:
sendBodyAndHeader in interface ProducerTemplate<E extends Exchange>
Parameters:
body - the payload send
header - the header name
headerValue - the header value
Returns:
the result

sendBodyAndHeaders

public Object sendBodyAndHeaders(Object body,
                                 Map<String,Object> headers)
Description copied from interface: ProducerTemplate
Sends the body to the default endpoint with the specified headers and header values

Specified by:
sendBodyAndHeaders in interface ProducerTemplate<E extends Exchange>
Parameters:
body - the payload send
Returns:
the result

getProducer

public Producer<E> getProducer(Endpoint<E> endpoint)

getContext

public CamelContext getContext()

getDefaultEndpoint

public Endpoint<E> getDefaultEndpoint()

setDefaultEndpoint

public void setDefaultEndpoint(Endpoint<E> defaultEndpoint)

setDefaultEndpointUri

public void setDefaultEndpointUri(String endpointUri)
Sets the default endpoint to use if none is specified


isUseEndpointCache

public boolean isUseEndpointCache()

setUseEndpointCache

public void setUseEndpointCache(boolean useEndpointCache)

getResolvedEndpoint

public <T extends Endpoint<?>> T getResolvedEndpoint(String endpointUri,
                                                     Class<T> expectedClass)

createBodyAndHeaderProcessor

protected Processor createBodyAndHeaderProcessor(Object body,
                                                 String header,
                                                 Object headerValue)

createSetBodyProcessor

protected Processor createSetBodyProcessor(Object body)

resolveMandatoryEndpoint

protected Endpoint resolveMandatoryEndpoint(String endpointUri)

getMandatoryDefaultEndpoint

protected Endpoint<E> getMandatoryDefaultEndpoint()

doStart

protected void doStart()
                throws Exception
Specified by:
doStart in class ServiceSupport
Throws:
Exception

doStop

protected void doStop()
               throws Exception
Specified by:
doStop in class ServiceSupport
Throws:
Exception

extractResultBody

protected Object extractResultBody(E result)


Copyright © 2008 IONA Open Source Community. All Rights Reserved.