in extensions/jolokia/runtime/src/main/java/org/apache/camel/quarkus/jolokia/JolokiaRecorder.java [67:135]
public RuntimeValue<JolokiaServerConfig> createJolokiaServerConfig(
JolokiaRuntimeConfig runtimeConfig,
String endpointPath,
String applicationName) {
Server server = runtimeConfig.server();
Kubernetes kubernetes = runtimeConfig.kubernetes();
// Configure Jolokia HTTP server host, port & context path
String host = runtimeConfig.server().host().orElse(null);
if (ObjectHelper.isEmpty(host)) {
if (LaunchMode.isRemoteDev()) {
host = ALL_INTERFACES;
} else if (LaunchMode.current().isDevOrTest()) {
if (!isWSL()) {
host = LOCALHOST;
} else {
host = ALL_INTERFACES;
}
} else {
host = ALL_INTERFACES;
}
}
Map<String, String> serverOptions = new HashMap<>();
serverOptions.put("host", host);
serverOptions.put("port", String.valueOf(server.port()));
serverOptions.put(ConfigKey.AGENT_CONTEXT.getKeyValue(), "/" + endpointPath);
// Attempt Kubernetes configuration
Optional<String> kubernetesServiceHost = ConfigProvider.getConfig().getOptionalValue("kubernetes.service.host",
String.class);
if (kubernetesServiceHost.isPresent()) {
if (kubernetes.clientAuthenticationEnabled() && kubernetes.serviceCaCert().exists()) {
serverOptions.put(ConfigKey.DISCOVERY_ENABLED.getKeyValue(), "false");
serverOptions.put("protocol", "https");
serverOptions.put("useSslClientAuthentication", "true");
serverOptions.put("extendedClientCheck", "true");
serverOptions.put("caCert", kubernetes.serviceCaCert().getAbsolutePath());
kubernetes.clientPrincipal()
.ifPresent(clientPrincipal -> serverOptions.put("clientPrincipal", clientPrincipal));
} else {
LOG.warnf("Kubernetes service CA certificate %s does not exist", kubernetes.serviceCaCert());
}
}
// Merge configuration with any arbitrary values provided via quarkus.camel.jolokia.additional-properties
Map<String, String> combinedOptions = CollectionHelper.mergeMaps(serverOptions,
runtimeConfig.additionalProperties());
// Configure CamelJolokiaRestrictor if an existing restrictor is not already provided
if (runtimeConfig.registerCamelRestrictor()) {
combinedOptions.putIfAbsent(ConfigKey.RESTRICTOR_CLASS.getKeyValue(), CamelJolokiaRestrictor.class.getName());
}
// Enable discovery based on the provided mode
DiscoveryEnabledMode discoveryMode = server.discoveryEnabledMode();
if (discoveryMode != DiscoveryEnabledMode.NONE) {
if ((discoveryMode == DiscoveryEnabledMode.ALL)
|| (discoveryMode == DiscoveryEnabledMode.DEV_TEST && LaunchMode.current().isDevOrTest())) {
combinedOptions.putIfAbsent(ConfigKey.DISCOVERY_ENABLED.getKeyValue(), "true");
}
}
// Set a default agent description so that it shows up during agent discovery
combinedOptions.putIfAbsent(ConfigKey.AGENT_DESCRIPTION.getKeyValue(), applicationName);
return new RuntimeValue<>(new JolokiaServerConfig(combinedOptions));
}