This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push:
new 6c65c95 CAMEL-15031: Accept FQHN for splunk-hec endpoint (#3811)
6c65c95 is described below
commit 6c65c952702c6c5cba1c47bb43fffef9d2fef6ce
Author: Mario Rutz <[email protected]>
AuthorDate: Fri May 8 17:45:50 2020 +0200
CAMEL-15031: Accept FQHN for splunk-hec endpoint (#3811)
* CAMEL-15031: Accept FQHN for endpoint
* CAMEL-15031: Tidy up regex for rough endpoint domain matching
Co-authored-by: Mario Rutz <[email protected]>
---
components/camel-splunk-hec/pom.xml | 5 +++++
.../apache/camel/component/splunkhec/SplunkHECEndpoint.java | 5 +++--
.../camel/component/splunkhec/SplunkHECEndpointTest.java | 11 ++++++++++-
parent/pom.xml | 1 +
4 files changed, 19 insertions(+), 3 deletions(-)
diff --git a/components/camel-splunk-hec/pom.xml
b/components/camel-splunk-hec/pom.xml
index 3242a10..2cbd881 100644
--- a/components/camel-splunk-hec/pom.xml
+++ b/components/camel-splunk-hec/pom.xml
@@ -46,6 +46,11 @@
<artifactId>httpclient</artifactId>
<version>${httpclient4-version}</version>
</dependency>
+ <dependency>
+ <groupId>commons-validator</groupId>
+ <artifactId>commons-validator</artifactId>
+ <version>${commons-validator-version}</version>
+ </dependency>
<!-- testing -->
<dependency>
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 240e72a..c9a4c9d 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
@@ -27,6 +27,7 @@ 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.commons.validator.routines.DomainValidator;
/**
* The splunk component allows to publish events in Splunk using the HTTP
Event Collector.
@@ -35,7 +36,7 @@ import org.apache.camel.support.DefaultEndpoint;
syntax = "splunk-hec:splunkURL/token", label = "log,monitoring")
public class SplunkHECEndpoint extends DefaultEndpoint {
- private static final Pattern URI_PARSER =
Pattern.compile("splunk-hec\\:\\/?\\/?(\\w+):(\\d+)/(\\w{8}-\\w{4}-\\w{4}-\\w{4}-\\w{12})\\??.*");
+ private static final Pattern URI_PARSER =
Pattern.compile("splunk-hec\\:\\/?\\/?(.*?):(\\d+)/(\\w{8}-\\w{4}-\\w{4}-\\w{4}-\\w{12})\\??.*");
@UriPath @Metadata(required = true)
private String splunkURL;
@@ -51,7 +52,7 @@ public class SplunkHECEndpoint extends DefaultEndpoint {
super(uri, component);
this.configuration = configuration;
Matcher match = URI_PARSER.matcher(uri);
- if (!match.matches()) {
+ if (!match.matches() ||
!DomainValidator.getInstance(true).isValid(match.group(1))) {
throw new IllegalArgumentException("Invalid URI: " + uri);
}
int port = Integer.parseInt(match.group(2));
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
index f14b495..ef535df 100644
---
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
@@ -37,7 +37,7 @@ public class SplunkHECEndpointTest {
}
@Test
- public void testValid() {
+ 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);
@@ -46,6 +46,15 @@ public class SplunkHECEndpointTest {
}
@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();
diff --git a/parent/pom.xml b/parent/pom.xml
index 87b871a..6f236c7 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -126,6 +126,7 @@
<commons-pool-version>1.6</commons-pool-version>
<commons-pool2-version>2.8.0</commons-pool2-version>
<commons-text-version>1.8</commons-text-version>
+ <commons-validator-version>1.4.1</commons-validator-version>
<compress-lzf-version>1.0.4</compress-lzf-version>
<conscrypt-uber-version>2.2.1</conscrypt-uber-version>
<consul-client-version>1.3.3</consul-client-version>