Camel Components

Platform HTTP

Since Camel 3.0

Only consumer is supported

The Platform HTTP is used to allow Camel to use the existing HTTP server from the runtime. For example, when running Camel on Spring Boot, Quarkus, or other runtimes.

Maven users will need to add the following dependency to their pom.xml for this component:

<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-platform-http</artifactId>
    <version>x.x.x</version>
    <!-- use the same version as your Camel core version -->
</dependency>

Configuring Options

Camel components are configured on two separate levels:

  • component level

  • endpoint level

Configuring Component Options

At the component level, you set general and shared configurations that are, then, inherited by the endpoints. It is the highest configuration level.

For example, a component may have security settings, credentials for authentication, urls for network connection and so forth.

Some components only have a few options, and others may have many. Because components typically have pre-configured defaults that are commonly used, then you may often only need to configure a few options on a component; or none at all.

You can configure components using:

  • the Component DSL.

  • in a configuration file (application.properties, *.yaml files, etc).

  • directly in the Java code.

Configuring Endpoint Options

You usually spend more time setting up endpoints because they have many options. These options help you customize what you want the endpoint to do. The options are also categorized into whether the endpoint is used as a consumer (from), as a producer (to), or both.

Configuring endpoints is most often done directly in the endpoint URI as path and query parameters. You can also use the Endpoint DSL and DataFormat DSL as a type safe way of configuring endpoints and data formats in Java.

A good practice when configuring options is to use Property Placeholders.

Property placeholders provide a few benefits:

  • They help prevent using hardcoded urls, port numbers, sensitive information, and other settings.

  • They allow externalizing the configuration from the code.

  • They help the code to become more flexible and reusable.

The following two sections list all the options, firstly for the component followed by the endpoint.

Component Options

The Platform HTTP component supports the following options which are listed below.

Name Description Default Type

bridgeErrorHandler (consumer)

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. Important: This is only possible if the 3rd party component allows Camel to be alerted if an exception was thrown. Some components handle this internally only, and therefore bridgeErrorHandler is not possible. In other situations we may improve the Camel component to hook into the 3rd party component and make this possible for future releases. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

boolean

handleWriteResponseError (consumer)

Whether a failure of the HTTP server while it writes the response (such as the client closing the connection) is set as the exception of the exchange, so that onCompletion and the unit of work see the exchange as failed and can access the exception, as the default for the endpoints of this component. When false, the exchange completes without the exception.

false

boolean

requestTimeout (consumer)

The time in milliseconds after which a request that has no response yet is answered with HTTP status 503 (Service Unavailable), as the default for the endpoints of this component. The route is not stopped, and its reply is discarded. 0 (the default) means no timeout. (currently only supported by camel-platform-http-vertx).

long

serverRequestValidation (consumer)

Whether HTTP server should do preliminary validation of incoming requests, validating if Content-Type/Accept header, matches what is allowed according to consumes/produces configuration (if set). If validation fails HTTP Status 415/406 is returned. The HTTP server performs this validation before Camel is involved, and as such if validation fails then Camel is never activated. Setting this option to false, allows Camel to process any incoming requests such as to do custom validation or all requests must be handled by Camel.

true

boolean

synchronous (consumer)

Whether the consumers route each request synchronously, as the default for the endpoints of this component. When true, the route runs on a thread of the Vert.x worker pool, which waits until the route is complete, so the size of the worker pool limits how many requests are routed at the same time. When false, the worker thread is free as soon as the route continues on another thread (such as an asynchronous producer). See the synchronous endpoint option. (currently only supported by camel-platform-http-vertx).

false

boolean

autowiredEnabled (advanced)

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

boolean

engine (advanced)

The PlatformHttpEngine (the HTTP server implementation) that serves the requests of the endpoints. When not set, the bean named platform-http-engine in the registry is used, or else the engine found on the classpath, such as camel-platform-http-vertx.

PlatformHttpEngine

headerFilterStrategy (filter)

