Package org.apache.camel.spi
Class RestConfiguration
- java.lang.Object
-
- org.apache.camel.spi.RestConfiguration
-
public class RestConfiguration extends Object
Configuration use byRestConsumerFactoryandRestApiConsumerFactoryfor Camel components to support the CamelrestDSL.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classRestConfiguration.RestBindingModestatic classRestConfiguration.RestHostNameResolver
-
Field Summary
Fields Modifier and Type Field Description static StringCORS_ACCESS_CONTROL_ALLOW_HEADERSstatic StringCORS_ACCESS_CONTROL_ALLOW_METHODSstatic StringCORS_ACCESS_CONTROL_ALLOW_ORIGINstatic StringCORS_ACCESS_CONTROL_MAX_AGEstatic StringDEFAULT_REST_CONFIGURATION_ID
-
Constructor Summary
Constructors Constructor Description RestConfiguration()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description StringgetApiComponent()Gets the name of the Camel component to use as the REST API (such as swagger or openapi).StringgetApiContextPath()StringgetApiContextRouteId()StringgetApiHost()Map<String,Object>getApiProperties()RestConfiguration.RestBindingModegetBindingMode()Gets the binding mode used by the REST consumerStringgetComponent()Gets the name of the Camel component to use as the REST consumerMap<String,Object>getComponentProperties()Gets additional options on component levelMap<String,Object>getConsumerProperties()Gets additional options on consumer levelStringgetContextPath()Gets the configured context-pathMap<String,String>getCorsHeaders()Gets the CORS headers to use if CORS has been enabled.Map<String,Object>getDataFormatProperties()Gets additional options on data format levelMap<String,Object>getEndpointProperties()Gets additional options on endpoint levelStringgetHost()Gets the hostname to use by the REST consumerRestConfiguration.RestHostNameResolvergetHostNameResolver()Gets the resolver to use for resolving hostnameStringgetJsonDataFormat()Gets the name of the json data format.intgetPort()Gets the port to use by the REST consumerStringgetProducerApiDoc()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.StringgetProducerComponent()Gets the name of the Camel component to use as the REST producerStringgetScheme()Gets the scheme to use by the REST consumerStringgetXmlDataFormat()Gets the name of the xml data format.booleanisApiVendorExtension()booleanisClientRequestValidation()booleanisEnableCORS()To specify whether to enable CORS which means Camel will automatic include CORS in the HTTP headers in the response.booleanisInlineRoutes()booleanisSkipBindingOnErrorCode()Whether to skip binding output if there is a custom HTTP error code, and instead use the response body as-is.booleanisUseXForwardHeaders()Whether to use X-Forward headers to set host etc.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 consumervoidsetClientRequestValidation(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.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.voidsetEndpointProperties(Map<String,Object> endpointProperties)Sets additional options on endpoint levelvoidsetHost(String host)Sets 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 producervoidsetScheme(String scheme)Sets 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.voidsetXmlDataFormat(String name)Sets a custom xml data format to be used.
-
-
-
Field Detail
-
CORS_ACCESS_CONTROL_ALLOW_ORIGIN
public static final String CORS_ACCESS_CONTROL_ALLOW_ORIGIN
- See Also:
- Constant Field Values
-
CORS_ACCESS_CONTROL_ALLOW_METHODS
public static final String CORS_ACCESS_CONTROL_ALLOW_METHODS
- See Also:
- Constant Field Values
-
CORS_ACCESS_CONTROL_MAX_AGE
public static final String CORS_ACCESS_CONTROL_MAX_AGE
- See Also:
- Constant Field Values
-
CORS_ACCESS_CONTROL_ALLOW_HEADERS
public static final String CORS_ACCESS_CONTROL_ALLOW_HEADERS
- See Also:
- Constant Field Values
-
DEFAULT_REST_CONFIGURATION_ID
public static final String DEFAULT_REST_CONFIGURATION_ID
- See Also:
- Constant Field Values
-
-
Method Detail
-
getComponent
public String getComponent()
Gets the name of the Camel component to use as the REST consumer- Returns:
- the component name, or null to let Camel search the
Registryto find suitable implementation
-
setComponent
public void setComponent(String componentName)
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
public String getApiComponent()
Gets the name of the Camel component to use as the REST API (such as swagger or openapi).- Returns:
- the component name
-
setApiComponent
public void setApiComponent(String apiComponent)
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
public String getProducerComponent()
Gets the name of the Camel component to use as the REST producer- Returns:
- the component name, or null to let Camel search the
Registryto find suitable implementation
-
setProducerComponent
public void setProducerComponent(String componentName)
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
public String 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
public void setProducerApiDoc(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. This requires adding camel-openapi-java, or camel-swagger-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
public String getHost()
Gets the hostname to use by the REST consumer- Returns:
- the hostname, or null to use default hostname
-
setHost
public void setHost(String host)
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 Swagger. This option is default true.
-
setUseXForwardHeaders
public void setUseXForwardHeaders(boolean useXForwardHeaders)
Whether to use X-Forward headers to set host etc. for Swagger. This option is default true.
-
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
-
getScheme
public String getScheme()
Gets the scheme to use by the REST consumer- Returns:
- the scheme, or null to use default scheme
-
setScheme
public void setScheme(String scheme)
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
public String getContextPath()
Gets the configured context-path- Returns:
- the context path, or null if none configured.
-
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.- Parameters:
contextPath- the context path
-
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
-
getApiContextRouteId
public String getApiContextRouteId()
-
setApiContextRouteId
public void setApiContextRouteId(String apiContextRouteId)
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()
-
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 RestConfiguration.RestHostNameResolver getHostNameResolver()
Gets the resolver to use for resolving hostname- Returns:
- the resolver
-
setHostNameResolver
public void setHostNameResolver(RestConfiguration.RestHostNameResolver hostNameResolver)
Sets the resolver to use for resolving hostname- Parameters:
hostNameResolver- the resolver
-
setHostNameResolver
public void setHostNameResolver(String hostNameResolver)
Sets the resolver to use for resolving hostname- Parameters:
hostNameResolver- the resolver
-
getBindingMode
public RestConfiguration.RestBindingMode getBindingMode()
Gets the binding mode used by the REST consumer- Returns:
- the binding mode
-
setBindingMode
public void setBindingMode(RestConfiguration.RestBindingMode bindingMode)
Sets the binding mode to be used by the REST consumer- Parameters:
bindingMode- the binding mode
-
setBindingMode
public void setBindingMode(String bindingMode)
Sets the binding mode to be used by the REST consumer- Parameters:
bindingMode- the binding mode
-
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()
-
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.
-
isEnableCORS
public boolean isEnableCORS()
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- 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
-
isInlineRoutes
public boolean isInlineRoutes()
-
setInlineRoutes
public void setInlineRoutes(boolean inlineRoutes)
Inline routes in rest-dsl which are linked using direct endpoints. By default, 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). Enabling this allows Camel to optimize and inline this as a single route, however this requires to use direct endpoints, which must be unique per service. This option is default false.
-
getJsonDataFormat
public String 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
public void setJsonDataFormat(String name)
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
public String 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
public void setXmlDataFormat(String name)
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
public Map<String,Object> getComponentProperties()
Gets additional options on component level- Returns:
- additional options
-
setComponentProperties
public void setComponentProperties(Map<String,Object> componentProperties)
Sets additional options on component level- Parameters:
componentProperties- the options
-
getEndpointProperties
public Map<String,Object> getEndpointProperties()
Gets additional options on endpoint level- Returns:
- additional options
-
setEndpointProperties
public void setEndpointProperties(Map<String,Object> endpointProperties)
Sets additional options on endpoint level- Parameters:
endpointProperties- the options
-
getConsumerProperties
public Map<String,Object> getConsumerProperties()
Gets additional options on consumer level- Returns:
- additional options
-
setConsumerProperties
public void setConsumerProperties(Map<String,Object> consumerProperties)
Sets additional options on consumer level- Parameters:
consumerProperties- the options
-
getDataFormatProperties
public Map<String,Object> getDataFormatProperties()
Gets additional options on data format level- Returns:
- additional options
-
setDataFormatProperties
public void setDataFormatProperties(Map<String,Object> dataFormatProperties)
Sets additional options on data format level- Parameters:
dataFormatProperties- the options
-
setApiProperties
public void setApiProperties(Map<String,Object> apiProperties)
Sets additional options on api level- Parameters:
apiProperties- the options
-
getCorsHeaders
public Map<String,String> getCorsHeaders()
Gets the CORS headers to use if CORS has been enabled.- Returns:
- the CORS headers
-
-