Configure REST DSL (REST)

Configuring with Java

In Java, we are able to configure the REST DSL using the restConfiguration() builder API. To configure the REST DSL to use the Servlet component as the underlying implementation, we would do the following:

restConfiguration().component("servlet").bindingMode("json").port("8181") .contextPath("/camel-example-servlet-rest-blueprint/rest");

Configuring with XML

In XML, we are able to configure the REST DSL using the restConfiguration element. To configure the REST DSL to use the Servlet component as the underlying implementation, we would do the following:

<camelContext xmlns="http://camel.apache.org/schema/blueprint"> ... <restConfiguration component="servlet" bindingMode="json" contextPath="/camel-example-servlet-rest-blueprint/rest" port="8181"> <dataFormatProperty key="prettyPrint" value="true"/> </restConfiguration> ... </camelContext>

Configuration Options

Java DSL

XML DSL

Description

Java DSL

XML DSL

Description

component()

@component

Specifies the Camel component to use as the REST transport (for example, servlet, restlet, spark-rest, and so on). The value can either be the standard component name or the bean ID of a custom instance. If this option is not specified, Camel looks for an instance of RestConsumerFactory on the classpath or in the bean registry.

scheme()

@scheme

The protocol to use for exposing the REST service. Depends on the underlying REST implementation, but http and https are usually supported. Default is http.

host()

@host

Hostname to use for exposing the REST service.

port()

@port

Port number to use for exposing the REST service.

contextPath()

@contextPath

The leading context path for the REST services. This can be used with components such as Servlet, where the deployed Web application is deployed using a context-path setting.

hostNameResolver()

@hostNameResolver

If a hostname is not set explicitly, this resolver determines the host for the REST service.

bindingMode()

@bindingMode

Enables binding mode for JSON or XML format messages. (ie. possible values are: off, auto, json, xml, or json_xml. Default is off.

skipBindingOnErrorCode()

@skipBindingOnErrorCode

Specifies whether to skip binding on output, if there is a custom HTTP error code header. Allows you to build custom error messages that do not bind to JSON or XML. Default is true.

jsonDataFormat()

@jsonDataFormat

Specifies the component that Camel uses to implement the JSON data format. Possible values are: json-jackson, json-gson, json-xstream. Default is json-jackson.

xmlDataFormat()

@xmlDataFormat

Specifies the component that Camel uses to implement the XML data format. Possible value is: jaxb. Default is jaxb.

componentProperty()

@componentProperty

Enables you to set arbitrary component level properties on the underlying REST implementation.

endPointProperty()

@endPointProperty

Enables you to set arbitrary endpoint level properties on the underlying REST implementation.

consumerProperty()

@consumerProperty

Enables you to set arbitrary consumer endpoint properties on the underlying REST implementation.

dataFormatProperty()

@dataFormatProperty

Set arbitrary properties on the underlying data format component (for example, Jackson or JAXB).