This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push: new 78250549b19 Officially add Splunk HEC URL and token as query parameters (#13041) 78250549b19 is described below commit 78250549b191c4e1203323348351a1e570c8d2c3 Author: Jeffrey D <11084623+neph...@users.noreply.github.com> AuthorDate: Thu Feb 8 03:13:11 2024 -0500 Officially add Splunk HEC URL and token as query parameters (#13041) * add Splunk HEC URL and token as query parameters * replace Splunk HEC token path with query param * regen splunk hec catalog --- .../camel/catalog/components/splunk-hec.json | 26 ++-- .../splunkhec/SplunkHECEndpointConfigurer.java | 3 + .../splunkhec/SplunkHECEndpointUriFactory.java | 3 +- .../camel/component/splunkhec/splunk-hec.json | 26 ++-- .../src/main/docs/splunk-hec-component.adoc | 8 +- .../component/splunkhec/SplunkHECComponent.java | 7 + .../splunkhec/SplunkHECConfiguration.java | 15 +++ .../component/splunkhec/SplunkHECEndpoint.java | 51 +++---- .../component/splunkhec/SplunkHECProducer.java | 2 +- .../splunkhec/SplunkHECComponentTest.java | 148 +++++++++++++++++++++ .../splunkhec/SplunkHECConfigurationTest.java | 6 + .../component/splunkhec/SplunkHECEndpointTest.java | 102 -------------- .../integration/SplunkHECITManualTest.java | 30 ++--- .../ROOT/pages/camel-4x-upgrade-guide-4_4.adoc | 4 + 14 files changed, 252 insertions(+), 179 deletions(-) diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/splunk-hec.json b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/splunk-hec.json index 5683789b886..14089680ebd 100644 --- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/splunk-hec.json +++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/splunk-hec.json @@ -14,7 +14,7 @@ "version": "4.4.0-SNAPSHOT", "scheme": "splunk-hec", "extendsScheme": "", - "syntax": "splunk-hec:splunkURL\/token", + "syntax": "splunk-hec:splunkURL", "async": false, "api": false, "consumerOnly": false, @@ -31,17 +31,17 @@ }, "properties": { "splunkURL": { "index": 0, "kind": "path", "displayName": "Splunk URL", "group": "producer", "label": "", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "Splunk Host and Port (example: my_splunk_server:8089)" }, - "token": { "index": 1, "kind": "path", "displayName": "Token", "group": "security", "label": "security", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": true, "description": "Splunk HEC token (this is the token created for HEC and not the user's token)" }, - "bodyOnly": { "index": 2, "kind": "parameter", "displayName": "Body Only", "group": "producer", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.splunkhec.SplunkHECConfiguration", "configurationField": "configuration", "description": "Send only the message body" }, - "headersOnly": { "index": 3, "kind": "parameter", "displayName": "Headers Only", "group": "producer", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.splunkhec.SplunkHECConfiguration", "configurationField": "configuration", "description": "Send only message headers" }, - "host": { "index": 4, "kind": "parameter", "displayName": "Host", "group": "producer", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.splunkhec.SplunkHECConfiguration", "configurationField": "configuration", "description": "Splunk host field of the event message. This is not the Splunk host to connect to." }, - "index": { "index": 5, "kind": "parameter", "displayName": "Index", "group": "producer", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "camel", "configurationClass": "org.apache.camel.component.splunkhec.SplunkHECConfiguration", "configurationField": "configuration", "description": "Splunk index to write to" }, - "source": { "index": 6, "kind": "parameter", "displayName": "Source", "group": "producer", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "camel", "configurationClass": "org.apache.camel.component.splunkhec.SplunkHECConfiguration", "configurationField": "configuration", "description": "Splunk source argument" }, - "sourceType": { "index": 7, "kind": "parameter", "displayName": "Source Type", "group": "producer", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "camel", "configurationClass": "org.apache.camel.component.splunkhec.SplunkHECConfiguration", "configurationField": "configuration", "description": "Splunk sourcetype argument" }, - "splunkEndpoint": { "index": 8, "kind": "parameter", "displayName": "Splunk Endpoint", "group": "producer", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "\/services\/collector\/event", "configurationClass": "org.apache.camel.component.splunkhec.SplunkHECConfiguration", "configurationField": "configuration", "description": "Splunk endpoint Defaults to \/services\/collector\/e [...] - "time": { "index": 9, "kind": "parameter", "displayName": "Time", "group": "producer", "label": "", "required": false, "type": "integer", "javaType": "java.lang.Long", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.splunkhec.SplunkHECConfiguration", "configurationField": "configuration", "description": "Time this even occurred. By default, the time will be when this event hits the splunk server." }, - "lazyStartProducer": { "index": 10, "kind": "parameter", "displayName": "Lazy Start Producer", "group": "producer (advanced)", "label": "producer,advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a produ [...] - "https": { "index": 11, "kind": "parameter", "displayName": "Https", "group": "security", "label": "security", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "configurationClass": "org.apache.camel.component.splunkhec.SplunkHECConfiguration", "configurationField": "configuration", "description": "Contact HEC over https." }, - "skipTlsVerify": { "index": 12, "kind": "parameter", "displayName": "Skip Tls Verify", "group": "security", "label": "security", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.splunkhec.SplunkHECConfiguration", "configurationField": "configuration", "description": "Splunk HEC TLS verification." } + "bodyOnly": { "index": 1, "kind": "parameter", "displayName": "Body Only", "group": "producer", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.splunkhec.SplunkHECConfiguration", "configurationField": "configuration", "description": "Send only the message body" }, + "headersOnly": { "index": 2, "kind": "parameter", "displayName": "Headers Only", "group": "producer", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.splunkhec.SplunkHECConfiguration", "configurationField": "configuration", "description": "Send only message headers" }, + "host": { "index": 3, "kind": "parameter", "displayName": "Host", "group": "producer", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.splunkhec.SplunkHECConfiguration", "configurationField": "configuration", "description": "Splunk host field of the event message. This is not the Splunk host to connect to." }, + "index": { "index": 4, "kind": "parameter", "displayName": "Index", "group": "producer", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "camel", "configurationClass": "org.apache.camel.component.splunkhec.SplunkHECConfiguration", "configurationField": "configuration", "description": "Splunk index to write to" }, + "source": { "index": 5, "kind": "parameter", "displayName": "Source", "group": "producer", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "camel", "configurationClass": "org.apache.camel.component.splunkhec.SplunkHECConfiguration", "configurationField": "configuration", "description": "Splunk source argument" }, + "sourceType": { "index": 6, "kind": "parameter", "displayName": "Source Type", "group": "producer", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "camel", "configurationClass": "org.apache.camel.component.splunkhec.SplunkHECConfiguration", "configurationField": "configuration", "description": "Splunk sourcetype argument" }, + "splunkEndpoint": { "index": 7, "kind": "parameter", "displayName": "Splunk Endpoint", "group": "producer", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "\/services\/collector\/event", "configurationClass": "org.apache.camel.component.splunkhec.SplunkHECConfiguration", "configurationField": "configuration", "description": "Splunk endpoint Defaults to \/services\/collector\/e [...] + "time": { "index": 8, "kind": "parameter", "displayName": "Time", "group": "producer", "label": "", "required": false, "type": "integer", "javaType": "java.lang.Long", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.splunkhec.SplunkHECConfiguration", "configurationField": "configuration", "description": "Time this even occurred. By default, the time will be when this event hits the splunk server." }, + "lazyStartProducer": { "index": 9, "kind": "parameter", "displayName": "Lazy Start Producer", "group": "producer (advanced)", "label": "producer,advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a produc [...] + "https": { "index": 10, "kind": "parameter", "displayName": "Https", "group": "security", "label": "security", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "configurationClass": "org.apache.camel.component.splunkhec.SplunkHECConfiguration", "configurationField": "configuration", "description": "Contact HEC over https." }, + "skipTlsVerify": { "index": 11, "kind": "parameter", "displayName": "Skip Tls Verify", "group": "security", "label": "security", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.splunkhec.SplunkHECConfiguration", "configurationField": "configuration", "description": "Splunk HEC TLS verification." }, + "token": { "index": 12, "kind": "parameter", "displayName": "Token", "group": "security", "label": "security", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": true, "configurationClass": "org.apache.camel.component.splunkhec.SplunkHECConfiguration", "configurationField": "configuration", "description": "Splunk HEC token (this is the token created for HEC and not the user's token)" } } } diff --git a/components/camel-splunk-hec/src/generated/java/org/apache/camel/component/splunkhec/SplunkHECEndpointConfigurer.java b/components/camel-splunk-hec/src/generated/java/org/apache/camel/component/splunkhec/SplunkHECEndpointConfigurer.java index b87621b0bff..a1863db5d36 100644 --- a/components/camel-splunk-hec/src/generated/java/org/apache/camel/component/splunkhec/SplunkHECEndpointConfigurer.java +++ b/components/camel-splunk-hec/src/generated/java/org/apache/camel/component/splunkhec/SplunkHECEndpointConfigurer.java @@ -38,6 +38,7 @@ public class SplunkHECEndpointConfigurer extends PropertyConfigurerSupport imple case "splunkendpoint": case "splunkEndpoint": target.getConfiguration().setSplunkEndpoint(property(camelContext, java.lang.String.class, value)); return true; case "time": target.getConfiguration().setTime(property(camelContext, java.lang.Long.class, value)); return true; + case "token": target.getConfiguration().setToken(property(camelContext, java.lang.String.class, value)); return true; default: return false; } } @@ -62,6 +63,7 @@ public class SplunkHECEndpointConfigurer extends PropertyConfigurerSupport imple case "splunkendpoint": case "splunkEndpoint": return java.lang.String.class; case "time": return java.lang.Long.class; + case "token": return java.lang.String.class; default: return null; } } @@ -87,6 +89,7 @@ public class SplunkHECEndpointConfigurer extends PropertyConfigurerSupport imple case "splunkendpoint": case "splunkEndpoint": return target.getConfiguration().getSplunkEndpoint(); case "time": return target.getConfiguration().getTime(); + case "token": return target.getConfiguration().getToken(); default: return null; } } diff --git a/components/camel-splunk-hec/src/generated/java/org/apache/camel/component/splunkhec/SplunkHECEndpointUriFactory.java b/components/camel-splunk-hec/src/generated/java/org/apache/camel/component/splunkhec/SplunkHECEndpointUriFactory.java index 168d6b2ac84..afe0e2488ba 100644 --- a/components/camel-splunk-hec/src/generated/java/org/apache/camel/component/splunkhec/SplunkHECEndpointUriFactory.java +++ b/components/camel-splunk-hec/src/generated/java/org/apache/camel/component/splunkhec/SplunkHECEndpointUriFactory.java @@ -15,7 +15,7 @@ import org.apache.camel.spi.EndpointUriFactory; */ public class SplunkHECEndpointUriFactory extends org.apache.camel.support.component.EndpointUriFactorySupport implements EndpointUriFactory { - private static final String BASE = ":splunkURL/token"; + private static final String BASE = ":splunkURL"; private static final Set<String> PROPERTY_NAMES; private static final Set<String> SECRET_PROPERTY_NAMES; @@ -55,7 +55,6 @@ public class SplunkHECEndpointUriFactory extends org.apache.camel.support.compon Map<String, Object> copy = new HashMap<>(properties); uri = buildPathParameter(syntax, uri, "splunkURL", null, true, copy); - uri = buildPathParameter(syntax, uri, "token", null, true, copy); uri = buildQueryParameters(uri, copy, encode); return uri; } diff --git a/components/camel-splunk-hec/src/generated/resources/org/apache/camel/component/splunkhec/splunk-hec.json b/components/camel-splunk-hec/src/generated/resources/org/apache/camel/component/splunkhec/splunk-hec.json index 5683789b886..14089680ebd 100644 --- a/components/camel-splunk-hec/src/generated/resources/org/apache/camel/component/splunkhec/splunk-hec.json +++ b/components/camel-splunk-hec/src/generated/resources/org/apache/camel/component/splunkhec/splunk-hec.json @@ -14,7 +14,7 @@ "version": "4.4.0-SNAPSHOT", "scheme": "splunk-hec", "extendsScheme": "", - "syntax": "splunk-hec:splunkURL\/token", + "syntax": "splunk-hec:splunkURL", "async": false, "api": false, "consumerOnly": false, @@ -31,17 +31,17 @@ }, "properties": { "splunkURL": { "index": 0, "kind": "path", "displayName": "Splunk URL", "group": "producer", "label": "", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "Splunk Host and Port (example: my_splunk_server:8089)" }, - "token": { "index": 1, "kind": "path", "displayName": "Token", "group": "security", "label": "security", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": true, "description": "Splunk HEC token (this is the token created for HEC and not the user's token)" }, - "bodyOnly": { "index": 2, "kind": "parameter", "displayName": "Body Only", "group": "producer", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.splunkhec.SplunkHECConfiguration", "configurationField": "configuration", "description": "Send only the message body" }, - "headersOnly": { "index": 3, "kind": "parameter", "displayName": "Headers Only", "group": "producer", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.splunkhec.SplunkHECConfiguration", "configurationField": "configuration", "description": "Send only message headers" }, - "host": { "index": 4, "kind": "parameter", "displayName": "Host", "group": "producer", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.splunkhec.SplunkHECConfiguration", "configurationField": "configuration", "description": "Splunk host field of the event message. This is not the Splunk host to connect to." }, - "index": { "index": 5, "kind": "parameter", "displayName": "Index", "group": "producer", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "camel", "configurationClass": "org.apache.camel.component.splunkhec.SplunkHECConfiguration", "configurationField": "configuration", "description": "Splunk index to write to" }, - "source": { "index": 6, "kind": "parameter", "displayName": "Source", "group": "producer", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "camel", "configurationClass": "org.apache.camel.component.splunkhec.SplunkHECConfiguration", "configurationField": "configuration", "description": "Splunk source argument" }, - "sourceType": { "index": 7, "kind": "parameter", "displayName": "Source Type", "group": "producer", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "camel", "configurationClass": "org.apache.camel.component.splunkhec.SplunkHECConfiguration", "configurationField": "configuration", "description": "Splunk sourcetype argument" }, - "splunkEndpoint": { "index": 8, "kind": "parameter", "displayName": "Splunk Endpoint", "group": "producer", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "\/services\/collector\/event", "configurationClass": "org.apache.camel.component.splunkhec.SplunkHECConfiguration", "configurationField": "configuration", "description": "Splunk endpoint Defaults to \/services\/collector\/e [...] - "time": { "index": 9, "kind": "parameter", "displayName": "Time", "group": "producer", "label": "", "required": false, "type": "integer", "javaType": "java.lang.Long", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.splunkhec.SplunkHECConfiguration", "configurationField": "configuration", "description": "Time this even occurred. By default, the time will be when this event hits the splunk server." }, - "lazyStartProducer": { "index": 10, "kind": "parameter", "displayName": "Lazy Start Producer", "group": "producer (advanced)", "label": "producer,advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a produ [...] - "https": { "index": 11, "kind": "parameter", "displayName": "Https", "group": "security", "label": "security", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "configurationClass": "org.apache.camel.component.splunkhec.SplunkHECConfiguration", "configurationField": "configuration", "description": "Contact HEC over https." }, - "skipTlsVerify": { "index": 12, "kind": "parameter", "displayName": "Skip Tls Verify", "group": "security", "label": "security", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.splunkhec.SplunkHECConfiguration", "configurationField": "configuration", "description": "Splunk HEC TLS verification." } + "bodyOnly": { "index": 1, "kind": "parameter", "displayName": "Body Only", "group": "producer", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.splunkhec.SplunkHECConfiguration", "configurationField": "configuration", "description": "Send only the message body" }, + "headersOnly": { "index": 2, "kind": "parameter", "displayName": "Headers Only", "group": "producer", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.splunkhec.SplunkHECConfiguration", "configurationField": "configuration", "description": "Send only message headers" }, + "host": { "index": 3, "kind": "parameter", "displayName": "Host", "group": "producer", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.splunkhec.SplunkHECConfiguration", "configurationField": "configuration", "description": "Splunk host field of the event message. This is not the Splunk host to connect to." }, + "index": { "index": 4, "kind": "parameter", "displayName": "Index", "group": "producer", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "camel", "configurationClass": "org.apache.camel.component.splunkhec.SplunkHECConfiguration", "configurationField": "configuration", "description": "Splunk index to write to" }, + "source": { "index": 5, "kind": "parameter", "displayName": "Source", "group": "producer", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "camel", "configurationClass": "org.apache.camel.component.splunkhec.SplunkHECConfiguration", "configurationField": "configuration", "description": "Splunk source argument" }, + "sourceType": { "index": 6, "kind": "parameter", "displayName": "Source Type", "group": "producer", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "camel", "configurationClass": "org.apache.camel.component.splunkhec.SplunkHECConfiguration", "configurationField": "configuration", "description": "Splunk sourcetype argument" }, + "splunkEndpoint": { "index": 7, "kind": "parameter", "displayName": "Splunk Endpoint", "group": "producer", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "\/services\/collector\/event", "configurationClass": "org.apache.camel.component.splunkhec.SplunkHECConfiguration", "configurationField": "configuration", "description": "Splunk endpoint Defaults to \/services\/collector\/e [...] + "time": { "index": 8, "kind": "parameter", "displayName": "Time", "group": "producer", "label": "", "required": false, "type": "integer", "javaType": "java.lang.Long", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.splunkhec.SplunkHECConfiguration", "configurationField": "configuration", "description": "Time this even occurred. By default, the time will be when this event hits the splunk server." }, + "lazyStartProducer": { "index": 9, "kind": "parameter", "displayName": "Lazy Start Producer", "group": "producer (advanced)", "label": "producer,advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a produc [...] + "https": { "index": 10, "kind": "parameter", "displayName": "Https", "group": "security", "label": "security", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "configurationClass": "org.apache.camel.component.splunkhec.SplunkHECConfiguration", "configurationField": "configuration", "description": "Contact HEC over https." }, + "skipTlsVerify": { "index": 11, "kind": "parameter", "displayName": "Skip Tls Verify", "group": "security", "label": "security", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.splunkhec.SplunkHECConfiguration", "configurationField": "configuration", "description": "Splunk HEC TLS verification." }, + "token": { "index": 12, "kind": "parameter", "displayName": "Token", "group": "security", "label": "security", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": true, "configurationClass": "org.apache.camel.component.splunkhec.SplunkHECConfiguration", "configurationField": "configuration", "description": "Splunk HEC token (this is the token created for HEC and not the user's token)" } } } diff --git a/components/camel-splunk-hec/src/main/docs/splunk-hec-component.adoc b/components/camel-splunk-hec/src/main/docs/splunk-hec-component.adoc index ff777ec8771..6a08c12aefd 100644 --- a/components/camel-splunk-hec/src/main/docs/splunk-hec-component.adoc +++ b/components/camel-splunk-hec/src/main/docs/splunk-hec-component.adoc @@ -32,7 +32,7 @@ for this component: == URI format ------------------------------- -splunk-hec:[endpoint]/[token]?[options] +splunk-hec:[splunkURL]?[options] ------------------------------- @@ -72,7 +72,7 @@ server. [source,java] ------------------------------- from("direct:start") - .to("splunk-hec://localhost:8080?token"); + .to("splunk-hec://localhost:8080?token=token"); ------------------------------- If you are ingesting a large enough dataset with a big enough lag then the time @@ -83,13 +83,13 @@ you want to override the index time you can do so. ------------------------------- from("kafka:logs") .setHeader(SplunkHECConstants.INDEX_TIME, simple("${headers[kafka.HEADERS].lastKey('TIME')}")) - .to("splunk-hec://localhost:8080/token"); + .to("splunk-hec://localhost:8080?token=token"); ------------------------------- [source,java] ------------------------------- from("kafka:logs") - .toD("splunk-hec://localhost:8080/token?time=${headers[kafka.HEADERS].lastKey('TIME')}"); + .toD("splunk-hec://localhost:8080?token=token&time=${headers[kafka.HEADERS].lastKey('TIME')}"); ------------------------------- diff --git a/components/camel-splunk-hec/src/main/java/org/apache/camel/component/splunkhec/SplunkHECComponent.java b/components/camel-splunk-hec/src/main/java/org/apache/camel/component/splunkhec/SplunkHECComponent.java index c6a2da5914d..8535f76314b 100644 --- a/components/camel-splunk-hec/src/main/java/org/apache/camel/component/splunkhec/SplunkHECComponent.java +++ b/components/camel-splunk-hec/src/main/java/org/apache/camel/component/splunkhec/SplunkHECComponent.java @@ -21,6 +21,7 @@ import java.util.Map; import org.apache.camel.Endpoint; import org.apache.camel.spi.annotations.Component; import org.apache.camel.support.DefaultComponent; +import org.apache.camel.util.URISupport; @Component("splunk-hec") public class SplunkHECComponent extends DefaultComponent { @@ -30,8 +31,14 @@ public class SplunkHECComponent extends DefaultComponent { @Override protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception { + if (remaining.split("/").length > 1) { + throw new IllegalArgumentException("Invalid URI: " + URISupport.sanitizeUri(uri)); + } + SplunkHECEndpoint answer = new SplunkHECEndpoint(uri, this, new SplunkHECConfiguration()); setProperties(answer, parameters); + answer.setSplunkURL(remaining); + return answer; } } diff --git a/components/camel-splunk-hec/src/main/java/org/apache/camel/component/splunkhec/SplunkHECConfiguration.java b/components/camel-splunk-hec/src/main/java/org/apache/camel/component/splunkhec/SplunkHECConfiguration.java index a3c80454d4a..77bd92856ad 100644 --- a/components/camel-splunk-hec/src/main/java/org/apache/camel/component/splunkhec/SplunkHECConfiguration.java +++ b/components/camel-splunk-hec/src/main/java/org/apache/camel/component/splunkhec/SplunkHECConfiguration.java @@ -18,6 +18,7 @@ package org.apache.camel.component.splunkhec; import java.net.UnknownHostException; +import org.apache.camel.spi.Metadata; import org.apache.camel.spi.UriParam; import org.apache.camel.spi.UriParams; import org.apache.camel.util.HostUtils; @@ -38,6 +39,9 @@ public class SplunkHECConfiguration { private String host; @UriParam(defaultValue = "/services/collector/event") private String splunkEndpoint = "/services/collector/event"; + @UriParam(label = "security", secret = true) + @Metadata(required = true) + private String token; @UriParam(label = "security") private boolean skipTlsVerify; @UriParam(label = "security", defaultValue = "true") @@ -117,6 +121,17 @@ public class SplunkHECConfiguration { return this.splunkEndpoint; } + public String getToken() { + return token; + } + + /** + * Splunk HEC token (this is the token created for HEC and not the user's token) + */ + public void setToken(String token) { + this.token = token; + } + public boolean isSkipTlsVerify() { return skipTlsVerify; } diff --git a/components/camel-splunk-hec/src/main/java/org/apache/camel/component/splunkhec/SplunkHECEndpoint.java b/components/camel-splunk-hec/src/main/java/org/apache/camel/component/splunkhec/SplunkHECEndpoint.java index d60531e9c41..5b3ee8e2858 100644 --- a/components/camel-splunk-hec/src/main/java/org/apache/camel/component/splunkhec/SplunkHECEndpoint.java +++ b/components/camel-splunk-hec/src/main/java/org/apache/camel/component/splunkhec/SplunkHECEndpoint.java @@ -28,7 +28,6 @@ import org.apache.camel.spi.UriEndpoint; import org.apache.camel.spi.UriParam; import org.apache.camel.spi.UriPath; import org.apache.camel.support.DefaultEndpoint; -import org.apache.camel.util.URISupport; import org.apache.commons.validator.routines.DomainValidator; import org.apache.commons.validator.routines.InetAddressValidator; @@ -36,19 +35,17 @@ import org.apache.commons.validator.routines.InetAddressValidator; * The splunk component allows to publish events in Splunk using the HTTP Event Collector. */ @UriEndpoint(firstVersion = "3.3.0", scheme = "splunk-hec", title = "Splunk HEC", producerOnly = true, - syntax = "splunk-hec:splunkURL/token", category = { Category.MONITORING }, + syntax = "splunk-hec:splunkURL", category = { Category.MONITORING }, headersClass = SplunkHECConstants.class) public class SplunkHECEndpoint extends DefaultEndpoint { - private static final Pattern URI_PARSER - = Pattern.compile("splunk-hec\\:\\/?\\/?(.*?):(\\d+)/(\\w{8}-\\w{4}-\\w{4}-\\w{4}-\\w{12})\\??.*"); + private static final Pattern SPLUNK_URL_PATTERN = Pattern.compile("^(.*?):(\\d+)$"); + private static final Pattern SPLUNK_TOKEN_PATTERN = Pattern.compile("^\\w{8}-\\w{4}-\\w{4}-\\w{4}-\\w{12}$"); @UriPath @Metadata(required = true) private String splunkURL; - @UriPath(label = "security", secret = true) - @Metadata(required = true) - private String token; + @UriParam private SplunkHECConfiguration configuration; @@ -58,12 +55,20 @@ public class SplunkHECEndpoint extends DefaultEndpoint { public SplunkHECEndpoint(String uri, SplunkHECComponent component, SplunkHECConfiguration configuration) { super(uri, component); this.configuration = configuration; - Matcher match = URI_PARSER.matcher(uri); - if (!match.matches()) { - throw new IllegalArgumentException("Invalid URI: " + URISupport.sanitizeUri(uri)); + } + + @Override + protected void doInit() throws Exception { + super.doInit(); + + Matcher splunkUrlMatch = SPLUNK_URL_PATTERN.matcher(splunkURL); + + if (!splunkUrlMatch.matches()) { + throw new IllegalArgumentException("Invalid Splunk URL provided"); } - String hostname = match.group(1); - int port = Integer.parseInt(match.group(2)); + + String hostname = splunkUrlMatch.group(1); + int port = Integer.parseInt(splunkUrlMatch.group(2)); if (!DomainValidator.getInstance(true).isValid(hostname) && !InetAddressValidator.getInstance().isValidInet4Address(hostname)) { @@ -72,8 +77,15 @@ public class SplunkHECEndpoint extends DefaultEndpoint { if (port < 1 || port > 65535) { throw new IllegalArgumentException("Invalid port: " + port); } - splunkURL = hostname + ":" + port; - token = match.group(3); + + String token = getConfiguration().getToken(); + if (token == null) { + throw new IllegalArgumentException("A token must be defined"); + } + + if (!SPLUNK_TOKEN_PATTERN.matcher(token).matches()) { + throw new IllegalArgumentException("Invalid Splunk HEC token provided"); + } } @Override @@ -101,15 +113,4 @@ public class SplunkHECEndpoint extends DefaultEndpoint { this.splunkURL = splunkURL; } - public String getToken() { - return token; - } - - /** - * Splunk HEC token (this is the token created for HEC and not the user's token) - */ - public void setToken(String token) { - this.token = token; - } - } diff --git a/components/camel-splunk-hec/src/main/java/org/apache/camel/component/splunkhec/SplunkHECProducer.java b/components/camel-splunk-hec/src/main/java/org/apache/camel/component/splunkhec/SplunkHECProducer.java index b53e2c63025..4d1e05fdf5f 100644 --- a/components/camel-splunk-hec/src/main/java/org/apache/camel/component/splunkhec/SplunkHECProducer.java +++ b/components/camel-splunk-hec/src/main/java/org/apache/camel/component/splunkhec/SplunkHECProducer.java @@ -82,7 +82,7 @@ public class SplunkHECProducer extends DefaultProducer { HttpPost httppost = new HttpPost( (endpoint.getConfiguration().isHttps() ? "https" : "http") + "://" + endpoint.getSplunkURL() + endpoint.getConfiguration().getSplunkEndpoint()); - httppost.addHeader("Authorization", " Splunk " + endpoint.getToken()); + httppost.addHeader("Authorization", " Splunk " + endpoint.getConfiguration().getToken()); EntityTemplate entityTemplate = new EntityTemplate( -1, ContentType.APPLICATION_JSON, null, outputStream -> MAPPER.writer().writeValue(outputStream, payload)); diff --git a/components/camel-splunk-hec/src/test/java/org/apache/camel/component/splunkhec/SplunkHECComponentTest.java b/components/camel-splunk-hec/src/test/java/org/apache/camel/component/splunkhec/SplunkHECComponentTest.java new file mode 100644 index 00000000000..b8de0fd73d9 --- /dev/null +++ b/components/camel-splunk-hec/src/test/java/org/apache/camel/component/splunkhec/SplunkHECComponentTest.java @@ -0,0 +1,148 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.splunkhec; + +import org.apache.camel.Endpoint; +import org.apache.camel.impl.DefaultCamelContext; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; +import org.mockito.Mockito; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class SplunkHECComponentTest { + SplunkHECComponent component; + + @BeforeEach + void setUp() { + component = Mockito.spy(new SplunkHECComponent()); + component.setCamelContext(new DefaultCamelContext()); + Mockito.when(component.getEndpointPropertyConfigurer()).thenReturn(new SplunkHECEndpointConfigurer()); + } + + @Test + public void testInvalidEndpoint() { + assertThrows(Exception.class, () -> component.createEndpoint("")); + } + + @Test + public void testInvalidUriSyntax() { + Exception e = assertThrows(IllegalArgumentException.class, () -> component.createEndpoint( + "splunk-hec:bad/path")); + assertEquals("Invalid URI: splunk-hec:bad/path", e.getMessage()); + } + + @Test + public void testInvalidHostname() throws Exception { + Endpoint endpoint = component.createEndpoint( + "splunk-hec:yo,lo:1234?token=11111111-1111-1111-1111-111111111111"); + Exception e = assertThrows(IllegalArgumentException.class, endpoint::init); + assertEquals("Invalid hostname: yo,lo", e.getMessage()); + } + + @Test + public void testIpAddressValid() throws Exception { + SplunkHECEndpoint endpoint = (SplunkHECEndpoint) component.createEndpoint( + "splunk-hec:192.168.0.1:18808?token=11111111-1111-1111-1111-111111111111"); + endpoint.init(); + assertEquals("192.168.0.1:18808", endpoint.getSplunkURL()); + assertEquals("11111111-1111-1111-1111-111111111111", endpoint.getConfiguration().getToken()); + } + + @Test + public void testLocalHostValid() throws Exception { + SplunkHECEndpoint endpoint = (SplunkHECEndpoint) component.createEndpoint( + "splunk-hec:localhost:18808?token=11111111-1111-1111-1111-111111111111"); + endpoint.init(); + assertEquals("localhost:18808", endpoint.getSplunkURL()); + assertEquals("11111111-1111-1111-1111-111111111111", endpoint.getConfiguration().getToken()); + } + + @Test + public void testFQHNValid() throws Exception { + SplunkHECEndpoint endpoint = (SplunkHECEndpoint) component.createEndpoint( + "splunk-hec:http-input.splunkcloud.com:18808?token=11111111-1111-1111-1111-111111111111"); + endpoint.init(); + assertEquals("http-input.splunkcloud.com:18808", endpoint.getSplunkURL()); + assertEquals("11111111-1111-1111-1111-111111111111", endpoint.getConfiguration().getToken()); + } + + @Test + public void testValidWithOptions() throws Exception { + SplunkHECEndpoint endpoint = (SplunkHECEndpoint) component.createEndpoint( + "splunk-hec:localhost:18808?token=11111111-1111-1111-1111-111111111111&index=foo"); + endpoint.init(); + assertEquals("localhost:18808", endpoint.getSplunkURL()); + assertEquals("11111111-1111-1111-1111-111111111111", endpoint.getConfiguration().getToken()); + assertEquals("foo", endpoint.getConfiguration().getIndex()); + } + + @Test + public void testInvalidPort() throws Exception { + Endpoint endpoint = component.createEndpoint( + "splunk-hec:yolo:188508?token=11111111-1111-1111-1111-111111111111"); + Exception e = assertThrows(IllegalArgumentException.class, endpoint::init); + assertEquals("Invalid port: 188508", e.getMessage()); + } + + @Test + public void testSplunkURLIsNotOverriddenByQuery() throws Exception { + SplunkHECEndpoint endpoint = (SplunkHECEndpoint) component.createEndpoint( + "splunk-hec:192.168.0.1:18808?token=11111111-1111-1111-1111-111111111111&splunkURL=ignored"); + assertEquals("192.168.0.1:18808", endpoint.getSplunkURL()); + endpoint.init(); + assertEquals("192.168.0.1:18808", endpoint.getSplunkURL()); + } + + @Test + public void testMissingToken() throws Exception { + Endpoint endpoint = component.createEndpoint("splunk-hec:localhost:18808"); + Exception e = assertThrows(IllegalArgumentException.class, endpoint::init); + assertEquals("A token must be defined", e.getMessage()); + } + + @ParameterizedTest + @ValueSource(strings = { "", "bad-token" }) + public void testInvalidToken(String token) throws Exception { + Endpoint endpoint = component.createEndpoint( + "splunk-hec:localhost:18808?token=" + token); + Exception e = assertThrows(IllegalArgumentException.class, endpoint::init); + assertEquals("Invalid Splunk HEC token provided", e.getMessage()); + } + + @Test + public void testTokenValid() throws Exception { + SplunkHECEndpoint endpoint = (SplunkHECEndpoint) component.createEndpoint( + "splunk-hec:localhost:18808?token=11111111-1111-1111-1111-111111111111"); + endpoint.init(); + assertEquals("11111111-1111-1111-1111-111111111111", endpoint.getConfiguration().getToken()); + } + + @Test + public void testSanitizedException() { + String tokenValue = "token-value"; + Exception e = assertThrows(IllegalArgumentException.class, () -> component.createEndpoint( + "splunk-hec:bad/path?token=" + tokenValue)); + assertTrue(e.getMessage().contains("token=xxxxxx")); + assertFalse(e.getMessage().contains(tokenValue)); + } +} diff --git a/components/camel-splunk-hec/src/test/java/org/apache/camel/component/splunkhec/SplunkHECConfigurationTest.java b/components/camel-splunk-hec/src/test/java/org/apache/camel/component/splunkhec/SplunkHECConfigurationTest.java index a83dcdc9e59..93a3b02d729 100644 --- a/components/camel-splunk-hec/src/test/java/org/apache/camel/component/splunkhec/SplunkHECConfigurationTest.java +++ b/components/camel-splunk-hec/src/test/java/org/apache/camel/component/splunkhec/SplunkHECConfigurationTest.java @@ -63,6 +63,12 @@ public class SplunkHECConfigurationTest { assertEquals("camel", config.getSourceType()); } + @Test + public void testDefaultToken() { + SplunkHECConfiguration config = new SplunkHECConfiguration(); + assertNull(config.getToken()); + } + @Test public void testDefaultSkipTlsVerifyIsFalse() { SplunkHECConfiguration config = new SplunkHECConfiguration(); diff --git a/components/camel-splunk-hec/src/test/java/org/apache/camel/component/splunkhec/SplunkHECEndpointTest.java b/components/camel-splunk-hec/src/test/java/org/apache/camel/component/splunkhec/SplunkHECEndpointTest.java deleted file mode 100644 index 89d9cc8166a..00000000000 --- a/components/camel-splunk-hec/src/test/java/org/apache/camel/component/splunkhec/SplunkHECEndpointTest.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.component.splunkhec; - -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; - -public class SplunkHECEndpointTest { - @Test - public void testInvalidEndpoint() { - SplunkHECConfiguration configuration = new SplunkHECConfiguration(); - SplunkHECComponent component = new SplunkHECComponent(); - assertThrows(IllegalArgumentException.class, () -> new SplunkHECEndpoint("", component, configuration)); - } - - @Test - public void testInvalidURL() { - SplunkHECConfiguration configuration = new SplunkHECConfiguration(); - SplunkHECComponent component = new SplunkHECComponent(); - assertThrows(IllegalArgumentException.class, () -> new SplunkHECEndpoint( - "splunk-hec:yo,lo:1234/11111111-1111-1111-1111-111111111111", component, configuration)); - } - - @Test - public void testIpAddressValid() { - SplunkHECConfiguration configuration = new SplunkHECConfiguration(); - SplunkHECComponent component = new SplunkHECComponent(); - SplunkHECEndpoint endpoint = new SplunkHECEndpoint( - "splunk-hec:192.168.0.1:18808/11111111-1111-1111-1111-111111111111", component, configuration); - assertEquals("192.168.0.1:18808", endpoint.getSplunkURL()); - assertEquals("11111111-1111-1111-1111-111111111111", endpoint.getToken()); - } - - @Test - public void testLocalHostValid() { - SplunkHECConfiguration configuration = new SplunkHECConfiguration(); - SplunkHECComponent component = new SplunkHECComponent(); - SplunkHECEndpoint endpoint = new SplunkHECEndpoint( - "splunk-hec:localhost:18808/11111111-1111-1111-1111-111111111111", component, configuration); - assertEquals("localhost:18808", endpoint.getSplunkURL()); - assertEquals("11111111-1111-1111-1111-111111111111", endpoint.getToken()); - } - - @Test - public void testFQHNValid() { - SplunkHECConfiguration configuration = new SplunkHECConfiguration(); - SplunkHECComponent component = new SplunkHECComponent(); - SplunkHECEndpoint endpoint = new SplunkHECEndpoint( - "splunk-hec:http-input.splunkcloud.com:18808/11111111-1111-1111-1111-111111111111", component, configuration); - assertEquals("http-input.splunkcloud.com:18808", endpoint.getSplunkURL()); - assertEquals("11111111-1111-1111-1111-111111111111", endpoint.getToken()); - } - - @Test - public void testValidWithOptions() { - SplunkHECConfiguration configuration = new SplunkHECConfiguration(); - SplunkHECComponent component = new SplunkHECComponent(); - SplunkHECEndpoint endpoint = new SplunkHECEndpoint( - "splunk-hec:localhost:18808/11111111-1111-1111-1111-111111111111?index=foo", component, configuration); - assertEquals("localhost:18808", endpoint.getSplunkURL()); - assertEquals("11111111-1111-1111-1111-111111111111", endpoint.getToken()); - } - - @Test - public void testInvalidPort() { - SplunkHECConfiguration configuration = new SplunkHECConfiguration(); - SplunkHECComponent component = new SplunkHECComponent(); - Exception e = assertThrows(IllegalArgumentException.class, () -> new SplunkHECEndpoint( - "splunk-hec:yolo:188508/11111111-1111-1111-1111-111111111111", component, configuration)); - assertEquals("Invalid port: 188508", e.getMessage()); - } - - @Test - public void testSanitizedException() { - SplunkHECConfiguration configuration = new SplunkHECConfiguration(); - SplunkHECComponent component = new SplunkHECComponent(); - String tokenValue = "token-value"; - Exception e = assertThrows(IllegalArgumentException.class, () -> new SplunkHECEndpoint( - "splunk-hec:localhost/11111111-1111-1111-1111-111111111111?token=" + tokenValue, component, - configuration)); - assertTrue(e.getMessage().contains("token=xxxxxx")); - assertFalse(e.getMessage().contains(tokenValue)); - } -} diff --git a/components/camel-splunk-hec/src/test/java/org/apache/camel/component/splunkhec/integration/SplunkHECITManualTest.java b/components/camel-splunk-hec/src/test/java/org/apache/camel/component/splunkhec/integration/SplunkHECITManualTest.java index a7e99a6af56..bfedf677899 100644 --- a/components/camel-splunk-hec/src/test/java/org/apache/camel/component/splunkhec/integration/SplunkHECITManualTest.java +++ b/components/camel-splunk-hec/src/test/java/org/apache/camel/component/splunkhec/integration/SplunkHECITManualTest.java @@ -18,16 +18,12 @@ package org.apache.camel.component.splunkhec.integration; import java.util.Collections; -import org.apache.camel.CamelContext; import org.apache.camel.Exchange; import org.apache.camel.RoutesBuilder; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.component.mock.MockEndpoint; -import org.apache.camel.component.splunkhec.SplunkHECComponent; -import org.apache.camel.component.splunkhec.SplunkHECConfiguration; import org.apache.camel.component.splunkhec.SplunkHECEndpoint; import org.apache.camel.component.splunkhec.SplunkHECProducer; -import org.apache.camel.impl.DefaultCamelContext; import org.apache.camel.support.DefaultExchange; import org.apache.camel.support.DefaultMessage; import org.apache.camel.test.junit5.CamelTestSupport; @@ -41,35 +37,31 @@ public class SplunkHECITManualTest extends CamelTestSupport { @Test public void testSendHEC() throws Exception { - CamelContext ctx = new DefaultCamelContext(); + SplunkHECEndpoint endpoint = getMandatoryEndpoint( + "splunk-hec:localhost:8088?token=4b35e71f-6a0f-4bab-94ce-f591ff45eecd", SplunkHECEndpoint.class); + assertEquals("4b35e71f-6a0f-4bab-94ce-f591ff45eecd", endpoint.getConfiguration().getToken()); + endpoint.getConfiguration().setSkipTlsVerify(true); + endpoint.getConfiguration().setIndex("camel"); + endpoint.getConfiguration().setSource("camel"); + endpoint.getConfiguration().setSourceType("camel"); - SplunkHECConfiguration configuration = new SplunkHECConfiguration(); - configuration.setSkipTlsVerify(true); - configuration.setIndex("camel"); - configuration.setSource("camel"); - configuration.setSourceType("camel"); - SplunkHECComponent component = new SplunkHECComponent(); - SplunkHECEndpoint endpoint = new SplunkHECEndpoint( - "splunk-hec:localhost:8088/4b35e71f-6a0f-4bab-94ce-f591ff45eecd", component, configuration); - assertEquals("4b35e71f-6a0f-4bab-94ce-f591ff45eecd", endpoint.getToken()); - endpoint.setCamelContext(ctx); SplunkHECProducer producer = new SplunkHECProducer(endpoint); producer.start(); - Exchange ex = new DefaultExchange(ctx); + Exchange ex = new DefaultExchange(context()); DefaultMessage message = new DefaultMessage(ex); message.setBody("TEST sending to Splunk"); message.setHeader("foo", "bar"); ex.setIn(message); producer.process(ex); - Exchange ex2 = new DefaultExchange(ctx); + Exchange ex2 = new DefaultExchange(context()); DefaultMessage message2 = new DefaultMessage(ex2); message2.setBody(Collections.singletonMap("key", "value")); ex2.setIn(message2); producer.process(ex2); - Exchange ex3 = new DefaultExchange(ctx); + Exchange ex3 = new DefaultExchange(context()); DefaultMessage message3 = new DefaultMessage(ex3); message3.setBody(null); ex3.setIn(message3); @@ -92,7 +84,7 @@ public class SplunkHECITManualTest extends CamelTestSupport { return new RouteBuilder() { public void configure() { from("direct:hec").to( - "splunk-hec:localhost:8088/4b35e71f-6a0f-4bab-94ce-f591ff45eecd?source=camelsource&skipTlsVerify=true") + "splunk-hec:localhost:8088?token=4b35e71f-6a0f-4bab-94ce-f591ff45eecd&source=camelsource&skipTlsVerify=true") .to("mock:hec-result"); } }; diff --git a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_4.adoc b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_4.adoc index fb4d2d9aa75..916fe1f59ae 100644 --- a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_4.adoc +++ b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_4.adoc @@ -154,6 +154,10 @@ The component now has support for batch processing. Removed deprecated `org.apache.camel.component.jsonvalidator.DefaultJsonSchemaLoader`, use `org.apache.camel.component.jsonvalidator.DefaultJsonUriSchemaLoader` instead. +=== camel-splunk-hec + +Removed `token` from the URI's path in favor of setting it through a `token` query parameter. While the `token` was in the URI path, it could potentially be leaked within the logs. + == Camel Spring Boot