pfx-rest

Summary: Reference for the pfx-rest Camel component — HTTP REST calls to external APIs with connection/authentication support.


Overview

The pfx-rest component is a producer-only Camel component for making HTTP requests to external APIs. It supports all standard HTTP methods, multiple authentication strategies (Basic, OAuth2, JWT, public/no-auth), named connections, proxy configuration, response size limits, streaming, and connection pooling.

The component is registered under the scheme pfx-rest and belongs to the API category.

URI Format

pfx-rest:method[?options]

The method path parameter is required and determines the HTTP method used. It also supports a special system method for system-configuration-based requests.

Supported Methods

Method

Description

get

HTTP GET

post

HTTP POST

put

HTTP PUT

delete

HTTP DELETE

patch

HTTP PATCH

head

HTTP HEAD

options

HTTP OPTIONS

trace

HTTP TRACE

system

Special method that reads configuration from system properties rather than inline parameters

Endpoint Parameters

Core Parameters

Parameter

Type

Default

Description

method

String

(required, path)

HTTP method to use (see table above)

uri

String


URI to invoke. If the connection does not specify a URL, provide the full path to the resource.

connection

String


Name of the connection to use for authentication and base URL resolution

contentType

String

application/json

Content type of the request

okStatusCodeRange

String

200-299

HTTP status codes considered a successful response

mapper

String


Mapper to apply to request/response

filter

String


Filter to apply

Input/Output Routing

Parameter

Type

Default

Description

inputSource

String


Source of data in the exchange: header, property, or body

inputSourceName

String


Name of the header or property when inputSource is header or property

outputTarget

String


Target for response data: header, property, or body

outputTargetName

String


Name of the header or property when outputTarget is header or property

Proxy

Parameter

Type

Default

Description

proxyHost

String


Proxy host. Both proxyHost and proxyPort must be set together.

proxyPort

Integer


Proxy port. Both proxyHost and proxyPort must be set together.

Timeouts

Parameter

Type

Default

Description

connectionTimeoutMs

Long


Connection timeout in milliseconds (legacy parameter)

connectTimeoutMs

Long


Connection timeout in milliseconds for connecting to a target

soTimeoutMs

Long


Socket timeout in milliseconds for waiting for data

responseTimeoutMs

Long


Response timeout in milliseconds for waiting for a response

Connection Pooling and Keep-Alive

Parameter

Type

Default

Description

reuseConnection

Boolean


Reuse connections for subsequent requests to the same target

evictExpiredConnections

Boolean


Automatically evict expired connections from the pool

evictIdleConnections

Boolean


Automatically evict idle connections

evictIdleConnectionsMaxIdleTimeMs

Long


Maximum idle time (ms) before eviction

maxConnectionsTotal

Integer


Maximum total simultaneous connections in the pool

maxConnectionsPerRoute

Integer


Maximum simultaneous connections per route in the pool

soKeepAlive

Boolean


Enable SO_KEEPALIVE socket option

useMinimalKeepAliveStrategy

Boolean


Use a minimal keep-alive strategy for determining keep-alive duration

Streaming and File Upload

Parameter

Type

Default

Description

disableStreamCache

boolean

false

When true, content is streamed directly to file instead of stored in memory

downloadDir

String


Custom directory for downloaded files when disableStreamCache is enabled (defaults to temp dir)

autoDecode

boolean

true

Whether to auto-decode response content

fileKey

String

file

Key name for the file part in multipart uploads

useBoundary

boolean

true

Whether to use a boundary in multipart requests and content type

maxResponseSizeInMB

int

0 (unlimited)

Maximum response size in MB. Throws an exception if exceeded.

Connection Behavior

Parameter

Type

Default

Description

failIfNoConnection

boolean

false

Whether to fail when a named connection is not found, or fall back to default behavior

System Configuration (method=system)

Parameter

Type

Description

systemName

String

System name

systemConfigurationItem

String

System configuration item

systemConfigurationProperties

Map

Additional system configuration properties (unmatched URI parameters are collected here)

Connection Types

The pfx-rest component supports four connection types, each providing a different authentication strategy:

REST Public (rest-public)

No authentication. Used for accessing public APIs.

  • Fields: url, headers

REST Basic (rest-basic)

