Package org.apache.camel.model.rest
Class RestDefinition
- java.lang.Object
-
- org.apache.camel.model.OptionalIdentifiedDefinition<RestDefinition>
-
- org.apache.camel.model.rest.RestDefinition
-
- All Implemented Interfaces:
org.apache.camel.CamelContextAware
,org.apache.camel.LineNumberAware
,org.apache.camel.NamedNode
,org.apache.camel.spi.HasId
,org.apache.camel.spi.IdAware
@Metadata(label="rest") public class RestDefinition extends OptionalIdentifiedDefinition<RestDefinition>
Defines a rest service using the rest-dsl
-
-
Constructor Summary
Constructors Constructor Description RestDefinition()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description RestDefinition
apiDocs(Boolean apiDocs)
Include or exclude the current Rest Definition in API documentation.static RouteDefinition
asRouteApiDefinition(org.apache.camel.CamelContext camelContext, org.apache.camel.spi.RestConfiguration configuration)
Transforms the rest api configuration into aRouteDefinition
which Camel routing engine uses to service the rest api docs.List<RouteDefinition>
asRouteDefinition(org.apache.camel.CamelContext camelContext)
Transforms this REST definition into a list ofRouteDefinition
which Camel routing engine can add and run.protected String
asTypeName(Class<?> classType)
RestDefinition
bindingMode(String mode)
RestDefinition
bindingMode(RestBindingMode mode)
String
buildFromUri(VerbDefinition verb)
Build the from endpoint uri for the verbRestDefinition
clientRequestValidation(boolean clientRequestValidation)
RestDefinition
consumes(String mediaType)
RestDefinition
delete()
RestDefinition
delete(String uri)
RestDefinition
deprecated()
RestDefinition
description(String text)
Sets the description of this nodeRestDefinition
description(String id, String text, String lang)
Sets the description of this nodeRestDefinition
disabled()
Disables this REST service from the route during build time.RestDefinition
disabled(boolean disabled)
Whether to disable this REST service from the route during build time.RestDefinition
disabled(String disabled)
Whether to disable this REST service from the route during build time.RestDefinition
enableCORS(boolean enableCORS)
RestDefinition
get()
RestDefinition
get(String uri)
String
getApiDocs()
String
getBindingMode()
String
getClientRequestValidation()
String
getConsumes()
String
getDisabled()
String
getEnableCORS()
String
getLabel()
String
getPath()
String
getProduces()
RestSecuritiesDefinition
getSecurityDefinitions()
List<SecurityDefinition>
getSecurityRequirements()
String
getShortName()
String
getSkipBindingOnErrorCode()
String
getTag()
List<VerbDefinition>
getVerbs()
RestDefinition
head()
RestDefinition
head(String uri)
RestDefinition
id(String id)
Sets the id of this node.RestDefinition
outType(Class<?> classType)
ParamDefinition
param()
RestDefinition
param(ParamDefinition param)
ParamDefinition
param(VerbDefinition verb)
RestDefinition
params(List<ParamDefinition> params)
RestDefinition
patch()
RestDefinition
patch(String uri)
RestDefinition
path(String path)
To set the base path of this REST serviceRestDefinition
post()
RestDefinition
post(String uri)
RestDefinition
produces(String mediaType)
RestDefinition
put()
RestDefinition
put(String uri)
ResponseMessageDefinition
responseMessage()
RestDefinition
responseMessage(int code, String message)
RestDefinition
responseMessage(String code, String message)
RestDefinition
responseMessage(ResponseMessageDefinition msg)
ResponseMessageDefinition
responseMessage(VerbDefinition verb)
RestDefinition
responseMessages(List<ResponseMessageDefinition> msgs)
RestDefinition
routeId(String routeId)
RestDefinition
security(String key)
Sets the security setting for this verb.RestDefinition
security(String key, String scopes)
Sets the security setting for this verb.RestSecuritiesDefinition
securityDefinitions()
To configure security definitions.void
setApiDocs(String apiDocs)
Whether to include or exclude this rest operation in API documentation.void
setBindingMode(String bindingMode)
Sets the binding mode to use.void
setClientRequestValidation(String 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
setConsumes(String consumes)
To define the content type what the REST service consumes (accept as input), such as application/xml or application/json.void
setDisabled(String disabled)
Whether to disable this REST service from the route during build time.void
setEnableCORS(String enableCORS)
Whether to enable CORS headers in the HTTP response.void
setPath(String path)
Path of the rest service, such as "/foo"void
setProduces(String produces)
To define the content type what the REST service produces (uses for output), such as application/xml or application/json This option will override what may be configured on a parent levelvoid
setSecurityDefinitions(RestSecuritiesDefinition securityDefinitions)
Sets the security definitions such as Basic, OAuth2 etc.void
setSecurityRequirements(List<SecurityDefinition> securityRequirements)
Sets the security requirement(s) for all endpoints.void
setSkipBindingOnErrorCode(String skipBindingOnErrorCode)
Whether to skip binding on output if there is a custom HTTP error code header.void
setTag(String tag)
To configure a special tag for the operations within this rest definition.void
setVerbs(List<VerbDefinition> verbs)
The HTTP verbs this REST service accepts and usesRestDefinition
skipBindingOnErrorCode(boolean skipBindingOnErrorCode)
RestDefinition
tag(String tag)
To set the tag to use of this REST serviceRestDefinition
to(String uri)
The Camel endpoint this REST service will call, such as a direct endpoint to link to an existing route that handles this REST call.RestDefinition
type(Class<?> classType)
protected void
validateUniqueDirects(List<VerbDefinition> verbs)
protected void
validateUniquePaths(List<VerbDefinition> verbs)
RestDefinition
verb(String verb)
RestDefinition
verb(String verb, String uri)
-
Methods inherited from class org.apache.camel.model.OptionalIdentifiedDefinition
getCamelContext, getCustomId, getDescription, getDescriptionText, getId, getLineNumber, getLocation, getParent, hasCustomIdAssigned, idOrCreate, setCamelContext, setCustomId, setDescription, setGeneratedId, setId, setLineNumber, setLocation
-
-
-
-
Method Detail
-
getShortName
public String getShortName()
-
getLabel
public String getLabel()
-
getPath
public String getPath()
-
setPath
public void setPath(String path)
Path of the rest service, such as "/foo"
-
getTag
public String getTag()
-
setTag
public void setTag(String tag)
To configure a special tag for the operations within this rest definition.
-
getConsumes
public String getConsumes()
-
setConsumes
public void setConsumes(String consumes)
To define the content type what the REST service consumes (accept as input), such as application/xml or application/json. This option will override what may be configured on a parent level
-
getProduces
public String getProduces()
-
setProduces
public void setProduces(String produces)
To define the content type what the REST service produces (uses for output), such as application/xml or application/json This option will override what may be configured on a parent level
-
getDisabled
public String getDisabled()
-
setDisabled
public void setDisabled(String disabled)
Whether to disable this REST service from the route during build time. Once an REST service has been disabled then it cannot be enabled later at runtime.
-
getBindingMode
public String getBindingMode()
-
setBindingMode
public void setBindingMode(String bindingMode)
Sets the binding mode to use. This option will override what may be configured on a parent level The default value is auto
-
getVerbs
public List<VerbDefinition> getVerbs()
-
getSecurityDefinitions
public RestSecuritiesDefinition getSecurityDefinitions()
-
setSecurityDefinitions
public void setSecurityDefinitions(RestSecuritiesDefinition securityDefinitions)
Sets the security definitions such as Basic, OAuth2 etc.
-
getSecurityRequirements
public List<SecurityDefinition> getSecurityRequirements()
-
setSecurityRequirements
public void setSecurityRequirements(List<SecurityDefinition> securityRequirements)
Sets the security requirement(s) for all endpoints.
-
setVerbs
public void setVerbs(List<VerbDefinition> verbs)
The HTTP verbs this REST service accepts and uses
-
getSkipBindingOnErrorCode
public String getSkipBindingOnErrorCode()
-
setSkipBindingOnErrorCode
public void setSkipBindingOnErrorCode(String 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. This option will override what may be configured on a parent level
-
getClientRequestValidation
public String getClientRequestValidation()
-
setClientRequestValidation
public void setClientRequestValidation(String 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 String getEnableCORS()
-
setEnableCORS
public void setEnableCORS(String enableCORS)
Whether to enable CORS headers in the HTTP response. This option will override what may be configured on a parent level The default value is false.
-
getApiDocs
public String getApiDocs()
-
setApiDocs
public void setApiDocs(String apiDocs)
Whether to include or exclude this rest operation in API documentation. This option will override what may be configured on a parent level. The default value is true.
-
path
public RestDefinition path(String path)
To set the base path of this REST service
-
disabled
public RestDefinition disabled()
Disables this REST service from the route during build time. Once an REST service has been disabled then it cannot be enabled later at runtime.
-
disabled
public RestDefinition disabled(boolean disabled)
Whether to disable this REST service from the route during build time. Once an REST service has been disabled then it cannot be enabled later at runtime.
-
disabled
public RestDefinition disabled(String disabled)
Whether to disable this REST service from the route during build time. Once an REST service has been disabled then it cannot be enabled later at runtime.
-
tag
public RestDefinition tag(String tag)
To set the tag to use of this REST service
-
get
public RestDefinition get()
-
get
public RestDefinition get(String uri)
-
post
public RestDefinition post()
-
post
public RestDefinition post(String uri)
-
put
public RestDefinition put()
-
put
public RestDefinition put(String uri)
-
patch
public RestDefinition patch()
-
patch
public RestDefinition patch(String uri)
-
delete
public RestDefinition delete()
-
delete
public RestDefinition delete(String uri)
-
head
public RestDefinition head()
-
head
public RestDefinition head(String uri)
-
verb
public RestDefinition verb(String verb)
-
verb
public RestDefinition verb(String verb, String uri)
-
id
public RestDefinition id(String id)
Description copied from class:OptionalIdentifiedDefinition
Sets the id of this node. Important: If you want to set the id of the route, then you must use routeId(String) instead.- Overrides:
id
in classOptionalIdentifiedDefinition<RestDefinition>
- Parameters:
id
- the id- Returns:
- the builder
-
routeId
public RestDefinition routeId(String routeId)
-
deprecated
public RestDefinition deprecated()
-
description
public RestDefinition description(String text)
Description copied from class:OptionalIdentifiedDefinition
Sets the description of this node- Overrides:
description
in classOptionalIdentifiedDefinition<RestDefinition>
- Parameters:
text
- sets the text description, use null to not set a text- Returns:
- the builder
-
description
public RestDefinition description(String id, String text, String lang)
Description copied from class:OptionalIdentifiedDefinition
Sets the description of this node- Overrides:
description
in classOptionalIdentifiedDefinition<RestDefinition>
- Parameters:
id
- sets the id, use null to not set an idtext
- sets the text description, use null to not set a textlang
- sets the language for the description, use null to not set a language- Returns:
- the builder
-
consumes
public RestDefinition consumes(String mediaType)
-
param
public ParamDefinition param()
-
param
public RestDefinition param(ParamDefinition param)
-
params
public RestDefinition params(List<ParamDefinition> params)
-
param
public ParamDefinition param(VerbDefinition verb)
-
responseMessage
public RestDefinition responseMessage(ResponseMessageDefinition msg)
-
responseMessage
public ResponseMessageDefinition responseMessage()
-
responseMessage
public ResponseMessageDefinition responseMessage(VerbDefinition verb)
-
responseMessages
public RestDefinition responseMessages(List<ResponseMessageDefinition> msgs)
-
responseMessage
public RestDefinition responseMessage(int code, String message)
-
responseMessage
public RestDefinition responseMessage(String code, String message)
-
securityDefinitions
public RestSecuritiesDefinition securityDefinitions()
To configure security definitions.
-
produces
public RestDefinition produces(String mediaType)
-
type
public RestDefinition type(Class<?> classType)
-
outType
public RestDefinition outType(Class<?> classType)
-
bindingMode
public RestDefinition bindingMode(RestBindingMode mode)
-
bindingMode
public RestDefinition bindingMode(String mode)
-
skipBindingOnErrorCode
public RestDefinition skipBindingOnErrorCode(boolean skipBindingOnErrorCode)
-
clientRequestValidation
public RestDefinition clientRequestValidation(boolean clientRequestValidation)
-
enableCORS
public RestDefinition enableCORS(boolean enableCORS)
-
apiDocs
public RestDefinition apiDocs(Boolean apiDocs)
Include or exclude the current Rest Definition in API documentation. The default value is true.
-
security
public RestDefinition security(String key)
Sets the security setting for this verb.
-
security
public RestDefinition security(String key, String scopes)
Sets the security setting for this verb.
-
to
public RestDefinition to(String uri)
The Camel endpoint this REST service will call, such as a direct endpoint to link to an existing route that handles this REST call.- Parameters:
uri
- the uri of the endpoint- Returns:
- this builder
-
buildFromUri
public String buildFromUri(VerbDefinition verb)
Build the from endpoint uri for the verb
-
asRouteDefinition
public List<RouteDefinition> asRouteDefinition(org.apache.camel.CamelContext camelContext)
Transforms this REST definition into a list ofRouteDefinition
which Camel routing engine can add and run. This allows us to define REST services using this REST DSL and turn those into regular Camel routes.- Parameters:
camelContext
- The Camel context
-
validateUniquePaths
protected void validateUniquePaths(List<VerbDefinition> verbs)
-
validateUniqueDirects
protected void validateUniqueDirects(List<VerbDefinition> verbs)
-
asRouteApiDefinition
public static RouteDefinition asRouteApiDefinition(org.apache.camel.CamelContext camelContext, org.apache.camel.spi.RestConfiguration configuration)
Transforms the rest api configuration into aRouteDefinition
which Camel routing engine uses to service the rest api docs.
-
-