This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch camel-4.10.x
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-4.10.x by this push:
new 2fae203a771 CAMEL-22476: camel-plc4j - Cannot load drivers when using
poll mode
2fae203a771 is described below
commit 2fae203a771d0bb6a651798d5a66ec4d6464ee05
Author: Claus Ibsen <[email protected]>
AuthorDate: Tue Sep 30 17:40:26 2025 +0200
CAMEL-22476: camel-plc4j - Cannot load drivers when using poll mode
---
.../apache/camel/component/plc4x/Plc4XEndpoint.java | 21 ++++++++++++++-------
1 file changed, 14 insertions(+), 7 deletions(-)
diff --git
a/components/camel-plc4x/src/main/java/org/apache/camel/component/plc4x/Plc4XEndpoint.java
b/components/camel-plc4x/src/main/java/org/apache/camel/component/plc4x/Plc4XEndpoint.java
index 35c00c2f0d8..bb843fd2e31 100644
---
a/components/camel-plc4x/src/main/java/org/apache/camel/component/plc4x/Plc4XEndpoint.java
+++
b/components/camel-plc4x/src/main/java/org/apache/camel/component/plc4x/Plc4XEndpoint.java
@@ -72,7 +72,6 @@ public class Plc4XEndpoint extends DefaultEndpoint implements
EndpointServiceLoc
public Plc4XEndpoint(String endpointUri, Component component) {
super(endpointUri, component);
- this.plcDriverManager = new DefaultPlcDriverManager();
this.uri = endpointUri.replaceFirst("plc4x:/?/?", "");
}
@@ -104,7 +103,6 @@ public class Plc4XEndpoint extends DefaultEndpoint
implements EndpointServiceLoc
public void setTrigger(String trigger) {
this.trigger = trigger;
- this.plcDriverManager = new DefaultPlcDriverManager();
}
public void setAutoReconnect(boolean autoReconnect) {
@@ -134,7 +132,7 @@ public class Plc4XEndpoint extends DefaultEndpoint
implements EndpointServiceLoc
LOGGER.warn("Could not connect during setup, retrying on
next request");
}
} else {
- LOGGER.warn("Could not connect during setup and auto reconnect
is turned off");
+ LOGGER.warn("Could not connect during setup and auto reconnect
is turned off due to: {}", e.getMessage());
throw e;
}
}
@@ -153,7 +151,9 @@ public class Plc4XEndpoint extends DefaultEndpoint
implements EndpointServiceLoc
connection = plcDriverManager.getConnection(uri);
LOGGER.debug("Successfully reconnected");
} else if (autoReconnect && !isConnected()) {
- connection.connect();
+ if (connection != null) {
+ connection.connect();
+ }
// If reconnection fails without Exception, reset connection
if (!isConnected()) {
LOGGER.debug("No connection established after connect,
resetting connection");
@@ -170,7 +170,7 @@ public class Plc4XEndpoint extends DefaultEndpoint
implements EndpointServiceLoc
* @return true if connection supports writing, else false
*/
public boolean canWrite() {
- return connection.getMetadata().isWriteSupported();
+ return connection != null &&
connection.getMetadata().isWriteSupported();
}
/**
@@ -255,10 +255,17 @@ public class Plc4XEndpoint extends DefaultEndpoint
implements EndpointServiceLoc
this.tags = tags;
}
+ @Override
+ protected void doStart() throws Exception {
+ super.doStart();
+ ClassLoader cl = getCamelContext().getApplicationContextClassLoader();
+ this.plcDriverManager = new DefaultPlcDriverManager(cl);
+ }
+
@Override
public void doStop() throws Exception {
- //Shutting down the connection when leaving the Context
- if (isConnected()) {
+ super.doStop();
+ if (isConnected() && connection != null) {
connection.close();
connection = null;
}