Configure Apache HTTP Client
Camunda Connect HTTP client uses the Apache HTTP client to make HTTP requests. Accordingly, it supports the same configuration options.
By default, the HTTP client uses Apache’s default configuration and respects the .
Custom Configuration
If you want to reconfigure the client going beyond the default configuration options, e.g. you want to configure another connection manager, the easiest way is to registera new connector configurator.
package org.camunda.connect.example;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.camunda.connect.httpclient.impl.AbstractHttpConnector;
import org.camunda.connect.spi.ConnectorConfigurator;
public class HttpConnectorConfigurator implements ConnectorConfigurator<HttpConnector> {
public Class<HttpConnector> getConnectorClass() {
return HttpConnector.class;
}
public void configure(HttpConnector connector) {
CloseableHttpClient client = HttpClients.custom()
.setMaxConnPerRoute(10)
.setMaxConnTotal(200)
.build();
((AbstractHttpConnector) connector).setHttpClient(client);
}
To enable auto detection of your new configurator please add a file calledorg.camunda.bpm.connect.spi.ConnectorConfigurator
to yourresources/META-INF/services
directory with class name as content. For moreinformation see the extending Connect section.
org.camunda.connect.example.HttpConnectorConfigurator
Requests
A simple GET request:
A POST request with a content type and payload set:
http.createRequest()
.url("http://camunda.org")
.contentType("text/plain")
.payload("Hello World!")
.execute();
The HTTP methods PUT, DELETE, PATCH, HEAD, OPTIONS, TRACEare also available.
Adding HTTP Headers to a Request
To add own headers to the HTTP request the method header
isavailable.
HttpResponse response = http.createRequest()
.get()
.header("Accept", "application/json")
.url("http://camunda.org")
.execute();
This can be used as follows:
Response
A response contains the status code, response headers and body.
Integer statusCode = response.getStatusCode();
String contentTypeHeader = response.getHeader("Content-Type");
After the response was processed it should be closed.
Using the Generic API
Besides the response methods a generic API is providedto gather the response parameters. The following parametersare available:
Parameter | Description |
---|---|
statusCode | Contains the status code of the response |
headers | Contains a map with the HTTP headers of the response |
response | Contains the response body |