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.

  1. package org.camunda.connect.example;
  2. import org.apache.http.impl.client.CloseableHttpClient;
  3. import org.apache.http.impl.client.HttpClients;
  4. import org.camunda.connect.httpclient.impl.AbstractHttpConnector;
  5. import org.camunda.connect.spi.ConnectorConfigurator;
  6. public class HttpConnectorConfigurator implements ConnectorConfigurator<HttpConnector> {
  7. public Class<HttpConnector> getConnectorClass() {
  8. return HttpConnector.class;
  9. }
  10. public void configure(HttpConnector connector) {
  11. CloseableHttpClient client = HttpClients.custom()
  12. .setMaxConnPerRoute(10)
  13. .setMaxConnTotal(200)
  14. .build();
  15. ((AbstractHttpConnector) connector).setHttpClient(client);
  16. }

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.

  1. org.camunda.connect.example.HttpConnectorConfigurator

Requests

A simple GET request:

A POST request with a content type and payload set:

  1. http.createRequest()
  2. .url("http://camunda.org")
  3. .contentType("text/plain")
  4. .payload("Hello World!")
  5. .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.

  1. HttpResponse response = http.createRequest()
  2. .get()
  3. .header("Accept", "application/json")
  4. .url("http://camunda.org")
  5. .execute();

This can be used as follows:

Response

A response contains the status code, response headers and body.

  1. Integer statusCode = response.getStatusCode();
  2. 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