Skip to content

fix(components/plc4x): fix NPE when Camel can not establish connection#16160

Merged
oscerd merged 1 commit into
apache:mainfrom
jmeierhofer:main
Nov 5, 2024
Merged

fix(components/plc4x): fix NPE when Camel can not establish connection#16160
oscerd merged 1 commit into
apache:mainfrom
jmeierhofer:main

Conversation

@jmeierhofer
Copy link
Copy Markdown
Contributor

@jmeierhofer jmeierhofer commented Nov 5, 2024

Description

When Camel can not establish the connection to the S7 PLC, the component is throwing follow-up exceptions which are causing the application start up to fail and which hide the real connection issue.

  • Added isConnected() to endpoint which checks if connection is null. This method is public to allow external logic to check if endpoint is really connected.
  • Moved canWrite() call to be checked only when connected.
  • Added additional canWrite() check after reconnectIfNeeded().

Steps to reproduce:

  • Add Camel route with S7 driver
  • PLC is not available
  • Connection failure
  • Additional NullPointerExceptions are thrown

Target

  • I checked that the commit is targeting the correct branch (note that Camel 3 uses camel-3.x, whereas Camel 4 uses the main branch)

Tracking

  • If this is a large change, bug fix, or code improvement, I checked there is a JIRA issue filed for the change (usually before you start working on it).

Apache Camel coding standards and style

  • I checked that each commit in the pull request has a meaningful subject line and body.

  • I have run mvn clean install -DskipTests locally from root folder and I have committed all auto-generated changes.

…n and allow to check if endpoint established connection
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Nov 5, 2024

🌟 Thank you for your contribution to the Apache Camel project! 🌟

🤖 CI automation will test this PR automatically.

🐫 Apache Camel Committers, please review the following items:

  • First-time contributors require MANUAL approval for the GitHub Actions to run

  • You can use the command /component-test (camel-)component-name1 (camel-)component-name2.. to request a test from the test bot.

  • You can label PRs using build-all, build-dependents, skip-tests and test-dependents to fine-tune the checks executed by this PR.

  • Build and test logs are available in the Summary page. Only Apache Camel committers have access to the summary.

  • ⚠️ Be careful when sharing logs. Review their contents before sharing them publicly.

@jmeierhofer
Copy link
Copy Markdown
Contributor Author

@oscerd I think the maven download failed during the JDK17 build. Can you please trigger the 2 builds again?

@oscerd
Copy link
Copy Markdown
Contributor

oscerd commented Nov 5, 2024

/component-tests plc4x

Result ✅ The tests passed successfully

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Nov 5, 2024

🤖 The Apache Camel test robot will run the tests for you 👍

@oscerd oscerd merged commit 42a62ac into apache:main Nov 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants