Package org.apache.camel.model.rest
Class RestConfigurationDefinition
- java.lang.Object
-
- org.apache.camel.model.rest.RestConfigurationDefinition
-
@Metadata(label="rest") public class RestConfigurationDefinition extends Object
To configure rest
-
-
Constructor Summary
Constructors Constructor Description RestConfigurationDefinition()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description RestConfigurationDefinition
apiComponent(String componentId)
To use a specific Camel rest API componentRestConfigurationDefinition
apiContextPath(String contextPath)
Sets a leading context-path the REST services will be using.RestConfigurationDefinition
apiHost(String host)
To define a specific host to use for API documentation instead of using a generated API hostname that is relative to the REST service host.RestConfigurationDefinition
apiProperty(String key, String value)
For configuring an api property, such as api.title, or api.version.RestConfigurationDefinition
apiVendorExtension(boolean vendorExtension)
Whether vendor extension is enabled in the Rest APIs.org.apache.camel.spi.RestConfiguration
asRestConfiguration(org.apache.camel.CamelContext context, org.apache.camel.spi.RestConfiguration target)
Configured an instance of aRestConfiguration
instance based on the definitionRestConfigurationDefinition
bindingMode(String bindingMode)
To specify the binding modeRestConfigurationDefinition
bindingMode(RestBindingMode bindingMode)
To specify the binding modeRestConfigurationDefinition
clientRequestValidation(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.RestConfigurationDefinition
component(String componentId)
To use a specific Camel rest component (consumer)RestConfigurationDefinition
componentProperty(String key, String value)
For additional configuration options on component levelRestConfigurationDefinition
consumerProperty(String key, String value)
For additional configuration options on consumer levelRestConfigurationDefinition
contextPath(String contextPath)
Sets a leading context-path the REST services will be using.RestConfigurationDefinition
corsAllowCredentials(boolean corsAllowCredentials)
Shortcut for setting theAccess-Control-Allow-Credentials
header.RestConfigurationDefinition
corsHeaderProperty(String key, String value)
For configuring CORS headersRestConfigurationDefinition
dataFormatProperty(String key, String value)
For additional configuration options on data format levelRestConfigurationDefinition
enableCORS(boolean enableCORS)
To specify whether to enable CORS which means Camel will automatic include CORS in the HTTP headers in the response.RestConfigurationDefinition
endpointProperty(String key, String value)
For additional configuration options on endpoint levelString
getApiComponent()
String
getApiContextPath()
String
getApiHost()
List<RestPropertyDefinition>
getApiProperties()
Boolean
getApiVendorExtension()
RestBindingMode
getBindingMode()
Boolean
getClientRequestValidation()
String
getComponent()
List<RestPropertyDefinition>
getComponentProperties()
List<RestPropertyDefinition>
getConsumerProperties()
String
getContextPath()
List<RestPropertyDefinition>
getCorsHeaders()
List<RestPropertyDefinition>
getDataFormatProperties()
Boolean
getEnableCORS()
List<RestPropertyDefinition>
getEndpointProperties()
String
getHost()
RestHostNameResolver
getHostNameResolver()
String
getJsonDataFormat()
String
getPort()
String
getProducerApiDoc()
String
getProducerComponent()
String
getScheme()
Boolean
getSkipBindingOnErrorCode()
Boolean
getUseXForwardHeaders()
String
getXmlDataFormat()
RestConfigurationDefinition
host(String host)
To define the host to use, such as 0.0.0.0 or localhostRestConfigurationDefinition
hostNameResolver(RestHostNameResolver hostNameResolver)
To specify the hostname resolverRestConfigurationDefinition
jsonDataFormat(String name)
To use a specific json data formatRestConfigurationDefinition
port(int port)
To specify the port number to use for the REST serviceRestConfigurationDefinition
port(String port)
To specify the port number to use for the REST serviceRestConfigurationDefinition
producerApiDoc(String apiDoc)
Sets the location of the api document the REST producer will use to validate the REST uri and query parameters are valid accordingly to the api document.RestConfigurationDefinition
producerComponent(String componentId)
To use a specific Camel rest component (producer)RestConfigurationDefinition
scheme(String scheme)
To use a specific scheme such as http/httpsvoid
setApiComponent(String apiComponent)
The name of the Camel component to use as the REST API.void
setApiContextPath(String contextPath)
Sets a leading API context-path the REST API services will be using.void
setApiHost(String apiHost)
To use a specific hostname for the API documentation (such as swagger or openapi)void
setApiProperties(List<RestPropertyDefinition> apiProperties)
Allows to configure as many additional properties for the api documentation.void
setApiVendorExtension(Boolean apiVendorExtension)
Whether vendor extension is enabled in the Rest APIs.void
setBindingMode(RestBindingMode bindingMode)
Sets the binding mode to use.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.void
setComponent(String component)
The Camel Rest component to use for the REST transport (consumer), such as netty-http, jetty, servlet, undertow.void
setComponentProperties(List<RestPropertyDefinition> componentProperties)
Allows to configure as many additional properties for the rest component in use.void
setConsumerProperties(List<RestPropertyDefinition> consumerProperties)
Allows to configure as many additional properties for the rest consumer in use.void
setContextPath(String contextPath)
Sets a leading context-path the REST services will be using.void
setCorsHeaders(List<RestPropertyDefinition> corsHeaders)
Allows to configure custom CORS headers.void
setDataFormatProperties(List<RestPropertyDefinition> dataFormatProperties)
Allows to configure as many additional properties for the data formats in use.void
setEnableCORS(Boolean enableCORS)
Whether to enable CORS headers in the HTTP response.void
setEndpointProperties(List<RestPropertyDefinition> endpointProperties)
Allows to configure as many additional properties for the rest endpoint in use.void
setHost(String host)
The hostname to use for exposing the REST service.void
setHostNameResolver(RestHostNameResolver hostNameResolver)
If no hostname has been explicit configured, then this resolver is used to compute the hostname the REST service will be using.void
setJsonDataFormat(String jsonDataFormat)
Name of specific json data format to use.void
setPort(String port)
The port number to use for exposing the REST service.void
setProducerApiDoc(String producerApiDoc)
Sets the location of the api document the REST producer will use to validate the REST uri and query parameters are valid accordingly to the api document.void
setProducerComponent(String producerComponent)
Sets the name of the Camel component to use as the REST producervoid
setScheme(String scheme)
The scheme to use for exposing the REST service.void
setSkipBindingOnErrorCode(Boolean skipBindingOnErrorCode)
Whether to skip binding on output if there is a custom HTTP error code header.void
setUseXForwardHeaders(Boolean useXForwardHeaders)
Whether to use X-Forward headers for Host and related setting.void
setXmlDataFormat(String xmlDataFormat)
Name of specific XML data format to use.RestConfigurationDefinition
skipBindingOnErrorCode(boolean skipBindingOnErrorCode)
To specify whether to skip binding output if there is a custom HTTP error codeRestConfigurationDefinition
useXForwardHeaders(boolean useXForwardHeaders)
To specify whether to use X-Forward headers for Host and related settingRestConfigurationDefinition
xmlDataFormat(String name)
To use a specific XML data format
-
-
-
Method Detail
-
getComponent
public String getComponent()
-
setComponent
public void setComponent(String component)
The Camel Rest component to use for the REST transport (consumer), such as netty-http, jetty, servlet, undertow. 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.
-
getApiComponent
public String getApiComponent()
-
setApiComponent
public void setApiComponent(String apiComponent)
The name of the Camel component to use as the REST API. If no API Component has been explicit configured, then Camel will lookup if there is a Camel component responsible for servicing and generating the REST API documentation, or if a org.apache.camel.spi.RestApiProcessorFactory is registered in the registry. If either one is found, then that is being used.
-
getProducerComponent
public String getProducerComponent()
-
setProducerComponent
public void setProducerComponent(String producerComponent)
Sets the name of the Camel component to use as the REST producer
-
getScheme
public String getScheme()
-
setScheme
public void setScheme(String scheme)
The scheme to use for exposing the REST service. Usually http or https is supported. The default value is http
-
getHost
public String getHost()
-
setHost
public void setHost(String host)
The hostname to use for exposing the REST service.
-
getApiHost
public String getApiHost()
-
setApiHost
public void setApiHost(String apiHost)
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
-
getPort
public String getPort()
-
setPort
public void setPort(String 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.
-
getProducerApiDoc
public String getProducerApiDoc()
-
setProducerApiDoc
public void setProducerApiDoc(String producerApiDoc)
Sets the location of the api document the REST producer will use to validate the REST uri and query parameters are valid accordingly to the api document. 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.
-
getContextPath
public String getContextPath()
-
setContextPath
public void setContextPath(String contextPath)
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.
-
getApiContextPath
public String getApiContextPath()
-
setApiContextPath
public void setApiContextPath(String contextPath)
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
-
getApiVendorExtension
public Boolean getApiVendorExtension()
-
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
public RestHostNameResolver getHostNameResolver()
-
setHostNameResolver
public void setHostNameResolver(RestHostNameResolver hostNameResolver)
If no hostname has been explicit configured, then this resolver is used to compute the hostname the REST service will be using.
-
getBindingMode
public RestBindingMode getBindingMode()
-
setBindingMode
public void setBindingMode(RestBindingMode bindingMode)
Sets the binding mode to use. The default value is off
-
getSkipBindingOnErrorCode
public Boolean getSkipBindingOnErrorCode()
-
setSkipBindingOnErrorCode
public void setSkipBindingOnErrorCode(Boolean skipBindingOnErrorCode)
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.
-
getClientRequestValidation
public Boolean getClientRequestValidation()
-
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.
-
getEnableCORS
public Boolean getEnableCORS()
-
setEnableCORS
public void setEnableCORS(Boolean enableCORS)
Whether to enable CORS headers in the HTTP response. The default value is false.
-
getJsonDataFormat
public String getJsonDataFormat()
-
setJsonDataFormat
public void setJsonDataFormat(String jsonDataFormat)
Name of specific json data format to use. By default 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.
-
getXmlDataFormat
public String getXmlDataFormat()
-
setXmlDataFormat
public void setXmlDataFormat(String 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.
-
getComponentProperties
public List<RestPropertyDefinition> getComponentProperties()
-
setComponentProperties
public void setComponentProperties(List<RestPropertyDefinition> componentProperties)
Allows to configure as many additional properties for the rest component in use.
-
getEndpointProperties
public List<RestPropertyDefinition> getEndpointProperties()
-
setEndpointProperties
public void setEndpointProperties(List<RestPropertyDefinition> endpointProperties)
Allows to configure as many additional properties for the rest endpoint in use.
-
getConsumerProperties
public List<RestPropertyDefinition> getConsumerProperties()
-
setConsumerProperties
public void setConsumerProperties(List<RestPropertyDefinition> consumerProperties)
Allows to configure as many additional properties for the rest consumer in use.
-
getDataFormatProperties
public List<RestPropertyDefinition> getDataFormatProperties()
-
setDataFormatProperties
public void setDataFormatProperties(List<RestPropertyDefinition> dataFormatProperties)
Allows to configure as many additional properties for the data formats in use. For example set property prettyPrint to true to have json outputted in pretty mode. The properties can be prefixed to denote the option is only for either JSON or XML and for either the IN or the OUT. The prefixes are:- json.in.
- json.out.
- xml.in.
- xml.out.
-
getApiProperties
public List<RestPropertyDefinition> getApiProperties()
-
setApiProperties
public void setApiProperties(List<RestPropertyDefinition> apiProperties)
Allows to configure as many additional properties for the api documentation. For example set property api.title to my cool stuff
-
getCorsHeaders
public List<RestPropertyDefinition> getCorsHeaders()
-
setCorsHeaders
public void setCorsHeaders(List<RestPropertyDefinition> corsHeaders)
Allows to configure custom CORS headers.
-
getUseXForwardHeaders
public Boolean getUseXForwardHeaders()
-
setUseXForwardHeaders
public void setUseXForwardHeaders(Boolean useXForwardHeaders)
Whether to use X-Forward headers for Host and related setting. The default value is true.
-
component
public RestConfigurationDefinition component(String componentId)
To use a specific Camel rest component (consumer)
-
apiComponent
public RestConfigurationDefinition apiComponent(String componentId)
To use a specific Camel rest API component
-
producerComponent
public RestConfigurationDefinition producerComponent(String componentId)
To use a specific Camel rest component (producer)
-
scheme
public RestConfigurationDefinition scheme(String scheme)
To use a specific scheme such as http/https
-
host
public RestConfigurationDefinition host(String host)
To define the host to use, such as 0.0.0.0 or localhost
-
apiHost
public RestConfigurationDefinition apiHost(String host)
To define a specific host to use for API documentation instead of using a generated API hostname that is relative to the REST service host.
-
port
public RestConfigurationDefinition port(int port)
To specify the port number to use for the REST service
-
port
public RestConfigurationDefinition port(String port)
To specify the port number to use for the REST service
-
producerApiDoc
public RestConfigurationDefinition producerApiDoc(String apiDoc)
Sets the location of the api document the REST producer will use to validate the REST uri and query parameters are valid accordingly to the api document. 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.
-
apiContextPath
public RestConfigurationDefinition apiContextPath(String contextPath)
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.
-
apiVendorExtension
public RestConfigurationDefinition apiVendorExtension(boolean vendorExtension)
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. Some API tooling may not support vendor extensions and this option can then be turned off.
-
contextPath
public RestConfigurationDefinition contextPath(String contextPath)
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.
-
hostNameResolver
public RestConfigurationDefinition hostNameResolver(RestHostNameResolver hostNameResolver)
To specify the hostname resolver
-
bindingMode
public RestConfigurationDefinition bindingMode(RestBindingMode bindingMode)
To specify the binding mode
-
bindingMode
public RestConfigurationDefinition bindingMode(String bindingMode)
To specify the binding mode
-
skipBindingOnErrorCode
public RestConfigurationDefinition skipBindingOnErrorCode(boolean skipBindingOnErrorCode)
To specify whether to skip binding output if there is a custom HTTP error code
-
clientRequestValidation
public RestConfigurationDefinition clientRequestValidation(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.
-
enableCORS
public RestConfigurationDefinition enableCORS(boolean enableCORS)
To specify whether to enable CORS which means Camel will automatic include CORS in the HTTP headers in the response.
-
jsonDataFormat
public RestConfigurationDefinition jsonDataFormat(String name)
To use a specific 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.- Parameters:
name
- name of the data format toresolve
-
xmlDataFormat
public RestConfigurationDefinition xmlDataFormat(String name)
To use a specific 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.- Parameters:
name
- name of the data format toresolve
-
componentProperty
public RestConfigurationDefinition componentProperty(String key, String value)
For additional configuration options on component level The value can use # to refer to a bean to lookup in the registry.
-
endpointProperty
public RestConfigurationDefinition endpointProperty(String key, String value)
For additional configuration options on endpoint level The value can use # to refer to a bean to lookup in the registry.
-
consumerProperty
public RestConfigurationDefinition consumerProperty(String key, String value)
For additional configuration options on consumer level The value can use # to refer to a bean to lookup in the registry.
-
dataFormatProperty
public RestConfigurationDefinition dataFormatProperty(String key, String value)
For additional configuration options on data format level The value can use # to refer to a bean to lookup in the registry.
-
apiProperty
public RestConfigurationDefinition apiProperty(String key, String value)
For configuring an api property, such as api.title, or api.version.
-
corsHeaderProperty
public RestConfigurationDefinition corsHeaderProperty(String key, String value)
For configuring CORS headers
-
corsAllowCredentials
public RestConfigurationDefinition corsAllowCredentials(boolean corsAllowCredentials)
Shortcut for setting theAccess-Control-Allow-Credentials
header.
-
useXForwardHeaders
public RestConfigurationDefinition useXForwardHeaders(boolean useXForwardHeaders)
To specify whether to use X-Forward headers for Host and related setting
-
asRestConfiguration
public org.apache.camel.spi.RestConfiguration asRestConfiguration(org.apache.camel.CamelContext context, org.apache.camel.spi.RestConfiguration target) throws Exception
Configured an instance of aRestConfiguration
instance based on the definition- Parameters:
context
- the camel contexttarget
- theRestConfiguration
target- Returns:
- the configuration
- Throws:
Exception
- is thrown if error creating the configuration
-
-