HTTP Basic authentication. Credentials are sent with every request.

  • Fields: url, headers, username, password, authRequestHeader (default: Authorization), authRequestHeaderBearer (default: Basic)

REST JWT (rest-jwt)

Token-based authentication. A token is obtained from an auth endpoint before the first request and refreshed when it expires.

  • Fields: url, headers, authUrl, username, password, authRequestTemplate (default: {"username": "::username","password":"::password"}), authRequestContentType (default: application/json), authRequestHeader, authRequestHeaderBearer (default: Bearer), authResponseTokenKey (default: access_token), authResponseExpirationKey (default: expires_in), authResponseExpirationKeyLocation, authExpirationMultiplier (default: 1), reAuthOnCodes

REST OAuth2 (rest-oauth2)

OAuth2 authentication. Similar to JWT but supports client credentials and scope.

  • Fields: url, headers, authUrl, username, password, clientId, clientSecret, scope, authRequestTemplate (default: {"grant_type": "password","client_id": "::clientId","client_secret": "::clientSecret","username": "::username","password":"::password"}), authRequestContentType (default: application/x-www-form-urlencoded), authRequestHeader, authRequestHeaderBearer (default: Bearer), authResponseTokenKey, authResponseExpirationKey, authResponseExpirationKeyLocation, authExpirationMultiplier, reAuthOnCodes

Authentication Template Placeholders

Token-based connections (JWT, OAuth2) use authRequestTemplate with these placeholders:

Placeholder

Resolved From

::username

Connection username

::password

Connection password

::clientId

Connection clientId (OAuth2 only)

::clientSecret

Connection clientSecret (OAuth2 only)

::scope

Connection scope (OAuth2 only)

Re-authentication on Error Codes

For token-based connections, the reAuthOnCodes field accepts a comma-separated list of HTTP status codes (e.g., 400,401,404). When any of these codes are returned from a request, the component will re-authenticate and retry. This is useful for systems like Salesforce where tokens may be invalidated unexpectedly.

Usage Examples

GET with named connection

XML
<route id="restGet">
    <from uri="direct:fetchData"/>
    <to uri="pfx-rest:get?connection=myRestConn&amp;uri=/api/v1/products"/>
</route>

POST with inline body

XML
<route id="restPost">
    <from uri="direct:sendData"/>
    <to uri="pfx-rest:post?connection=myRestConn&amp;uri=/api/v1/orders&amp;contentType=application/json"/>
</route>

The exchange body is sent as the request body.

GET with query parameters

Unmatched URI parameters (those not recognized as component options) are automatically collected as query parameters:

XML
<route id="restGetWithParams">
    <from uri="direct:search"/>
    <to uri="pfx-rest:get?connection=myRestConn&amp;uri=/api/v1/search&amp;q=test&amp;limit=100"/>
</route>

Here, q and limit are passed as query parameters: /api/v1/search?q=test&limit=100.

Download large file with streaming

XML
<route id="restDownload">
    <from uri="direct:downloadFile"/>
    <to uri="pfx-rest:get?connection=myRestConn&amp;uri=/api/v1/export&amp;disableStreamCache=true&amp;downloadDir=/tmp/downloads"/>
</route>

Using input/output routing

XML
<route id="restInputOutput">
    <from uri="direct:start"/>
    <setHeader name="requestPayload">
        <constant>{"key": "value"}</constant>
    </setHeader>
    <to uri="pfx-rest:post?connection=myRestConn&amp;uri=/api/v1/data&amp;inputSource=header&amp;inputSourceName=requestPayload&amp;outputTarget=header&amp;outputTargetName=responseData"/>
    <!-- response is now in header 'responseData', body is unchanged -->
</route>

Response size limit

XML
<to uri="pfx-rest:get?connection=myRestConn&amp;uri=/api/v1/large-data&amp;maxResponseSizeInMB=50"/>

An exception is thrown if the response exceeds 50 MB.

Error Handling

  • If failIfNoConnection is true and the named connection is not found, the component throws an exception.

  • If failIfNoConnection is false (default) and no connection is found, a default no-auth connection is used.

  • HTTP responses outside the okStatusCodeRange result in an ExternalSystemException.

  • Proxy misconfiguration (only one of proxyHost/proxyPort set) is detected by the proxyValid() check.

See Also