Package org.apache.camel.spi
Class RestConfiguration
- java.lang.Object
-
- org.apache.camel.spi.RestConfiguration
-
public class RestConfiguration extends Object
Configuration use byRestConsumerFactory
andRestApiConsumerFactory
for Camel components to support the Camelrest
DSL.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
RestConfiguration.RestBindingMode
static class
RestConfiguration.RestHostNameResolver
-
Field Summary
Fields Modifier and Type Field Description static String
CORS_ACCESS_CONTROL_ALLOW_HEADERS
static String
CORS_ACCESS_CONTROL_ALLOW_METHODS
static String
CORS_ACCESS_CONTROL_ALLOW_ORIGIN
static String
CORS_ACCESS_CONTROL_MAX_AGE
static String
DEFAULT_REST_CONFIGURATION_ID
-
Constructor Summary
Constructors Constructor Description RestConfiguration()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description String
getApiComponent()
Gets the name of the Camel component to use as the REST API (such as swagger or openapi).String
getApiContextIdPattern()
Deprecated.String
getApiContextPath()
String
getApiContextRouteId()
String
getApiHost()
Map<String,Object>
getApiProperties()
RestConfiguration.RestBindingMode
getBindingMode()
Gets the binding mode used by the REST consumerString
getComponent()
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 levelString
getContextPath()
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 levelString
getHost()
Gets the hostname to use by the REST consumerRestConfiguration.RestHostNameResolver
getHostNameResolver()
Gets the resolver to use for resolving hostnameString
getJsonDataFormat()
Gets the name of the json data format.int
getPort()
Gets the port to use by the REST consumerString
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.String
getProducerComponent()
Gets the name of the Camel component to use as the REST producerString
getScheme()
Gets the scheme to use by the REST consumerString
getXmlDataFormat()
Gets the name of the xml data format.boolean
isApiContextListing()
Deprecated.boolean
isApiVendorExtension()
boolean
isClientRequestValidation()
boolean
isEnableCORS()
To specify whether to enable CORS which means Camel will automatic include CORS in the HTTP headers in the response.boolean
isSkipBindingOnErrorCode()
Whether to skip binding output if there is a custom HTTP error code, and instead use the response body as-is.boolean
isUseXForwardHeaders()
Whether to use X-Forward headers to set host etc.void
setApiComponent(String apiComponent)
Sets the name of the Camel component to use as the REST API (such as swagger or openapi)void
setApiContextIdPattern(String apiContextIdPattern)
Deprecated.void
setApiContextListing(boolean apiContextListing)
Deprecated.void
setApiContextPath(String contextPath)
Sets a leading API context-path the REST API services will be using.void
setApiContextRouteId(String apiContextRouteId)
Sets the route id to use for the route that services the REST API.void
setApiHost(String apiHost)
To use a specific hostname for the API documentation (such as swagger or openapi)void
setApiProperties(Map<String,Object> apiProperties)
Sets additional options on api levelvoid
setApiVendorExtension(boolean apiVendorExtension)
Whether vendor extension is enabled in the Rest APIs.void
setBindingMode(String bindingMode)
Sets the binding mode to be used by the REST consumervoid
setBindingMode(RestConfiguration.RestBindingMode bindingMode)
Sets the binding mode to be used by the REST consumervoid
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 componentName)
Sets the name of the Camel component to use as the REST consumervoid
setComponentProperties(Map<String,Object> componentProperties)
Sets additional options on component levelvoid
setConsumerProperties(Map<String,Object> consumerProperties)
Sets additional options on consumer levelvoid
setContextPath(String contextPath)
Sets a leading context-path the REST services will be using.void
setCorsHeaders(Map<String,String> corsHeaders)
Sets the CORS headers to use if CORS has been enabled.void
setDataFormatProperties(Map<String,Object> dataFormatProperties)
Sets additional options on data format levelvoid
setEnableCORS(boolean enableCORS)
To specify whether to enable CORS which means Camel will automatic include CORS in the HTTP headers in the response.void
setEndpointProperties(Map<String,Object> endpointProperties)
Sets additional options on endpoint levelvoid
setHost(String host)
Sets the hostname to use by the REST consumervoid
setHostNameResolver(String hostNameResolver)
Sets the resolver to use for resolving hostnamevoid
setHostNameResolver(RestConfiguration.RestHostNameResolver hostNameResolver)
Sets the resolver to use for resolving hostnamevoid
setJsonDataFormat(String name)
Sets a custom json data format to be usedvoid
setPort(int port)
Sets the port to use by the REST consumervoid
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.void
setProducerComponent(String componentName)
Sets the name of the Camel component to use as the REST producervoid
setScheme(String scheme)
Sets the scheme to use by the REST consumervoid
setSkipBindingOnErrorCode(boolean skipBindingOnErrorCode)
Whether to skip binding output if there is a custom HTTP error code, and instead use the response body as-is.void
setUseXForwardHeaders(boolean useXForwardHeaders)
Whether to use X-Forward headers to set host etc.void
setXmlDataFormat(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
Registry
to 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
Registry
to 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-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
-
getApiContextIdPattern
@Deprecated public String getApiContextIdPattern()
Deprecated.
-
setApiContextIdPattern
@Deprecated public void setApiContextIdPattern(String apiContextIdPattern)
Deprecated.Optional CamelContext id pattern to only allow Rest APIs from rest services within CamelContext's which name matches the pattern. The pattern #name# refers to the CamelContext name, to match on the current CamelContext only. For any other value, the pattern uses the rules fromorg.apache.camel.support.EndpointHelper#matchPattern(String, String)
- Parameters:
apiContextIdPattern
- the pattern
-
isApiContextListing
@Deprecated public boolean isApiContextListing()
Deprecated.
-
setApiContextListing
@Deprecated public void setApiContextListing(boolean apiContextListing)
Deprecated.Sets whether listing of all available CamelContext's with REST services in the JVM is enabled. If enabled it allows to discover these contexts, if false then only the current CamelContext is in use.
-
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
-
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
-
-