HTTP Sink
Provided by: "Apache Software Foundation"
Support Level for this Kamelet is: "Stable"
Sends each message to a web service or REST API as an HTTP or HTTPS request, for example a POST of JSON to a webhook.
Use it to push data to any service that accepts HTTP calls, such as a webhook, a REST API or a serverless function.
Input: the body is sent as the request body, as text, bytes or a stream. Turn structured data such as a Map into JSON text first, for example with json-serialize-action. The Content-Type header is sent as the content type of the request, and the other headers of the message, except the Camel ones and Authorization and Proxy-Authorization, are sent as HTTP headers.
Output: when it is used inside a route, the body afterwards is the response of the service.
Good to know: a response with a status code outside okStatusCodeRange, which is 200-299 when it is not set, fails the message. The address, the method and the proxy come only from the options; headers on the message cannot change where it is sent. The login comes only from the options too: an Authorization or Proxy-Authorization header on the message is removed, so a credential that came with the message, such as the one of the caller of webhook-source, is not sent on. For a token that differs for each message, use the http component instead. Log in either with authUsername and authPassword, with a static token in authBearerToken, or with oauth2ClientId, oauth2ClientSecret and oauth2TokenEndpoint: the Kamelet then gets a token from that URL and sends it as a Bearer token. Without authenticationPreemptive, the user and password, or the static token, are sent only after the service asks for them with a 401 response. To go through an HTTP proxy, set proxyHost and proxyPort, and proxyUser and proxyPassword when the proxy asks for a login; an https:// address goes through the proxy too. The certificate of an https:// service is checked against the certificate authorities that Java trusts. To trust a private one with Camel JBang or Camel Main, set the application properties camel.ssl.enabled=true, camel.ssl.trustStore, camel.ssl.trustStorePassword and camel.component.https.useGlobalSslContextParameters=true: that trust store then replaces the one of Java for every https:// call of the application. It keeps the cookies that the service sets, as a browser does, and sends them back on the next calls. To turn that off, set the application property camel.component.http.cookie-management-disabled=true, or camel.component.https.cookie-management-disabled=true for an https:// address: it then applies to every call of the application to such addresses.
Configuration Options
The following table summarizes the configuration options available for the http-sink Kamelet:
| Property | Name | Description | Type | Default | Example |
|---|---|---|---|---|---|
URL | Required The address to send each message to, with the path and any query parameters. It must start with | string | https://my-service/path | ||
Bearer Token | A static token, such as an API key, sent in the | string | |||
Authentication Method | The login method, | string | Basic | ||
Authentication Password | The password of | string | |||
Authentication Username | The user to log in as, together with | string | |||
Authentication Preemptive | If true, | boolean | false | ||
Follow Redirects | If true, a redirect, a response with a status code such as 301, 302 or 307, is followed to the address in its | boolean | |||
Method | The HTTP method of the request. Most APIs expect Enum values: * GET * POST * PUT * DELETE * HEAD * OPTIONS * TRACE * PATCH | string | POST | ||
OAuth2 Client ID | The client ID of the application, as registered with the OAuth 2.0 provider. With | string | |||
OAuth2 Client Secret | The client secret of the application, as given by the OAuth 2.0 provider. | string | |||
OAuth2 Scope | The scope to ask for in the token request, when the OAuth 2.0 provider needs one. | string | orders.write | ||
OAuth2 Token URL | The URL to get the tokens from, as given by the OAuth 2.0 provider. The Kamelet logs in to it with | string | https://login.example.com/oauth2/token | ||
OK Status Codes | The status codes of a response that do not fail the message, as ranges such as | string | 200-299,404 | ||
Proxy Host | The host name or IP address of an HTTP proxy to send the requests through, without the port. Use it with | string | proxy.example.com | ||
Proxy Password | The password of | string | |||
Proxy Port | The port of the HTTP proxy in | integer | 3128 | ||
Proxy User | The user to log in to the HTTP proxy as, when the proxy asks for a login. Use it with | string |
Dependencies
At runtime, the http-sink Kamelet relies upon the presence of the following dependencies:
-
camel:http
-
camel:kamelet
Camel JBang usage
Prerequisites
-
You’ve installed JBang.
-
You have executed the following command:
jbang app install camel@apache/camel Supposing you have a file named route.yaml with this content:
- route:
from:
uri: "kamelet:timer-source"
parameters:
period: 10000
message: 'test'
steps:
- to:
uri: "kamelet:http-sink" You can now run it directly through the following command
camel run route.yaml HTTP Sink Kamelet Description
HTTP Methods
Supports all standard HTTP methods: GET, POST (default), PUT, DELETE, HEAD, OPTIONS, TRACE, and PATCH.
Logging In
The login options are all optional. Without them, the requests are sent without a login.
| Login | Options | When the credentials are sent |
|---|---|---|
Basic or Digest |
| After the service answers 401 and asks for them. With |
Static token, such as an API key |
| After the service answers 401 with a |
OAuth 2.0 client credentials |
| With every request: the Kamelet gets a token from |
For example, to call an API that takes a static token:
- route:
from:
uri: "kamelet:timer-source"
parameters:
message: '{"status": "ok"}'
steps:
- to:
uri: "kamelet:http-sink"
parameters:
url: "https://api.example.com/v1/events"
authMethod: Bearer
authBearerToken: "{{api.token}}"
authenticationPreemptive: true The token is sent as the header Authorization: Bearer followed by the token.
Status Codes That Do Not Fail
A response with a status code outside okStatusCodeRange fails the message. When the option is not set, it is 200-299, so a status code of 300 or higher fails the message. Some APIs answer a normal case with another code, such as 404 when a record does not exist, or 409 when it exists already. List those codes together with the 2xx codes:
- to:
uri: "kamelet:http-sink"
parameters:
url: "https://api.example.com/v1/customers"
okStatusCodeRange: "200-299,409" The response code is then in the CamelHttpResponseCode header, and the body is the response of the service. Setting only 409 would make a 200 response fail.
Going Through a Proxy
To send the requests through an HTTP proxy, set proxyHost and proxyPort. The proxy is used only when both are set. When the proxy asks for a login, also set proxyUser and proxyPassword: they are sent after the proxy answers 407 and asks for them.
- to:
uri: "kamelet:http-sink"
parameters:
url: "https://api.example.com/v1/events"
proxyHost: proxy.example.com
proxyPort: 3128
proxyUser: "{{proxy.user}}"
proxyPassword: "{{proxy.password}}" An https:// address goes through the proxy too, in a tunnel: the proxy sees the host name, not the request.
Following Redirects
A redirect, a response with a status code such as 301, 302 or 307, is not followed when followRedirects is not set: its status code fails the message, unless it is in okStatusCodeRange. With followRedirects: true, the request goes on to the address in the Location header of the response. A POST answered with 301, 302 or 303 goes on as a GET without the body; 307 and 308 keep the method and the body.
Trusting a Private Certificate Authority
The certificate of an https:// service is checked against the certificate authorities that Java trusts. A service whose certificate is signed by a private certificate authority fails with PKIX path building failed.
With Camel JBang or Camel Main, put the certificate of the authority in a trust store, for example with keytool -importcert -file ca.crt -keystore truststore.p12 -storetype PKCS12, and set these application properties:
camel.ssl.enabled = true
camel.ssl.trustStore = file:/etc/certs/truststore.p12
camel.ssl.trustStorePassword = changeit
camel.component.https.useGlobalSslContextParameters = true That trust store then replaces the one of Java for every https:// call of the application, so it must also hold the authorities of any public service the application calls. The http:// calls are not changed.