Class RestConfiguration
java.lang.Object
org.apache.camel.spi.RestConfiguration
Central configuration bean for the Camel REST DSL, shared by
RestConsumerFactory,
RestProducerFactory, and RestApiConsumerFactory implementations.
An instance of this class is held on CamelContext and controls every aspect of REST service
hosting and client invocation: the HTTP component to use (e.g. platform-http, jetty,
netty-http, servlet), the server host and port, the binding mode (RestConfiguration.RestBindingMode.off,
RestConfiguration.RestBindingMode.json, RestConfiguration.RestBindingMode.xml, or RestConfiguration.RestBindingMode.json_xml), CORS headers, JSON
and XML data-format class names, and additional Map<String, Object> property overrides for the component,
consumer, and producer tiers. The configuration is typically expressed via the restConfiguration() builder in
the Java DSL, or the rest-configuration element in XML and YAML DSLs.
See Rest DSL in the Camel user manual.- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumstatic enum -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription@Nullable StringGets the name of the Camel component to use as the REST API (such as swagger or openapi).@Nullable StringGets the leading API context-path the REST API services will be using.@Nullable StringGets the route id used for the route that services the REST API.@Nullable StringGets the hostname to use for the API documentation (such as swagger or openapi).Gets additional options on API level.Gets the binding mode used by the REST consumer@Nullable StringGets the package name used as base for classpath scanning of POJO classes when binding mode is enabled.@Nullable StringGets the name of the Camel component to use as the REST consumerGets additional options on component levelGets additional options on consumer level@Nullable StringGets the configured context-pathGets the CORS headers to use if CORS has been enabled.Gets additional options on data format levelGets additional options on endpoint level@Nullable StringgetHost()Gets the hostname to use by the REST consumerGets the resolver to use for resolving hostname@Nullable StringGets the name of the json data format.intgetPort()Gets the port to use by the REST consumer@Nullable StringGets the location of the api document (swagger api) the REST producer will use to validate the REST uri and query parameters are valid accordingly to the api document.@Nullable StringGets the name of the Camel component to use as the REST producer@Nullable StringGets the scheme to use by the REST consumerGets the client request validation levels when using camel-openapi-validator.@Nullable StringGets the name of the xml data format.booleanWhether vendor extension is enabled in the REST APIs.booleanWhether client request validation is enabled.booleanWhether client response validation is enabled.booleanTo specify whether to enable CORS which means Camel will automatically include CORS in the HTTP headers in the response.booleanWhether HTTP 204 No Content responses are enabled for empty JSON or XML responses.booleanWhether routes in rest-dsl linked via direct endpoints are inlined as a single route.booleanWhether to skip binding output if there is a custom HTTP error code, and instead use the response body as-is.booleanWhether to use X-Forward headers to set host etc. for OpenApi.voidsetApiComponent(String apiComponent) Sets the name of the Camel component to use as the REST API (such as swagger or openapi)voidsetApiContextPath(String contextPath) Sets a leading API context-path the REST API services will be using.voidsetApiContextRouteId(String apiContextRouteId) Sets the route id to use for the route that services the REST API.voidsetApiHost(String apiHost) To use a specific hostname for the API documentation (such as swagger or openapi)voidsetApiProperties(Map<String, Object> apiProperties) Sets additional options on api levelvoidsetApiVendorExtension(boolean apiVendorExtension) Whether vendor extension is enabled in the Rest APIs.voidsetBindingMode(String bindingMode) Sets the binding mode to be used by the REST consumervoidsetBindingMode(RestConfiguration.RestBindingMode bindingMode) Sets the binding mode to be used by the REST consumervoidsetBindingPackageScan(String bindingPackageScan) Package name to use as base (offset) for classpath scanning of POJO classes are located when using binding mode is enabled for JSon or XML.voidsetClientRequestValidation(boolean clientRequestValidation) Whether to enable validation of the client request to check: 1) Content-Type header matches what the Rest DSL consumes; returns HTTP Status 415 if validation error. 2) Accept header matches what the Rest DSL produces; returns HTTP Status 406 if validation error. 3) Missing required data (query parameters, HTTP headers, body); returns HTTP Status 400 if validation error. 4) Parsing error of the message body (JSon, XML or Auto binding mode must be enabled); returns HTTP Status 400 if validation error.voidsetClientResponseValidation(boolean clientResponseValidation) Whether to check what Camel is returning as response to the client: 1) Status-code and Content-Type matches Rest DSL response messages. 2) Check whether expected headers is included according to the Rest DSL repose message headers. 3) If the response body is JSon then check whether its valid JSon.voidsetComponent(String componentName) Sets the name of the Camel component to use as the REST consumervoidsetComponentProperties(Map<String, Object> componentProperties) Sets additional options on component levelvoidsetConsumerProperties(Map<String, Object> consumerProperties) Sets additional options on consumer levelvoidsetContextPath(String contextPath) Sets a leading context-path the REST services will be using.voidsetCorsHeaders(Map<String, String> corsHeaders) Sets the CORS headers to use if CORS has been enabled.voidsetDataFormatProperties(Map<String, Object> dataFormatProperties) Sets additional options on data format levelvoidsetEnableCORS(boolean enableCORS) To specify whether to enable CORS which means Camel will automatic include CORS in the HTTP headers in the response.voidsetEnableNoContentResponse(boolean enableNoContentResponse) Whether to return HTTP 204 with an empty body when a response contains an empty JSON object or XML root object.voidsetEndpointProperties(Map<String, Object> endpointProperties) Sets additional options on endpoint levelvoidSets the hostname to use by the REST consumervoidsetHostNameResolver(String hostNameResolver) Sets the resolver to use for resolving hostnamevoidsetHostNameResolver(RestConfiguration.RestHostNameResolver hostNameResolver) Sets the resolver to use for resolving hostnamevoidsetInlineRoutes(boolean inlineRoutes) Inline routes in rest-dsl which are linked using direct endpoints.voidsetJsonDataFormat(String name) Sets a custom json data format to be usedvoidsetPort(int port) Sets the port to use by the REST consumervoidsetProducerApiDoc(String producerApiDoc) Sets the location of the api document (swagger api) the REST producer will use to validate the REST uri and query parameters are valid accordingly to the api document.voidsetProducerComponent(String componentName) Sets the name of the Camel component to use as the REST producervoidSets the scheme to use by the REST consumervoidsetSkipBindingOnErrorCode(boolean skipBindingOnErrorCode) Whether to skip binding output if there is a custom HTTP error code, and instead use the response body as-is.voidsetUseXForwardHeaders(boolean useXForwardHeaders) Whether to use X-Forward headers to set host etc. for OpenApi.voidsetValidationLevels(@Nullable Map<String, String> validationLevels) Sets the client request validation levels when using camel-openapi-validator.voidsetXmlDataFormat(String name) Sets a custom xml data format to be used.
-
Field Details
-
CORS_ACCESS_CONTROL_ALLOW_ORIGIN
- See Also:
-
CORS_ACCESS_CONTROL_ALLOW_METHODS
- See Also:
-
CORS_ACCESS_CONTROL_MAX_AGE
- See Also:
-
CORS_ACCESS_CONTROL_ALLOW_HEADERS
- See Also:
-
DEFAULT_REST_CONFIGURATION_ID
- See Also:
-
-
Constructor Details
-
RestConfiguration
public RestConfiguration()
-
-
Method Details
-
getComponent
-
setComponent
Sets the name of the Camel component to use as the REST consumer- Parameters:
componentName- the name of the component (such as netty-http, jetty, servlet, undertow, etc.)
-
getApiComponent
Gets the name of the Camel component to use as the REST API (such as swagger or openapi).- Returns:
- the component name
-
setApiComponent
Sets the name of the Camel component to use as the REST API (such as swagger or openapi)- Parameters:
apiComponent- the name of the component (such as swagger or openapi)
-
getProducerComponent
-
setProducerComponent
Sets the name of the Camel component to use as the REST producer- Parameters:
componentName- the name of the component (such as http, netty-http, undertow, etc.)
-
getProducerApiDoc
Gets the location of the api document (swagger api) the REST producer will use to validate the REST uri and query parameters are valid accordingly to the api document. -
setProducerApiDoc
Sets the location of the api document (swagger api) the REST producer will use to validate the REST uri and query parameters are valid accordingly to the api document. This requires adding camel-openapi-java to the classpath, and any miss configuration will let Camel fail on startup and report the error(s). The location of the api document is loaded from classpath by default, but you can use file: or http: to refer to resources to load from file or http url. -
getHost
Gets the hostname to use by the REST consumer- Returns:
- the hostname, or null to use default hostname
-
setHost
Sets the hostname to use by the REST consumer- Parameters:
host- the hostname
-
isUseXForwardHeaders
public boolean isUseXForwardHeaders()Whether to use X-Forward headers to set host etc. for OpenApi. This may be needed in special cases involving reverse-proxy and networking going from HTTP to HTTPS etc. Then the proxy can send X-Forward headers (X-Forwarded-Proto) that influences the host names in the OpenAPI schema that camel-openapi-java generates from Rest DSL routes. -
setUseXForwardHeaders
public void setUseXForwardHeaders(boolean useXForwardHeaders) Whether to use X-Forward headers to set host etc. for OpenApi. This may be needed in special cases involving reverse-proxy and networking going from HTTP to HTTPS etc. Then the proxy can send X-Forward headers (X-Forwarded-Proto) that influences the host names in the OpenAPI schema that camel-openapi-java generates from Rest DSL routes. -
getApiHost
Gets the hostname to use for the API documentation (such as swagger or openapi).- Returns:
- the API host, or null to use the default host
-
setApiHost
To use a specific hostname for the API documentation (such as swagger or openapi) This can be used to override the generated host with this configured hostname -
getScheme
Gets the scheme to use by the REST consumer- Returns:
- the scheme, or null to use default scheme
-
setScheme
Sets the scheme to use by the REST consumer- Parameters:
scheme- the scheme
-
getPort
public int getPort()Gets the port to use by the REST consumer- Returns:
- the port, or 0 or -1 to use default port
-
setPort
public void setPort(int port) Sets the port to use by the REST consumer- Parameters:
port- the port number
-
getContextPath
Gets the configured context-path- Returns:
- the context path, or null if none configured.
-
setContextPath
Sets a leading context-path the REST services will be using. This can be used when using components such as camel-servlet where the deployed web application is deployed using a context-path. Or for components such as camel-jetty or camel-netty-http that includes a HTTP server.- Parameters:
contextPath- the context path
-
getApiContextPath
Gets the leading API context-path the REST API services will be using.- Returns:
- the API context path, or null if none configured.
-
setApiContextPath
Sets a leading API context-path the REST API services will be using. This can be used when using components such as camel-servlet where the deployed web application is deployed using a context-path.- Parameters:
contextPath- the API context path
-
getApiContextRouteId
Gets the route id used for the route that services the REST API.- Returns:
- the route id, or null if using an auto-assigned id
-
setApiContextRouteId
Sets the route id to use for the route that services the REST API. The route will by default use an auto assigned route id.- Parameters:
apiContextRouteId- the route id
-
isApiVendorExtension
public boolean isApiVendorExtension()Whether vendor extension is enabled in the REST APIs.- Returns:
- true if vendor extensions are included in the API docs
-
setApiVendorExtension
public void setApiVendorExtension(boolean apiVendorExtension) Whether vendor extension is enabled in the Rest APIs. If enabled then Camel will include additional information as vendor extension (eg keys starting with x-) such as route ids, class names etc. Not all 3rd party API gateways and tools supports vendor-extensions when importing your API docs. -
getHostNameResolver
Gets the resolver to use for resolving hostname- Returns:
- the resolver
-
setHostNameResolver
Sets the resolver to use for resolving hostname- Parameters:
hostNameResolver- the resolver
-
setHostNameResolver
Sets the resolver to use for resolving hostname- Parameters:
hostNameResolver- the resolver
-
getBindingMode
Gets the binding mode used by the REST consumer- Returns:
- the binding mode
-
setBindingMode
Sets the binding mode to be used by the REST consumer- Parameters:
bindingMode- the binding mode
-
setBindingMode
Sets the binding mode to be used by the REST consumer- Parameters:
bindingMode- the binding mode
-
getBindingPackageScan
Gets the package name used as base for classpath scanning of POJO classes when binding mode is enabled.- Returns:
- the package name, or null if not configured
-
setBindingPackageScan
Package name to use as base (offset) for classpath scanning of POJO classes are located when using binding mode is enabled for JSon or XML. Multiple package names can be separated by comma. -
isSkipBindingOnErrorCode
public boolean isSkipBindingOnErrorCode()Whether to skip binding output if there is a custom HTTP error code, and instead use the response body as-is. This option is default true.- Returns:
- whether to skip binding on error code
-
setSkipBindingOnErrorCode
public void setSkipBindingOnErrorCode(boolean skipBindingOnErrorCode) Whether to skip binding output if there is a custom HTTP error code, and instead use the response body as-is. This option is default true.- Parameters:
skipBindingOnErrorCode- whether to skip binding on error code
-
isClientRequestValidation
public boolean isClientRequestValidation()Whether client request validation is enabled.- Returns:
- true if client request validation is enabled
-
setClientRequestValidation
public void setClientRequestValidation(boolean clientRequestValidation) Whether to enable validation of the client request to check: 1) Content-Type header matches what the Rest DSL consumes; returns HTTP Status 415 if validation error. 2) Accept header matches what the Rest DSL produces; returns HTTP Status 406 if validation error. 3) Missing required data (query parameters, HTTP headers, body); returns HTTP Status 400 if validation error. 4) Parsing error of the message body (JSon, XML or Auto binding mode must be enabled); returns HTTP Status 400 if validation error. -
isClientResponseValidation
public boolean isClientResponseValidation()Whether client response validation is enabled.- Returns:
- true if client response validation is enabled
-
setClientResponseValidation
public void setClientResponseValidation(boolean clientResponseValidation) Whether to check what Camel is returning as response to the client: 1) Status-code and Content-Type matches Rest DSL response messages. 2) Check whether expected headers is included according to the Rest DSL repose message headers. 3) If the response body is JSon then check whether its valid JSon. Returns 500 if validation error detected. -
isEnableCORS
public boolean isEnableCORS()To specify whether to enable CORS which means Camel will automatically include CORS in the HTTP headers in the response. This option is default false- Returns:
- whether CORS is enabled or not
-
setEnableCORS
public void setEnableCORS(boolean enableCORS) To specify whether to enable CORS which means Camel will automatic include CORS in the HTTP headers in the response. This option is default false- Parameters:
enableCORS- true to enable CORS
-
isEnableNoContentResponse
public boolean isEnableNoContentResponse()Whether HTTP 204 No Content responses are enabled for empty JSON or XML responses.- Returns:
- true if HTTP 204 responses are enabled
-
setEnableNoContentResponse
public void setEnableNoContentResponse(boolean enableNoContentResponse) Whether to return HTTP 204 with an empty body when a response contains an empty JSON object or XML root object. The default value is false.- Parameters:
enableNoContentResponse- true to enable HTTP 204 response codes
-
isInlineRoutes
public boolean isInlineRoutes()Whether routes in rest-dsl linked via direct endpoints are inlined as a single route.- Returns:
- true if rest-dsl routes are inlined
-
setInlineRoutes
public void setInlineRoutes(boolean inlineRoutes) Inline routes in rest-dsl which are linked using direct endpoints. Each service in Rest DSL is an individual route, meaning that you would have at least two routes per service (rest-dsl, and the route linked from rest-dsl). By inlining (default) allows Camel to optimize and inline this as a single route, however this requires to use direct endpoints, which must be unique per service. If a route is not using direct endpoint then the rest-dsl is not inlined, and will become an individual route. This option is default true. -
getJsonDataFormat
Gets the name of the json data format. Important: This option is only for setting a custom name of the data format, not to refer to an existing data format instance.- Returns:
- the name, or null to use default
-
setJsonDataFormat
Sets a custom json data format to 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.- Parameters:
name- name of the data format
-
getXmlDataFormat
Gets the name of the xml data format. Important: This option is only for setting a custom name of the data format, not to refer to an existing data format instance.- Returns:
- the name, or null to use default
-
setXmlDataFormat
Sets a custom xml data format to 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.- Parameters:
name- name of the data format
-
getComponentProperties
-
setComponentProperties
-
getEndpointProperties
-
setEndpointProperties
-
getConsumerProperties
-
setConsumerProperties
-
getDataFormatProperties
-
setDataFormatProperties
-
getApiProperties
-
setApiProperties
-
getCorsHeaders
-
setCorsHeaders
-
getValidationLevels
-
setValidationLevels
-