Jolokia

Spring Boot auto-configuration for Camel Jolokia integration.

The Jolokia Starter integrates Jolokia agent configuration in Spring Boot, wrapping the Jolokia Spring Support with default configurations to let the application work out-of-the-box without manually declaring Jolokia servers.

This starter can be considered an alternative to the Jolokia JVM agent. When enabled, it exposes the Jolokia endpoint at http://0.0.0.0:8778/jolokia.

Maven coordinates

<dependency>
    <groupId>org.apache.camel.springboot</groupId>
    <artifactId>camel-jolokia-starter</artifactId>
</dependency>

Usage

The Jolokia agent is auto-configured when the starter is on the classpath. Configure in application.properties:

# Change the default port
camel.component.jolokia.server-config.port=8779

# Enable discovery for Hawtio
camel.component.jolokia.server-config.discoveryEnabled=true

Security Restrictor

To avoid exposing all JMX MBeans (see Security considerations), a default Jolokia Restrictor is provided that allows only Camel related data and some basic information from Java.

You can disable the restrictor with camel.component.jolokia.use-camel-restrictor=false or use your own custom one with camel.component.jolokia.server-config.restrictorClass=org.example.MyRestrictor.

An example to extend the provided restrictor:

public class MyRestrictor extends CamelRestrictor {

    @Override
    protected List<String> getAllowedDomains() {
        final List<String> newDomains = new ArrayList<>(getDefaultDomains());
        newDomains.add("my.domain");
        return newDomains;
    }
}

Custom Configuration

The starter creates a default configuration according to the provided properties, but you can provide a custom SpringJolokiaConfigHolder implementation by declaring a Bean named camelConfigHolder:

@Bean("camelConfigHolder")
public SpringJolokiaConfigHolder myConfigHolder() {
    final SpringJolokiaConfigHolder myConfig = new SpringJolokiaConfigHolder();
    myConfig.setConfig(Map.of("threadNr", "5", "executor", "fixed"));
    return myConfig;
}

The executor configuration will be taken from the custom Bean if the same properties are not defined in application.properties. This behaviour is configurable with camel.component.jolokia.config-from-properties-first=false, meaning the configuration uses the Bean value when the key is present in both places. If the keys from properties and beans do not override each other, they will be merged.

Logging Configuration

The starter provides a log configuration using the slf4j implementation. You can change this by providing a Bean named camelLogHandlerHolder:

@Bean
@ConditionalOnMissingBean(name = "camelLogHandlerHolder")
public SpringJolokiaLogHandlerHolder myLogHandlerHolder() {
    final SpringJolokiaLogHandlerHolder stdoutHandlerHolder = new SpringJolokiaLogHandlerHolder();
    stdoutHandlerHolder.setType("stdout");
    return stdoutHandlerHolder;
}

The logging category for the Camel Spring Boot starter is org.apache.camel.component.jolokia, while the core Jolokia server uses org.jolokia:

logging.level.org.apache.camel.component.jolokia=TRACE
logging.level.org.jolokia=TRACE

Kubernetes Support

The starter provides default configurations for Kubernetes environments. It checks for the existence of a certification authority file at /var/run/secrets/kubernetes.io/serviceaccount/service-ca.crt and, if present, initializes the server using TLS protocol and client authentication. The endpoint becomes https://0.0.0.0:8778/jolokia.

You can disable this behaviour with camel.component.jolokia.kubernetes-discover=false.

Spring Boot Actuator Integration

The wrapped Jolokia Spring Support library provides integration with Spring Boot Actuator, where it is possible to retrieve information about the Jolokia server. As with any other actuator endpoint, it can be excluded or disabled.

Spring Boot Auto-Configuration

The starter supports 10 options, which are listed below.

Name Description Default Type

camel.component.jolokia.config-from-properties-first

In case of custom bean configuration (it is necessary to provide a bean named 'camelConfigHolder' of type SpringJolokiaConfigHolder) containing the same keys provided by the configuration (application.properties), it prefers values from configuration on values from bean, default true.

true

Boolean

camel.component.jolokia.enabled

Enable the component, default true.

true

Boolean

camel.component.jolokia.expose-application-context

If set to true, additional org.jolokia.support.spring.backend.SpringRequestHandler is added to the agent, so we can invoke Spring bean operations using Jolokia protocol, default false. @see <a href="https://jolokia.org/reference/html/manual/spring.html">Support for Spring Framework in Jolokia</a>

false

Boolean

camel.component.jolokia.kubernetes-discover

To set default properties to make the jolokia enpoint work on k8s/OCP, default true. It sets: <ul> <li>protocol = https</li> <li>caCert = /var/run/secrets/kubernetes.io/serviceaccount/service-ca.crt</li> <li>useSslClientAuthentication = true</li> </ul>

true

Boolean

camel.component.jolokia.kubernetes-use-default-ca

To prefer the default CA file, default true. <pre> /var/run/secrets/kubernetes.io/serviceaccount/service-ca.crt </pre>

true

Boolean

camel.component.jolokia.lookup-config

If set to true, Spring’s application context is searched for additional beans of org.jolokia.support.spring.SpringJolokiaConfigHolder class that are used to configure the agent, default false. @see <a href="https://jolokia.org/reference/html/manual/spring.html">Support for Spring Framework in Jolokia</a>

false

Boolean

camel.component.jolokia.lookup-services

If set to true, Spring’s application context is searched for additional beans of org.jolokia.server.core.service.api.JolokiaService. These beans are added to Jolokia internal context as services used by the Agent, default false. @see <a href="https://jolokia.org/reference/html/manual/spring.html">Support for Spring Framework in Jolokia</a>

false

Boolean

camel.component.jolokia.server-config

Configuration for the exposed endpoint. Example: <pre> camel.component.jolokia.serverConfig.discoveryEnabled=true </pre> @see <a href="https://jolokia.org/reference/html/manual/agents.html#jvm-agent">JVM agent configuration options</a>

String>

camel.component.jolokia.system-properties-mode

Specifies how system properties with jolokia. prefix (the prefix is then stripped) affect Jolokia Agent configuration, default 'never'. There are three modes available: <ul> <li>never - No lookup is done on system properties as all. This is the default mode.</li> <li>fallback - System properties with a prefix jolokia. are used as fallback configuration values if not specified locally in the Spring application context. E.g. jolokia.port=8888 will change the port on which the agent is listening to 8888 if the port is not explicitly specified in the configuration.</li> <li>override - System properties with a prefix jolokia. are used as configuration values even if they are specified locally in the Spring application context. E.g. jolokia.port=8888 will change the port on which the agent is listening to 8888 in any case.</li> </ul> @see <a href="https://jolokia.org/reference/html/manual/spring.html">Support for Spring Framework in Jolokia</a>

never

String

camel.component.jolokia.use-camel-restrictor

All operations on MBeans are allowed by default, the Camel restrictor allows only operations on Camel domain, default true. If key 'restrictorClass' in serverConfig has been provided, this property will be ignorated. <pre> org.apache.camel.component.jolokia.springboot.restrictor.CamelRestrictor </pre>

true

Boolean