To use a custom org.apache.camel.spi.HeaderFilterStrategy to filter header to and from Camel message.

HeaderFilterStrategy

Endpoint Options

The Platform HTTP endpoint is configured using URI syntax:

platform-http:path

With the following path and query parameters:

Path Parameters

Name Description Default Type

path (consumer)

Required The path under which this endpoint serves the HTTP requests, such as /orders/{id}, where a {name} segment is a path parameter whose value becomes a message header. The path proxy makes this endpoint a forward proxy that serves the requests for any host, and sets the CamelHttpHost header from the Host header of the request (currently only supported by camel-platform-http-vertx).

String

Query Parameters

Name Description Default Type

consumes (consumer)

A comma separated list of the content types that this endpoint accepts in the Content-Type header of the request, such as application/json. With serverRequestValidation enabled on the component (the default), the HTTP server answers a request with another content type with HTTP status 415 (Unsupported Media Type) before the route is called. When not set, or set to */*, any content type is accepted.

String

cookieDomain (consumer)

The Domain attribute of the cookies that the route adds with the cookie handler: the browser sends such a cookie to this domain and its subdomains. When not set, the cookie has no Domain attribute, and the browser sends it only to the host that set it.

String

cookieHttpOnly (consumer)

Whether the cookies that the route adds with the cookie handler have the HttpOnly attribute, so that scripts in the browser (such as JavaScript document.cookie) cannot read them.

false

boolean

cookieMaxAge (consumer)

The Max-Age attribute of the cookies that the route adds with the cookie handler: the number of seconds that the browser keeps the cookie; 0 or a negative value expires it at once. When not set, the cookie is a session cookie, which the browser removes when it closes.

Long

cookiePath (consumer)

The Path attribute of the cookies that the route adds with the cookie handler: the browser sends such a cookie only with requests to this path or a path below it.

/

String

cookieSameSite (consumer)

The SameSite attribute of the cookies that the route adds with the cookie handler: STRICT sends such a cookie only with requests from the same site, LAX also when the user navigates to the site from another site (such as following a link), and NONE with all cross-site requests (browsers accept NONE only together with cookieSecure=true).

Enum values:

  • STRICT

  • LAX

  • NONE

LAX

CookieSameSite

cookieSecure (consumer)

Whether the cookies that the route adds with the cookie handler have the Secure attribute, so that the browser sends them only over HTTPS.

false

boolean

handleWriteResponseError (consumer)

Whether a failure of the HTTP server while it writes the response (such as the client closing the connection) is set as the exception of the exchange, so that onCompletion and the unit of work see the exchange as failed and can access the exception. When false, the exchange completes without the exception.

false

boolean

httpMethodRestrict (consumer)

A comma separated list of the HTTP methods that this endpoint serves, such as GET,POST. When not set, all methods are served.

String

matchOnUriPrefix (consumer)

Whether this endpoint also serves the requests whose path starts with the path of this endpoint, such as /foo/bar for the path /foo. With camel-platform-http-vertx the HTTP server matches the endpoints in the order they started, so a prefix endpoint started before an endpoint with a longer path also receives the requests of that path.

false

boolean

muteException (consumer)

Whether to leave the stack trace out of the response when the exchange failed with an exception: when true the error response has an empty body, when false its body is the stack trace of the exception as text/plain.

true

boolean

populateBodyWithForm (consumer)

Whether to set the message body to a Map of the form fields of an application/x-www-form-urlencoded or multipart/form-data request. The form fields become message headers whether or not this is set. Has no effect when useBodyHandler is false.

true

boolean

produces (consumer)

A comma separated list of the content types that this endpoint produces, such as application/json. With serverRequestValidation enabled on the component (the default), the HTTP server answers a request whose Accept header accepts none of them with HTTP status 406 (Not Acceptable) before the route is called. It does not set the Content-Type of the response.

String

requestTimeout (consumer)

The time in milliseconds after which a request that has no response yet is answered with HTTP status 503 (Service Unavailable). The route is not stopped, and its reply is discarded. 0 (the default) means no timeout. (currently only supported by camel-platform-http-vertx).

long

returnHttpRequestHeaders (consumer)

Whether to copy the common HTTP request headers (such as Accept, Authorization, Cookie, Host and User-Agent) to the HTTP response when they are still message headers at the end of the route. When false, these headers are left out of the response; the other message headers are copied as the header filter strategy allows.

false

boolean

stripUriPrefix (consumer)

Whether to remove the path of this endpoint from the start of the CamelHttpPath header, so the route sees the request path relative to this endpoint (/ for an exact match). For example, with platform-http:/reverse-proxy?matchOnUriPrefix=true a request to /reverse-proxy/get has the CamelHttpPath /get, and an http producer with bridgeEndpoint=true forwards it to http://backend/get. The CamelHttpUri and CamelHttpUrl headers keep the full request path. (currently only supported by camel-platform-http-vertx).

false

boolean

synchronous (consumer)

Whether the consumer routes each request synchronously. When true, the route runs on a thread of the Vert.x worker pool, which waits until the route is complete, so the size of the worker pool limits how many requests are routed at the same time. When false, the route starts on a worker thread with the asynchronous routing engine, and the worker thread is free as soon as the route continues on another thread (such as an asynchronous producer), so the worker pool no longer limits the requests in flight. Keep it false for a route that calls an asynchronous producer using the same Vert.x as the HTTP server (such as vertx-http in Camel Quarkus): with true, such requests can occupy every worker thread while their producers need a worker thread to complete, and then no request completes. (currently only supported by camel-platform-http-vertx).

false

boolean

useBodyHandler (consumer)

Whether the HTTP server reads the request body before the route is called, keeping it in memory and parsing form fields and file uploads. When false, the body is not read: with camel-platform-http-vertx the message body is the paused Vert.x HttpServerRequest, which the route reads itself, and the form fields and file uploads are not parsed.

true

boolean

useCookieHandler (consumer)

Whether to set a CookieHandler as the exchange property CamelCookieHandler, with which the route reads the cookies of the request, adds cookies to the response (with the attributes of the cookie options) and expires cookies. (currently only supported by camel-platform-http-vertx).

false

boolean

useStreaming (consumer)

Whether to read the request body as a stream, so a large body is not held in memory as one buffer: the body is copied into a stream cache as it arrives (spooled to disk when stream caching spooling is enabled), and the message body is an InputStream. A multipart/form-data request then fails. A response body that is an InputStream is streamed whether or not this is set. (currently only supported by camel-platform-http-vertx).

false

boolean

bridgeErrorHandler (consumer (advanced))

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. Important: This is only possible if the 3rd party component allows Camel to be alerted if an exception was thrown. Some components handle this internally only, and therefore bridgeErrorHandler is not possible. In other situations we may improve the Camel component to hook into the 3rd party component and make this possible for future releases. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

boolean

exceptionHandler (consumer (advanced))

To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this option is not in use. By default the consumer will deal with exceptions, that will be logged at WARN or ERROR level and ignored.

ExceptionHandler

exchangePattern (consumer (advanced))

Sets the exchange pattern when the consumer creates an exchange.

Enum values:

  • InOnly

  • InOut

ExchangePattern

fileNameExtWhitelist (consumer (advanced))

A comma separated list of the file extensions (compared without regard to case) of the multipart/form-data file uploads that become attachments of the message (and the message body for a single upload); an upload with another extension is left out. The extension is the part of the file name after its first dot, such as tar.gz. When not set, or set to *, all uploads are accepted.

String

unmatchedRequestHandling (consumer (advanced))

Who answers requests that match no registered operation when using rest-dsl contract-first (such as the rest-openapi component): the HTTP layer (platform) or Camel via the route (camel). When set to camel, a catch-all is registered so unmatched requests are routed to Camel. Currently supported by camel-platform-http-vertx (Camel Main, Quarkus) and the Spring Boot platform-http-starter.

Enum values:

  • platform

  • camel

platform

String

headerFilterStrategy (advanced)

To use a custom HeaderFilterStrategy to filter headers to and from Camel message.

HeaderFilterStrategy

platformHttpEngine (advanced)

The PlatformHttpEngine (the HTTP server implementation) that serves the requests of this endpoint, instead of the engine of the component.

PlatformHttpEngine

oauthProfile (security)

OAuth profile name for validating incoming Authorization: Bearer tokens. When set, the request is authenticated before the route is processed: a request without a valid token is answered with HTTP status 401 (400 for a malformed Authorization header) and the route is not called. For an authenticated request the Authorization header is removed, and the validation result is the exchange property CamelOAuthTokenValidationResult. This requires an OAuthTokenValidationFactory; camel-oauth provides the default implementation.

String

Message Headers

The Platform HTTP component supports the following message header(s), which is/are listed below:

Name Description Default Type

CamelHttpMethod (consumer)

Constant: HTTP_METHOD

The HTTP method of the request, such as GET or POST.

String

CamelHttpPath (consumer)

Constant: HTTP_PATH

The path of the request, such as /orders/42. With stripUriPrefix, the part of the path after the path of the endpoint.

String

CamelHttpUri (consumer)

Constant: HTTP_URI

The URI of the request, without the scheme, host and port.

String

CamelHttpUrl (consumer)

Constant: HTTP_URL

The URL of the request, with the scheme, host and port.

String

CamelHttpQuery (consumer)

Constant: HTTP_QUERY

The query string of the request, such as foo=bar&beer=yes.

String

CamelHttpRawQuery (consumer)

Constant: HTTP_RAW_QUERY

The query string of the request in the raw form it arrived in, before URL decoding.

String

CamelHttpCharacterEncoding (consumer)

Constant: HTTP_CHARACTER_ENCODING

The charset that the Content-Type of the request declares, if any.

String

Content-Type (consumer)

Constant: CONTENT_TYPE

The Content-Type of the request body, and of the response body that the consumer sends.

String

CamelHttpResponseCode (consumer)

Constant: HTTP_RESPONSE_CODE

The HTTP status code of the response that the consumer sends. When it is not set, the status is 200, or 204 when the response has no body, or 500 when the exchange failed.

Integer

CamelAuthentication (consumer)

Constant: AUTHENTICATION

Set to Basic when the Authorization header of the request carries HTTP Basic credentials.

String

CamelHttpHost (consumer)

Constant: HTTP_HOST

With the platform-http:proxy forward proxy of the Vert.x engine, the value of the Host header of the request: the server that the request is for.

String

CamelAttachmentsSize (consumer)

Constant: ATTACHMENTS_SIZE

The number of files that a multipart/form-data request uploads.

Integer

CamelFileName (consumer)

Constant: FILE_NAME

The name of the uploaded file, without a path, when the request uploads one file. The body is then the file.

String

CamelFileContentType (consumer)

Constant: FILE_CONTENT_TYPE

The content type of the uploaded file, when the request uploads one file: from the extension of its name, or else the content type of the upload.

String

CamelFileLength (consumer)

Constant: FILE_LENGTH

The size in bytes of the uploaded file, when the request uploads one file.

Long

CamelFilePath (consumer)

Constant: FILE_PATH

With the Vert.x engine, the path of the local copy of the uploaded file, when the request uploads one file.

String

Message Body

The message body at each side of the Platform HTTP component: Consumer is the body of the messages the consumer creates, Consumer reply the bodies a consumer that answers its caller can reply with, Producer input the bodies the producer can send or write, and Producer output the body after the producer.

Side Body Description

Consumer

stream, bytes, null, map or file

The request body: the stream cache with the Vert.x engine, a byte array with Spring Boot; null for a request without a body, such as a GET; a Map of the fields of a form (populateBodyWithForm); a File for an upload.

  • With useBodyHandler=false: pojo

Consumer reply

null, text, bytes or stream

The response body: text, bytes, a stream or no body. A Map or a List fails: marshal it first.

The bodies are the ones with the default options. A side that is not listed is not known, and tooling does not guess it. The carriers, the sides and the tools that use them are described in Message Body Types.

Usage

Platform HTTP Provider

To use Platform HTTP, a provider (engine) is required to be available on the classpath. The purpose is to have drivers for different runtimes such as Quarkus, or Spring Boot.

With camel run, the provider is the embedded HTTP server of camel-platform-http-main, which starts when a route uses platform-http, on port 8080 (camel.server.port in application.properties or camel run --port changes it). With Camel Main, the embedded HTTP server is disabled by default: enable it in application.properties with camel.server.enabled=true and set camel.server.port. See Platform HTTP Main for the other camel.server.* options.

To use it with different runtimes:

  • Quarkus

  • Spring Boot

<dependency>
    <groupId>org.apache.camel.quarkus</groupId>
    <artifactId>camel-quarkus-platform-http</artifactId>
    <version>x.x.x</version>
    <!-- use the same version as your Camel Quarkus version -->
</dependency>
<dependency>
    <groupId>org.apache.camel.springboot</groupId>
    <artifactId>camel-platform-http-starter</artifactId>
    <version>x.x.x</version>
    <!-- use the same version as your Camel version -->
</dependency>

OAuth Bearer token validation

Platform HTTP consumers can validate incoming Authorization: Bearer tokens by setting the oauthProfile endpoint option. The profile is resolved through Camel’s OAuthTokenValidationFactory SPI. The camel-oauth component provides the default implementation for standalone Camel applications; runtimes such as Camel Spring Boot or Camel Quarkus can provide their own implementation backed by their native security stack.

<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-oauth</artifactId>
    <version>x.x.x</version>
</dependency>

If oauthProfile is set but no OAuthTokenValidationFactory is available on the classpath, the route fails to start. Add camel-oauth for the default provider or include a runtime-specific provider from the platform integration.

Camel first checks whether the selected profile has a profile-specific validation factory:

camel.oauth.myprofile.validation-factory=#bean:myTokenValidationFactory

If this property is set, the referenced bean must exist and implement OAuthTokenValidationFactory. Otherwise, Camel looks for a single OAuthTokenValidationFactory in the registry before falling back to the classpath provider.

  • Java

  • XML

  • YAML

from("platform-http:/secure?oauthProfile=myprofile")
    .to("direct:businessLogic");
<route>
  <from uri="platform-http:/secure?oauthProfile=myprofile"/>
  <to uri="direct:businessLogic"/>
</route>
- route:
    from:
      uri: platform-http:/secure
      parameters:
        oauthProfile: myprofile
      steps:
        - to:
            uri: direct:businessLogic
camel.oauth.myprofile.jwks-endpoint=https://idp.example.com/.well-known/jwks.json
camel.oauth.myprofile.expected-issuer=https://idp.example.com
camel.oauth.myprofile.expected-audience=my-api
camel.oauth.myprofile.connect-timeout-seconds=5
camel.oauth.myprofile.read-timeout-seconds=10

See camel-oauth for OIDC discovery and opaque-token introspection profile examples.

Opaque-token introspection performs a blocking outbound HTTP call for every request. For high-traffic endpoints, prefer JWT validation with JWKS when the identity provider publishes signing keys. See camel-oauth for timeout and validation profile options.

When oauthProfile is set, static profile configuration is resolved and validated at route startup. Updates to OAuth profile properties require restarting the route or Camel context before they take effect. Requests without a Bearer token or with an invalid token are rejected with HTTP 401 before the route is processed; missing credentials receive a WWW-Authenticate: Bearer response header and invalid tokens receive WWW-Authenticate: Bearer error="invalid_token", and tokens not meeting step-up requirements (see required-acr and max-auth-age-seconds in camel-oauth) receive WWW-Authenticate: Bearer error="insufficient_user_authentication". Malformed Authorization headers are rejected with HTTP 400 and WWW-Authenticate: Bearer error="invalid_request". Token validation infrastructure failures are rejected with HTTP 503. With the Vert.x platform-http engine, Bearer token validation runs before the request body handler, so unauthenticated requests are rejected before body buffering, form parsing, or file uploads. For valid tokens, the token validation result is stored on the exchange as the CamelOAuthTokenValidationResult exchange property. Route code can use the result to read the principal name, token scopes, and immutable token attributes/claims. The raw Authorization header is removed before the route is invoked and from OAuth rejection responses.

Java-only: accessing OAuth token validation result in a processor
import org.apache.camel.component.platform.http.PlatformHttpConstants;
import org.apache.camel.spi.OAuthTokenValidationResult;

from("platform-http:/secure?oauthProfile=myprofile")
    .process(exchange -> {
        OAuthTokenValidationResult result = exchange.getProperty(
                "CamelOAuthTokenValidationResult",
                OAuthTokenValidationResult.class);
        exchange.getMessage().setHeader("X-Principal", result.getName());
    });

Configure expected-issuer and expected-audience for production resource-server routes, and use HTTPS for JWKS, OIDC discovery, and introspection endpoints. The camel-oauth provider rejects missing issuer/audience policy and plain HTTP endpoints by default; use its explicit opt-out properties only for legacy providers or local development. Do not return token validation diagnostic details directly to external clients.

Implementing a reverse proxy

Platform HTTP component can act as a reverse proxy. In that case, some headers are populated from the absolute URL received on the request line of the HTTP request. Those headers are specific to the underlining platform.

At this moment, this feature is only supported by the camel-platform-http-vertx engine (Camel Main and Camel Quarkus).

Forwarding requests under a path prefix (path-based reverse proxy)

This is a different scenario from the platform-http:proxy forward proxy described above, which is a Host header based forward proxy and only supported in camel-platform-http-vertx. Here, the consumer is registered under an ordinary path, e.g. /reverse-proxy, and requests received under that path should be forwarded to a fixed backend with the prefix stripped, using the http producer’s bridgeEndpoint option.

Enable the consumer option stripUriPrefix so the matched consumer path is removed from CamelHttpPath before the route runs:

from("platform-http:/reverse-proxy?matchOnUriPrefix=true&stripUriPrefix=true")
    .to("http://backend?bridgeEndpoint=true");

matchOnUriPrefix is not required for stripUriPrefix; it is only needed to also forward requests under sub-paths. On an exact match (e.g. GET /reverse-proxy) the path is stripped to /.

Incoming request CamelHttpPath (stripUriPrefix=false, default) CamelHttpPath (stripUriPrefix=true) Forwarded to

GET /reverse-proxy/get

/reverse-proxy/get

/get

http://backend/get

CamelHttpUri/CamelHttpUrl still hold the full original request, only CamelHttpPath is rewritten. This option is currently implemented in camel-platform-http-vertx.

Contract-first REST and unmatched requests

When the consumer is used by the rest-openapi component (rest-dsl contract-first), requests that do not match any operation of the OpenAPI specification are answered by the HTTP layer itself (status 404/405).

Set the unmatchedRequestHandling endpoint option to camel to instead route such requests to Camel, where they are answered by the unmatched request handler (see the rest-openapi component documentation). On Camel Main and Quarkus, camel-platform-http-vertx registers a catch-all route per API base path; on Spring Boot, the catch-all is registered on this component and served by the platform-http starter. The catch-all is evaluated last, so it never shadows the operations of other APIs served by the same server, even when their base paths are nested under this API.

File Attachments handling

Since Apache Camel 4.10, multipart file uploads are easier and harmonized across all runtimes. When a single file is uploaded, the Apache Camel framework provides the following:

  • The Apache Camel message contains:

    • The uploaded file in the message body

    • The file name in the "CamelFileName" message header

    • The file content type in the "CamelFileContentType" message header

    • The file size in the "CamelFileLength" message header

In case of multiple uploads, the header "CamelAttachmentsSize" contains the number of files uploaded.