Smile Camel HTTP Endpoint

 

Smile provides a configurable Camel HTTP Endpoint for receiving calls to URLs and passing those requests to Camel routes.

Configuration

 

The Camel HTTP Endpoint module must be configured with a set of mappings to control how incoming HTTP requests are connected to Camel routes. The configuration takes the form of a JSON document.

{
	"mappings": [
		{
			"name": "myReadMapping",
			"path": "/myRelativePath",
			"methods": ["GET"],
			"targetRoute": "direct:camelReadRoute",
			"headers": ["accept", "accept-encoding", "pragma", "cache-control"]
		},
		{
			"name": "myWriteMapping",
			"path": "/myRelativePath",
			"methods": ["PUT", "POST"],
			"targetRoute": "direct:camelWriteRoute",
			"headers": ["content-type", "content-length", "CamelHttpMethod"]
		}
	]
}

Assuming that the endpoint module is configured to listen on port 8004, an HTTP request to GET https://myhost.com:8004/myRelativePath will be passed to the Camel route consuming from the URI default:camelReadRoute. If multiple mappings in the configuration match the incoming request, the one that occurs first in the document will be given priority.

If a mapping configuration is not provided, all requests on https://myhost.com:8004/ will be passed to the Camel route consuming from the URI direct:camel-http-endpoint.

Configuration Parameters

Each mapping can specify the following parameters.

ParameterUse
nameAn optional name for the mapping. This name will be used in the permissions to restrict access to this mapping to certain users.
pathThe relative URL path that matches this mapping. This parameter uses Ant path format.
methodsThe HTTP methods accepted by this mapping. If this parameter is not specified, all HTTP methods will be accepted on this mapping.
targetRouteThe URI that the target Camel route consumes from.
headersThe HTTP headers that will be copied into the Camel Exchange. If this parameter is not specified, all available headers will be included in the exchange.

Data Transfer

 

The endpoint will copy the body of the HTTP request to the body of the Camel exchange message.

By default, the endpoint will copy all headers from the HTTP request as headers of the Camel exchange message, except for the Authorization header. The following special headers will also be populated.

HeaderContentsExample value
CamelHttpProtocolVersionThe version of the http protocol used.HTTP/1.1
CamelHttpMethodThe http method of the request.GET
CamelHttpCharacterEncodingThe character encoding of the request.UTF-8
CamelHttpUriThe relative URI of the request./myPath
CamelHttpQueryThe query parameters of the request.param=value
CamelHttpPathThe absolute path of the request. This includes both the URI and the query.https://myhost.com:8004/myPath?param=value

The headers parameter of the mapping configuration can be used to restrict which headers will be copied.

One of the following properties will be populated on the Camel exchange, providing the details of how the request was authenticated.

PropertyData TypeDescription
ca.cdr.camel.property.usersession.objectca.cdr.api.model.json.UserSessionDetailsJsonThe details of a user session.
ca.cdr.camel.property.clientsession.objectca.cdr.api.model.json.OAuth2ClientDetailsJsonThe details of a client session.

Once the Camel route has completed execution, the body and headers will be copied from the Camel exchange to the HTTP response. The value of the header CamelHttpResponseCode will be used as the HTTP response code. If this header is not present, the default response code will be 200 OK.

Permissions

 

In order to access the Camel HTTP Endpoint, a user must be granted one of the following permissions.