Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Base PathUri templateVerbConsumes

/say

/hello

get

all

/say

/bye

get

application/json

/say

/bye

post

all

Notice that in the REST service we route directly to a Camel endpoint using the to(). This is because the Rest DSL has a short-hand for routing directly to an endpoint using to(). An alternative is to embed a Camel route directly using route() - there is such an example further below.

...

The binding modes are:

Binding ModeDescription

off

Binding is turned off. This is the default option.

auto

Binding is enabled and Camel is relaxed and support json, xml or both if the needed data formats are included in the classpath. Notice that if for example camel-jaxb is not on the classpath, then XML binding is not enabled.

json

Binding to/from json is enabled, and requires a json capabile data format on the classpath. By default Camel will use json-jackson as the data format.

xml

Binding to/from xml is enabled, and requires camel-jaxb on the classpath.

json_xml

Biding to/from json and xml is enabled and requires both data formats to be on the classpath.

Tip

From Camel 2.14.1 onwards when using camel-jaxb for xml bindings, then you can use the option mustBeJAXBElement to relax the output message body must be a class with JAXB annotations. You can use this in situations where the message body is already in XML format, and you want to use the message body as-is as the output type. If that is the case, then set the dataFormatProperty option mustBeJAXBElement to false value.

...

Message BodyDirectionBinding ModeMessage Body

XML

Incoming

auto
xml
json_xml 

POJO

POJO

Outgoing

auto

xml

json_xml 

XML

JSON

Incoming

auto

json

json_xml 

POJO

POJO

Outgoing

auto

json

json_xml 

JSON

 

When using binding you must also configure what POJO type to map to. This is mandatory for incoming messages, and optional for outgoing. 

...

The Rest DSL allows to configure the following options using a builder style

OptionDefaultDescription

component

 

The Camel Rest component to use for the REST transport, such as restlet, spark-rest. If no component has been explicit configured, then Camel will lookup if there is a Camel component that integrates with the Rest DSL, or if a org.apache.camel.spi.RestConsumerFactory is registered in the registry. If either one is found, then that is being used.

scheme

http

The scheme to use for exposing the REST service. Usually http or https is supported

hostname

 

The hostname to use for exposing the REST service.

port

 

The port number to use for exposing the REST service. Notice if you use servlet component then the port number configured here does not apply, as the port number in use is the actual port number the servlet component is using. eg if using Apache Tomcat its the tomcat http port, if using Apache Karaf its the HTTP service in Karaf that uses port 8181 by default etc. Though in those situations setting the port number here, allows tooling and JMX to know the port number, so its recommended to set the port number to the number that the servlet engine uses.

contextPath

 

Sets a leading context-path the REST services will be using. This can be used when using components such as SERVLET where the deployed web application is deployed using a context-path.

restHostNameResolver

localHostName

If no hostname has been explicit configured, then this resolver is used to compute the hostname the REST service will be using. The resolver supports localHostName or localIp.

bindingMode

off

Whether binding is in use. See further above for more details.

skipBindingOnErrorCode

true

Camel 2.14.1: Whether to skip binding on output if there is a custom HTTP error code header. This allows to build custom error messages that do not bind to json / xml etc, as success messages otherwise will do. See further below for an example.

enableCORS

false

Camel 2.14.1: Whether to enable CORS headers in the HTTP response.

jsonDataFormat

 

Name of specific json data format to use. By default json-jackson will be used. Important: This option is only for setting a custom name of the data format, not to refer to an existing data format instance. Notice: Currently Jackson is what we recommend and are using for testing.

xmlDataFormat

 

Name of specific XML data format to use. By default jaxb will be used. Important: This option is only for setting a custom name of the data format, not to refer to an existing data format instance. Notice: Currently only jaxb is supported.

componentProperty

 

Allows to configure as many additional properties. This is used to configure component specific options such as for Restlet / Spark-Rest etc.

endpointProperty

 

Allows to configure as many additional properties. This is used to configure endpoint specific options for  Restlet / Spark-Rest etc.

consumerProperty

 

Allows to configure as many additional properties. This is used to configure consumer specific options for  Restlet / Spark-Rest etc.

dataFormatProperty

 

Allows to configure as many additional properties. This is used to configure the data format specific options. For example set property prettyPrint to true to have json outputted in pretty mode. From Camel 2.14.1 onwards the keys can be prefixed with either

  • json.in.

  • json.out.

  • xml.in.

  • xml.out.

to denote that the option is only for either JSON or XML data format, and only for either the in or the out going. For example a key with value "xml.out.mustBeJAXBElement" is only for the XML data format for the outgoing. A key without a prefix is a common key for all situations.

corsHeaderProperty

 

Allows to configure custom CORS headers.

 

For example to configure to use the spark-rest component on port 9091, then we can do as follows

...

If CORS is enabled then the follow headers is in use by default. You can configure custom CORS headers which takes precedence over the default value.

KeyValue

Access-Control-Allow-Origin

*

Access-Control-Allow-Methods

GET, HEAD, POST, PUT, DELETE, TRACE, OPTIONS, CONNECT, PATCH

Access-Control-Allow-Headers

Origin, Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers

Access-Control-Max-Age

3600

 

Defining a custom error message as-is

...