This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch ra in repository https://gitbox.apache.org/repos/asf/camel.git
commit 3d4ff397cef73dee3a4db05cee17a5c7fc129f67 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Sat May 25 10:07:41 2024 +0200 CAMEL-20798: Add RemoteAddress to endpoints so they can tell the url/hostname etc for the system it connects. This is needed for better monitoring, tracing and management. Add this information into camel-tracer as tags. --- .../camel/component/rocketmq/RocketMQEndpoint.java | 8 ++++++- .../component/sap/netweaver/NetWeaverEndpoint.java | 18 ++++++++++++++- .../apache/camel/component/smb/SmbEndpoint.java | 22 +++++++++++++++++- .../apache/camel/component/smpp/SmppEndpoint.java | 8 ++++++- .../apache/camel/component/snmp/SnmpEndpoint.java | 26 +++++++++++++++------- .../apache/camel/component/snmp/SnmpHelper.java | 4 ++-- .../apache/camel/component/snmp/SnmpOIDPoller.java | 8 +++---- .../apache/camel/component/snmp/SnmpProducer.java | 4 ++-- .../camel/component/snmp/SnmpTrapConsumer.java | 14 ++++++------ .../camel/component/snmp/SnmpTrapProducer.java | 4 ++-- .../camel/component/snmp/UriConfigurationTest.java | 6 ++--- .../splunkhec/SplunkHECConfiguration.java | 3 ++- .../component/splunkhec/SplunkHECEndpoint.java | 8 ++++++- .../camel/component/splunk/SplunkEndpoint.java | 19 ++++++++++++++-- .../camel/component/splunk/SplunkProducer.java | 2 +- .../component/splunk/support/StreamDataWriter.java | 6 ++--- .../camel/component/redis/RedisEndpoint.java | 10 +++++++-- .../apache/camel/component/ssh/SshEndpoint.java | 18 ++++++++++++++- 18 files changed, 145 insertions(+), 43 deletions(-) diff --git a/components/camel-rocketmq/src/main/java/org/apache/camel/component/rocketmq/RocketMQEndpoint.java b/components/camel-rocketmq/src/main/java/org/apache/camel/component/rocketmq/RocketMQEndpoint.java index a77ec99f018..dd76eba6062 100644 --- a/components/camel-rocketmq/src/main/java/org/apache/camel/component/rocketmq/RocketMQEndpoint.java +++ b/components/camel-rocketmq/src/main/java/org/apache/camel/component/rocketmq/RocketMQEndpoint.java @@ -23,6 +23,7 @@ import org.apache.camel.Consumer; import org.apache.camel.Exchange; import org.apache.camel.Processor; import org.apache.camel.Producer; +import org.apache.camel.spi.EndpointLocationAddress; import org.apache.camel.spi.Metadata; import org.apache.camel.spi.UriEndpoint; import org.apache.camel.spi.UriParam; @@ -35,7 +36,7 @@ import org.apache.camel.support.DefaultMessage; */ @UriEndpoint(firstVersion = "3.20.0", scheme = "rocketmq", syntax = "rocketmq:topicName", title = "RocketMQ", category = Category.MESSAGING, headersClass = RocketMQConstants.class) -public class RocketMQEndpoint extends DefaultEndpoint implements AsyncEndpoint { +public class RocketMQEndpoint extends DefaultEndpoint implements AsyncEndpoint, EndpointLocationAddress { @UriPath @Metadata(required = true) @@ -72,6 +73,11 @@ public class RocketMQEndpoint extends DefaultEndpoint implements AsyncEndpoint { super(endpointUri, component); } + @Override + public String getAddress() { + return namesrvAddr; + } + @Override public Producer createProducer() { return new RocketMQProducer(this); diff --git a/components/camel-sap-netweaver/src/main/java/org/apache/camel/component/sap/netweaver/NetWeaverEndpoint.java b/components/camel-sap-netweaver/src/main/java/org/apache/camel/component/sap/netweaver/NetWeaverEndpoint.java index cbd862bf686..1b2e745bc13 100644 --- a/components/camel-sap-netweaver/src/main/java/org/apache/camel/component/sap/netweaver/NetWeaverEndpoint.java +++ b/components/camel-sap-netweaver/src/main/java/org/apache/camel/component/sap/netweaver/NetWeaverEndpoint.java @@ -21,19 +21,22 @@ import org.apache.camel.Component; import org.apache.camel.Consumer; import org.apache.camel.Processor; import org.apache.camel.Producer; +import org.apache.camel.spi.EndpointLocationAddress; import org.apache.camel.spi.Metadata; 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 java.util.Map; + /** * Send requests to SAP NetWeaver Gateway using HTTP. */ @UriEndpoint(firstVersion = "2.12.0", scheme = "sap-netweaver", title = "SAP NetWeaver", syntax = "sap-netweaver:url", producerOnly = true, category = { Category.SAAS }, headersClass = NetWeaverConstants.class) -public class NetWeaverEndpoint extends DefaultEndpoint { +public class NetWeaverEndpoint extends DefaultEndpoint implements EndpointLocationAddress { @UriPath @Metadata(required = true) @@ -55,6 +58,19 @@ public class NetWeaverEndpoint extends DefaultEndpoint { super(endpointUri, component); } + @Override + public String getAddress() { + return url; + } + + @Override + public Map<String, String> getAddressMetadata() { + if (username != null) { + return Map.of("username", username); + } + return null; + } + @Override public Producer createProducer() throws Exception { return new NetWeaverProducer(this); diff --git a/components/camel-smb/src/main/java/org/apache/camel/component/smb/SmbEndpoint.java b/components/camel-smb/src/main/java/org/apache/camel/component/smb/SmbEndpoint.java index 5fae5eca5fd..93b938cea3d 100644 --- a/components/camel-smb/src/main/java/org/apache/camel/component/smb/SmbEndpoint.java +++ b/components/camel-smb/src/main/java/org/apache/camel/component/smb/SmbEndpoint.java @@ -20,19 +20,22 @@ import org.apache.camel.Category; import org.apache.camel.Consumer; import org.apache.camel.Processor; import org.apache.camel.Producer; +import org.apache.camel.spi.EndpointLocationAddress; import org.apache.camel.spi.Metadata; import org.apache.camel.spi.UriEndpoint; import org.apache.camel.spi.UriParam; import org.apache.camel.spi.UriPath; import org.apache.camel.support.ScheduledPollEndpoint; +import java.util.Map; + /** * Receive files from SMB (Server Message Block) shares. */ @UriEndpoint(firstVersion = "4.3.0", scheme = "smb", title = "SMB", syntax = "smb:hostname:port/shareName", consumerOnly = true, category = { Category.FILE }) -public class SmbEndpoint extends ScheduledPollEndpoint { +public class SmbEndpoint extends ScheduledPollEndpoint implements EndpointLocationAddress { @UriPath @Metadata(required = true) @@ -53,6 +56,23 @@ public class SmbEndpoint extends ScheduledPollEndpoint { super(uri, component); } + @Override + public String getAddress() { + if (port != 0) { + return hostname + ":" + port; + } else { + return hostname; + } + } + + @Override + public Map<String, String> getAddressMetadata() { + if (configuration.getUsername() != null) { + return Map.of("username", configuration.getUsername()); + } + return null; + } + @Override public Producer createProducer() { throw new UnsupportedOperationException("SMB producer is not supported."); diff --git a/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppEndpoint.java b/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppEndpoint.java index ab4dc6032a0..98e9eb47e56 100644 --- a/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppEndpoint.java +++ b/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppEndpoint.java @@ -23,6 +23,7 @@ import org.apache.camel.Exchange; import org.apache.camel.ExchangePattern; import org.apache.camel.Processor; import org.apache.camel.Producer; +import org.apache.camel.spi.EndpointLocationAddress; import org.apache.camel.spi.UriEndpoint; import org.apache.camel.spi.UriParam; import org.apache.camel.support.DefaultEndpoint; @@ -34,7 +35,7 @@ import org.jsmpp.bean.DeliverSm; */ @UriEndpoint(firstVersion = "2.2.0", scheme = "smpp,smpps", title = "SMPP", syntax = "smpp:host:port", category = { Category.MOBILE }, lenientProperties = true, headersClass = SmppConstants.class) -public class SmppEndpoint extends DefaultEndpoint { +public class SmppEndpoint extends DefaultEndpoint implements EndpointLocationAddress { private SmppBinding binding; @UriParam @@ -45,6 +46,11 @@ public class SmppEndpoint extends DefaultEndpoint { this.configuration = configuration; } + @Override + public String getAddress() { + return configuration.getHost() + ":" + configuration.getPort(); + } + @Override protected String createEndpointUri() { return getConnectionString(); diff --git a/components/camel-snmp/src/main/java/org/apache/camel/component/snmp/SnmpEndpoint.java b/components/camel-snmp/src/main/java/org/apache/camel/component/snmp/SnmpEndpoint.java index d0500702ce2..9fccaebe9ca 100644 --- a/components/camel-snmp/src/main/java/org/apache/camel/component/snmp/SnmpEndpoint.java +++ b/components/camel-snmp/src/main/java/org/apache/camel/component/snmp/SnmpEndpoint.java @@ -23,6 +23,7 @@ import org.apache.camel.Consumer; import org.apache.camel.Exchange; import org.apache.camel.Processor; import org.apache.camel.Producer; +import org.apache.camel.spi.EndpointLocationAddress; import org.apache.camel.spi.Metadata; import org.apache.camel.spi.UriEndpoint; import org.apache.camel.spi.UriParam; @@ -39,7 +40,7 @@ import org.snmp4j.security.SecurityLevel; */ @UriEndpoint(firstVersion = "2.1.0", scheme = "snmp", title = "SNMP", syntax = "snmp:host:port", category = { Category.MONITORING }) -public class SnmpEndpoint extends DefaultPollingEndpoint { +public class SnmpEndpoint extends DefaultPollingEndpoint implements EndpointLocationAddress { public static final String DEFAULT_COMMUNITY = "public"; public static final int DEFAULT_SNMP_VERSION = SnmpConstants.version1; @@ -48,7 +49,7 @@ public class SnmpEndpoint extends DefaultPollingEndpoint { private static final Logger LOG = LoggerFactory.getLogger(SnmpEndpoint.class); - private transient String address; + private transient String serverAddress; @UriPath(description = "Hostname of the SNMP enabled device") @Metadata(required = true) @@ -103,6 +104,15 @@ public class SnmpEndpoint extends DefaultPollingEndpoint { super.setDelay(60000); } + @Override + public String getAddress() { + if (port != null) { + return host + ":" + port; + } else { + return host; + } + } + @Override public Consumer createConsumer(Processor processor) throws Exception { if (this.type == SnmpActionType.TRAP) { @@ -174,12 +184,12 @@ public class SnmpEndpoint extends DefaultPollingEndpoint { this.oids = oids; } - public String getAddress() { - return this.address; + public String getServerAddress() { + return this.serverAddress; } - public void setAddress(String address) { - this.address = address; + public void setServerAddress(String serverAddress) { + this.serverAddress = serverAddress; } public int getRetries() { @@ -260,7 +270,7 @@ public class SnmpEndpoint extends DefaultPollingEndpoint { // set the address String address = String.format("%s:%s/%d", getProtocol(), host, port); LOG.debug("Using snmp address {}", address); - setAddress(address); + setServerAddress(address); } public int getSecurityLevel() { @@ -378,6 +388,6 @@ public class SnmpEndpoint extends DefaultPollingEndpoint { @Override public String toString() { // only show address to avoid user and password details to be shown - return "snmp://" + address; + return "snmp://" + serverAddress; } } diff --git a/components/camel-snmp/src/main/java/org/apache/camel/component/snmp/SnmpHelper.java b/components/camel-snmp/src/main/java/org/apache/camel/component/snmp/SnmpHelper.java index cc1d29e1ea0..ee2636af0dd 100644 --- a/components/camel-snmp/src/main/java/org/apache/camel/component/snmp/SnmpHelper.java +++ b/components/camel-snmp/src/main/java/org/apache/camel/component/snmp/SnmpHelper.java @@ -116,7 +116,7 @@ final class SnmpHelper { CommunityTarget communityTarget = new CommunityTarget(); communityTarget.setCommunity(convertToOctetString(endpoint.getSnmpCommunity())); - communityTarget.setAddress(GenericAddress.parse(endpoint.getAddress())); + communityTarget.setAddress(GenericAddress.parse(endpoint.getServerAddress())); communityTarget.setRetries(endpoint.getRetries()); communityTarget.setTimeout(endpoint.getTimeout()); communityTarget.setVersion(endpoint.getSnmpVersion()); @@ -129,7 +129,7 @@ final class SnmpHelper { userTarget.setSecurityLevel(endpoint.getSecurityLevel()); userTarget.setSecurityName(convertToOctetString(endpoint.getSecurityName())); - userTarget.setAddress(GenericAddress.parse(endpoint.getAddress())); + userTarget.setAddress(GenericAddress.parse(endpoint.getServerAddress())); userTarget.setRetries(endpoint.getRetries()); userTarget.setTimeout(endpoint.getTimeout()); userTarget.setVersion(endpoint.getSnmpVersion()); diff --git a/components/camel-snmp/src/main/java/org/apache/camel/component/snmp/SnmpOIDPoller.java b/components/camel-snmp/src/main/java/org/apache/camel/component/snmp/SnmpOIDPoller.java index f93017024ca..71a24ebe25a 100644 --- a/components/camel-snmp/src/main/java/org/apache/camel/component/snmp/SnmpOIDPoller.java +++ b/components/camel-snmp/src/main/java/org/apache/camel/component/snmp/SnmpOIDPoller.java @@ -60,7 +60,7 @@ public class SnmpOIDPoller extends ScheduledPollConsumer implements ResponseList protected void doStart() throws Exception { super.doStart(); - this.targetAddress = GenericAddress.parse(this.endpoint.getAddress()); + this.targetAddress = GenericAddress.parse(this.endpoint.getServerAddress()); // either tcp or udp if ("tcp".equals(endpoint.getProtocol())) { @@ -78,11 +78,11 @@ public class SnmpOIDPoller extends ScheduledPollConsumer implements ResponseList // listen to the transport if (LOG.isDebugEnabled()) { - LOG.debug("Starting OID poller on {} using {} protocol", endpoint.getAddress(), endpoint.getProtocol()); + LOG.debug("Starting OID poller on {} using {} protocol", endpoint.getServerAddress(), endpoint.getProtocol()); } this.transport.listen(); if (LOG.isInfoEnabled()) { - LOG.info("Started OID poller on {} using {} protocol", endpoint.getAddress(), endpoint.getProtocol()); + LOG.info("Started OID poller on {} using {} protocol", endpoint.getServerAddress(), endpoint.getProtocol()); } } @@ -169,7 +169,7 @@ public class SnmpOIDPoller extends ScheduledPollConsumer implements ResponseList */ public void processPDU(PDU pdu) { if (LOG.isDebugEnabled()) { - LOG.debug("Received response event for {} : {}", this.endpoint.getAddress(), pdu); + LOG.debug("Received response event for {} : {}", this.endpoint.getServerAddress(), pdu); } Exchange exchange = endpoint.createExchange(pdu); try { diff --git a/components/camel-snmp/src/main/java/org/apache/camel/component/snmp/SnmpProducer.java b/components/camel-snmp/src/main/java/org/apache/camel/component/snmp/SnmpProducer.java index 06d94674bf7..e48532bbddb 100644 --- a/components/camel-snmp/src/main/java/org/apache/camel/component/snmp/SnmpProducer.java +++ b/components/camel-snmp/src/main/java/org/apache/camel/component/snmp/SnmpProducer.java @@ -65,7 +65,7 @@ public class SnmpProducer extends DefaultProducer { protected void doStart() throws Exception { super.doStart(); - this.targetAddress = GenericAddress.parse(this.endpoint.getAddress()); + this.targetAddress = GenericAddress.parse(this.endpoint.getServerAddress()); LOG.debug("targetAddress: {}", targetAddress); this.usm = SnmpHelper.createAndSetUSM(endpoint); @@ -115,7 +115,7 @@ public class SnmpProducer extends DefaultProducer { TransportMapping<? extends Address> transport = null; try { - LOG.debug("Starting SNMP producer on {}", this.endpoint.getAddress()); + LOG.debug("Starting SNMP producer on {}", this.endpoint.getServerAddress()); // either tcp or udp if ("tcp".equals(this.endpoint.getProtocol())) { diff --git a/components/camel-snmp/src/main/java/org/apache/camel/component/snmp/SnmpTrapConsumer.java b/components/camel-snmp/src/main/java/org/apache/camel/component/snmp/SnmpTrapConsumer.java index 297dac6f3ba..1ea9f2e28fb 100644 --- a/components/camel-snmp/src/main/java/org/apache/camel/component/snmp/SnmpTrapConsumer.java +++ b/components/camel-snmp/src/main/java/org/apache/camel/component/snmp/SnmpTrapConsumer.java @@ -54,10 +54,10 @@ public class SnmpTrapConsumer extends DefaultConsumer implements CommandResponde // load connection data only if the endpoint is enabled if (LOG.isInfoEnabled()) { - LOG.info("Starting trap consumer on {}", this.endpoint.getAddress()); + LOG.info("Starting trap consumer on {}", this.endpoint.getServerAddress()); } - Address listenGenericAddress = GenericAddress.parse(this.endpoint.getAddress()); + Address listenGenericAddress = GenericAddress.parse(this.endpoint.getServerAddress()); // either tcp or udp if ("tcp".equals(endpoint.getProtocol())) { @@ -73,11 +73,11 @@ public class SnmpTrapConsumer extends DefaultConsumer implements CommandResponde // listen to the transport if (LOG.isDebugEnabled()) { - LOG.debug("Starting trap consumer on {} using {} protocol", endpoint.getAddress(), endpoint.getProtocol()); + LOG.debug("Starting trap consumer on {} using {} protocol", endpoint.getServerAddress(), endpoint.getProtocol()); } this.transport.listen(); if (LOG.isInfoEnabled()) { - LOG.info("Started trap consumer on {} using {} protocol", endpoint.getAddress(), endpoint.getProtocol()); + LOG.info("Started trap consumer on {} using {} protocol", endpoint.getServerAddress(), endpoint.getProtocol()); } } @@ -86,10 +86,10 @@ public class SnmpTrapConsumer extends DefaultConsumer implements CommandResponde // stop listening to the transport if (this.transport != null && this.transport.isListening()) { if (LOG.isDebugEnabled()) { - LOG.debug("Stopping trap consumer on {}", this.endpoint.getAddress()); + LOG.debug("Stopping trap consumer on {}", this.endpoint.getServerAddress()); } this.transport.close(); - LOG.info("Stopped trap consumer on {}", this.endpoint.getAddress()); + LOG.info("Stopped trap consumer on {}", this.endpoint.getServerAddress()); } super.doStop(); @@ -133,7 +133,7 @@ public class SnmpTrapConsumer extends DefaultConsumer implements CommandResponde public void processPDU(PDU pdu, CommandResponderEvent event) { if (LOG.isDebugEnabled()) { - LOG.debug("Received trap event for {} : {}", this.endpoint.getAddress(), pdu); + LOG.debug("Received trap event for {} : {}", this.endpoint.getServerAddress(), pdu); } Exchange exchange = createExchange(pdu, event); try { diff --git a/components/camel-snmp/src/main/java/org/apache/camel/component/snmp/SnmpTrapProducer.java b/components/camel-snmp/src/main/java/org/apache/camel/component/snmp/SnmpTrapProducer.java index 7ddb7133443..b55ba2fd204 100644 --- a/components/camel-snmp/src/main/java/org/apache/camel/component/snmp/SnmpTrapProducer.java +++ b/components/camel-snmp/src/main/java/org/apache/camel/component/snmp/SnmpTrapProducer.java @@ -55,7 +55,7 @@ public class SnmpTrapProducer extends DefaultProducer { protected void doStart() throws Exception { super.doStart(); - this.targetAddress = GenericAddress.parse(this.endpoint.getAddress()); + this.targetAddress = GenericAddress.parse(this.endpoint.getServerAddress()); LOG.debug("targetAddress: {}", targetAddress); this.usm = SnmpHelper.createAndSetUSM(endpoint); @@ -84,7 +84,7 @@ public class SnmpTrapProducer extends DefaultProducer { TransportMapping<? extends Address> transport = null; try { - LOG.debug("Starting SNMP Trap producer on {}", this.endpoint.getAddress()); + LOG.debug("Starting SNMP Trap producer on {}", this.endpoint.getServerAddress()); // either tcp or udp if ("tcp".equals(this.endpoint.getProtocol())) { diff --git a/components/camel-snmp/src/test/java/org/apache/camel/component/snmp/UriConfigurationTest.java b/components/camel-snmp/src/test/java/org/apache/camel/component/snmp/UriConfigurationTest.java index a08dc61f110..6a9c9b9ce92 100644 --- a/components/camel-snmp/src/test/java/org/apache/camel/component/snmp/UriConfigurationTest.java +++ b/components/camel-snmp/src/test/java/org/apache/camel/component/snmp/UriConfigurationTest.java @@ -37,7 +37,7 @@ public class UriConfigurationTest { assertEquals(SnmpActionType.TRAP, snmpEndpoint.getType()); assertEquals("1.3.6.1.2.1.7.5.1", snmpEndpoint.getOids().get(0).toString()); - assertEquals("udp:0.0.0.0/1662", snmpEndpoint.getAddress()); + assertEquals("udp:0.0.0.0/1662", snmpEndpoint.getServerAddress()); } @Test @@ -50,7 +50,7 @@ public class UriConfigurationTest { assertEquals(SnmpActionType.TRAP, snmpEndpoint.getType()); assertEquals("1.3.6.1.2.1.7.5.1", snmpEndpoint.getOids().get(0).toString()); - assertEquals("udp:0.0.0.0/162", snmpEndpoint.getAddress()); + assertEquals("udp:0.0.0.0/162", snmpEndpoint.getServerAddress()); } @Test @@ -63,6 +63,6 @@ public class UriConfigurationTest { assertEquals(SnmpActionType.POLL, snmpEndpoint.getType()); assertEquals("1.3.6.1.2.1.7.5.1", snmpEndpoint.getOids().get(0).toString()); - assertEquals("udp:127.0.0.1/1662", snmpEndpoint.getAddress()); + assertEquals("udp:127.0.0.1/1662", snmpEndpoint.getServerAddress()); } } 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 77bd92856ad..a8f367e79ec 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 @@ -27,7 +27,8 @@ import org.slf4j.LoggerFactory; @UriParams public class SplunkHECConfiguration { - private static final transient Logger LOG = LoggerFactory.getLogger(SplunkHECConfiguration.class); + + private static final Logger LOG = LoggerFactory.getLogger(SplunkHECConfiguration.class); @UriParam(defaultValue = "camel") private String index = "camel"; 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 2fc9bf9eac5..687a7f6f070 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 @@ -23,6 +23,7 @@ import org.apache.camel.Category; import org.apache.camel.Consumer; import org.apache.camel.Processor; import org.apache.camel.Producer; +import org.apache.camel.spi.EndpointLocationAddress; import org.apache.camel.spi.Metadata; import org.apache.camel.spi.UriEndpoint; import org.apache.camel.spi.UriParam; @@ -37,7 +38,7 @@ import org.apache.commons.validator.routines.InetAddressValidator; @UriEndpoint(firstVersion = "3.3.0", scheme = "splunk-hec", title = "Splunk HEC", producerOnly = true, syntax = "splunk-hec:splunkURL", category = { Category.MONITORING }, headersClass = SplunkHECConstants.class) -public class SplunkHECEndpoint extends DefaultEndpoint { +public class SplunkHECEndpoint extends DefaultEndpoint implements EndpointLocationAddress { 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}$"); @@ -98,6 +99,11 @@ public class SplunkHECEndpoint extends DefaultEndpoint { throw new UnsupportedOperationException(); } + @Override + public String getAddress() { + return splunkURL; + } + public SplunkHECConfiguration getConfiguration() { return configuration; } diff --git a/components/camel-splunk/src/main/java/org/apache/camel/component/splunk/SplunkEndpoint.java b/components/camel-splunk/src/main/java/org/apache/camel/component/splunk/SplunkEndpoint.java index 10145050a4a..77873346954 100644 --- a/components/camel-splunk/src/main/java/org/apache/camel/component/splunk/SplunkEndpoint.java +++ b/components/camel-splunk/src/main/java/org/apache/camel/component/splunk/SplunkEndpoint.java @@ -18,6 +18,7 @@ package org.apache.camel.component.splunk; import java.net.ConnectException; import java.net.SocketException; +import java.util.Map; import java.util.regex.Pattern; import javax.net.ssl.SSLException; @@ -27,6 +28,7 @@ import org.apache.camel.Category; import org.apache.camel.Consumer; import org.apache.camel.Processor; import org.apache.camel.Producer; +import org.apache.camel.spi.EndpointLocationAddress; import org.apache.camel.spi.UriEndpoint; import org.apache.camel.spi.UriParam; import org.apache.camel.support.ScheduledPollEndpoint; @@ -38,7 +40,7 @@ import org.slf4j.LoggerFactory; */ @UriEndpoint(firstVersion = "2.13.0", scheme = "splunk", title = "Splunk", syntax = "splunk:name", category = { Category.IOT, Category.MONITORING }) -public class SplunkEndpoint extends ScheduledPollEndpoint { +public class SplunkEndpoint extends ScheduledPollEndpoint implements EndpointLocationAddress { private static final Logger LOG = LoggerFactory.getLogger(SplunkEndpoint.class); @@ -57,6 +59,19 @@ public class SplunkEndpoint extends ScheduledPollEndpoint { this.configuration = configuration; } + @Override + public String getAddress() { + return configuration.getHost() + ":" + configuration.getPort(); + } + + @Override + public Map<String, String> getAddressMetadata() { + if (configuration.getUsername() != null) { + return Map.of("username", configuration.getUsername()); + } + return null; + } + @Override public Producer createProducer() throws Exception { String[] uriSplit = splitUri(getEndpointUri()); @@ -112,7 +127,7 @@ public class SplunkEndpoint extends ScheduledPollEndpoint { public synchronized boolean reset(Exception e) { boolean answer = false; - if (e instanceof RuntimeException && ((RuntimeException) e).getCause() instanceof ConnectException + if (e instanceof RuntimeException && e.getCause() instanceof ConnectException || e instanceof SocketException || e instanceof SSLException) { LOG.warn("Got exception from Splunk. Service will be reset."); this.service = null; diff --git a/components/camel-splunk/src/main/java/org/apache/camel/component/splunk/SplunkProducer.java b/components/camel-splunk/src/main/java/org/apache/camel/component/splunk/SplunkProducer.java index 641350fba0c..31035849ef6 100644 --- a/components/camel-splunk/src/main/java/org/apache/camel/component/splunk/SplunkProducer.java +++ b/components/camel-splunk/src/main/java/org/apache/camel/component/splunk/SplunkProducer.java @@ -33,7 +33,7 @@ import org.slf4j.LoggerFactory; * The Splunk producer. */ public class SplunkProducer extends DefaultProducer { - private static final transient Logger LOG = LoggerFactory.getLogger(SplunkProducer.class); + private static final Logger LOG = LoggerFactory.getLogger(SplunkProducer.class); private SplunkEndpoint endpoint; private DataWriter dataWriter; diff --git a/components/camel-splunk/src/main/java/org/apache/camel/component/splunk/support/StreamDataWriter.java b/components/camel-splunk/src/main/java/org/apache/camel/component/splunk/support/StreamDataWriter.java index 9cc5f8b7897..55d7bef0141 100644 --- a/components/camel-splunk/src/main/java/org/apache/camel/component/splunk/support/StreamDataWriter.java +++ b/components/camel-splunk/src/main/java/org/apache/camel/component/splunk/support/StreamDataWriter.java @@ -43,9 +43,9 @@ public class StreamDataWriter extends SplunkDataWriter { @Override protected Socket createSocket(Service service) throws IOException { - Index indexObject = null; - Receiver receiver = null; - Socket socket = null; + Index indexObject; + Receiver receiver; + Socket socket; if (index != null) { indexObject = service.getIndexes().get(index); diff --git a/components/camel-spring-redis/src/main/java/org/apache/camel/component/redis/RedisEndpoint.java b/components/camel-spring-redis/src/main/java/org/apache/camel/component/redis/RedisEndpoint.java index 485f77f1103..e74dc010458 100644 --- a/components/camel-spring-redis/src/main/java/org/apache/camel/component/redis/RedisEndpoint.java +++ b/components/camel-spring-redis/src/main/java/org/apache/camel/component/redis/RedisEndpoint.java @@ -20,6 +20,7 @@ import org.apache.camel.Category; import org.apache.camel.Consumer; import org.apache.camel.Processor; import org.apache.camel.Producer; +import org.apache.camel.spi.EndpointLocationAddress; import org.apache.camel.spi.UriEndpoint; import org.apache.camel.spi.UriParam; import org.apache.camel.support.DefaultEndpoint; @@ -30,10 +31,10 @@ import org.springframework.data.redis.core.RedisTemplate; */ @UriEndpoint(firstVersion = "2.11.0", scheme = "spring-redis", title = "Spring Redis", syntax = "spring-redist:host:port", category = { Category.CACHE }, headersClass = RedisConstants.class) -public class RedisEndpoint extends DefaultEndpoint { +public class RedisEndpoint extends DefaultEndpoint implements EndpointLocationAddress { @UriParam - private RedisConfiguration configuration; + private final RedisConfiguration configuration; public RedisEndpoint(String uri, RedisComponent component, RedisConfiguration configuration) { super(uri, component); @@ -60,6 +61,11 @@ public class RedisEndpoint extends DefaultEndpoint { return answer; } + @Override + public String getAddress() { + return configuration.getHost() + ":" + configuration.getPort(); + } + @Override protected void doShutdown() throws Exception { super.doShutdown(); diff --git a/components/camel-ssh/src/main/java/org/apache/camel/component/ssh/SshEndpoint.java b/components/camel-ssh/src/main/java/org/apache/camel/component/ssh/SshEndpoint.java index 12a13fafcc3..4a7ded2899a 100644 --- a/components/camel-ssh/src/main/java/org/apache/camel/component/ssh/SshEndpoint.java +++ b/components/camel-ssh/src/main/java/org/apache/camel/component/ssh/SshEndpoint.java @@ -20,18 +20,21 @@ import org.apache.camel.Category; import org.apache.camel.Consumer; import org.apache.camel.Processor; import org.apache.camel.Producer; +import org.apache.camel.spi.EndpointLocationAddress; import org.apache.camel.spi.UriEndpoint; import org.apache.camel.spi.UriParam; import org.apache.camel.support.ScheduledPollEndpoint; import org.apache.sshd.common.keyprovider.KeyPairProvider; +import java.util.Map; + /** * Execute commands on remote hosts using SSH. */ @UriEndpoint(firstVersion = "2.10.0", scheme = "ssh", title = "SSH", syntax = "ssh:host:port", alternativeSyntax = "ssh:username:password@host:port", category = { Category.FILE }, headersClass = SshConstants.class) -public class SshEndpoint extends ScheduledPollEndpoint { +public class SshEndpoint extends ScheduledPollEndpoint implements EndpointLocationAddress { @UriParam private SshConfiguration configuration; @@ -67,6 +70,19 @@ public class SshEndpoint extends ScheduledPollEndpoint { return false; } + @Override + public String getAddress() { + return configuration.getHost() + ":" + configuration.getPort(); + } + + @Override + public Map<String, String> getAddressMetadata() { + if (configuration.getUsername() != null) { + return Map.of("username", configuration.getUsername()); + } + return null; + } + public SshConfiguration getConfiguration() { return configuration; }