Skip to content

CAMEL-26335: camel-cometd - configure allowedTransports and disable callback-polling by default - #28555

Merged
davsclaus merged 4 commits into
apache:mainfrom
oscerd:fix/CAMEL-26335
Oct 27, 2026
Merged

davsclaus merged 4 commits into
apache:mainfrom
oscerd:fix/CAMEL-26335

Conversation

@oscerd

@oscerd oscerd commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Jira: https://issues.apache.org/jira/browse/CAMEL-26335

CometD endpoints in camel-cometd accept transport connections through the CometD BayeuxServer. By default, CometD registers all transports available on its classpath, which historically included callback-polling (JSONP) in addition to websocket and long-polling.

This change introduces an allowedTransports configuration option on CometdEndpoint (and forwarded to the servlet init parameters in CometdComponent), defaulting to "websocket,long-polling". As a result, callback-polling is disabled by default.

Changes

  • Added allowedTransports URI option to CometdEndpoint (default: "websocket,long-polling"), normalized by trimming whitespace between comma-separated entries.
  • In CometdComponent.createServletForConnector(), passed allowedTransports as an init parameter to allowedTransports (BayeuxServerImpl.ALLOWED_TRANSPORTS_OPTION), which CometD uses to initialize its active server transports.
  • Generated endpoint configurers, URI factory, and catalog descriptors.
  • Added documentation in cometd-component.adoc and synchronized catalog docs.
  • Added upgrade guide documentation noting the change in default active transports and showing how to re-enable callback-polling if needed for legacy environments.

Tests

Added CometdAllowedTransportsTest covering:

  • testDefaultTransportsRejectsJsonp: verifies that handshake requests with callback-polling (JSONP) transport are rejected by default with HTTP 400.
  • testDefaultTransportsAllowsLongPolling: verifies that handshake requests with standard long-polling transport continue to be accepted.
  • testCustomTransportsAllowsJsonpWhenConfigured: verifies that configuring allowedTransports=websocket, long-polling, callback-polling restores support for callback-polling and handles spaces between transport names.

Claude Code on behalf of oscerd

…allback-polling by default

Configure the allowedTransports parameter on CometdEndpoint and CometdComponent to restrict accepted Bayeux transport mechanisms.
By default, allowedTransports defaults to "websocket,long-polling", disabling callback-polling.
Users requiring callback-polling can explicitly configure allowedTransports on the endpoint.

Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: Andrea Cosentino <ancosen@gmail.com>
@oscerd oscerd self-assigned this Oct 27, 2026
@oscerd
oscerd requested review from Croway and davsclaus October 27, 2026 08:11
@oscerd oscerd added the bug Something isn't working label Oct 27, 2026
@gnodet

gnodet commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

🔄 Backport Bot

This bugfix targets main and may need porting to:

  • camel-4.22.x

Add a port/<branch> label to automatically create a backport PR for that branch.

Backport PRs will be created automatically on merge (once a port label is added). Comment /port to create them immediately.

ℹ️ If you push additional commits after /port, use /port again to update the port PRs.

@github-actions

Copy link
Copy Markdown
Contributor

🌟 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 although they are normally detected and executed by CI.
  • You can label PRs using 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.

@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

✅ Generated files are up to date

An earlier CI run reported uncommitted generated changes; the latest run no longer does.

@github-actions github-actions Bot added the dsl label Oct 27, 2026
@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

🧪 CI tested the following changed modules:

  • catalog/camel-catalog
  • components/camel-cometd
  • docs
  • dsl/camel-endpointdsl

🔁 1 test passed only after a retry on JDK 21 (1 retried attempt)

Recovered flaky tests on JDK 21 (1)
Module Test Failed attempts First failure
dsl/camel-jbang/camel-jbang-plugin-tui MonitorStartupTest.browserOnlyServesUntilTheServerStops 1 Connection refused (connect failed)

ℹ️ These tests did not fail the build. Surefire retried them and they passed.
Retries are enabled project-wide by surefire.rerunFailingTestsCount in parent/pom.xml.


🔬 Scalpel shadow comparison — Scalpel: 8 of 708 tested, 24 compile-only — current: 8 all tested

Maveniverse Scalpel detected 8 affected modules (current approach: 8).

Skip-tests mode would test 8 modules (4 direct + 7 downstream), skip tests for 24 (generated code, meta-modules)

Modules Scalpel would test (8)
  • camel-cometd ← components/camel-cometd/src/generated/java/org/apache/camel/component/cometd/CometdEndpointConfigurer.java, components/camel-cometd/src/generated/java/org/apache/camel/component/cometd/CometdEndpointUriFactory.java, components/camel-cometd/src/generated/resources/META-INF/org/apache/camel/component/cometd/cometd.json, components/camel-cometd/src/generated/resources/META-INF/org/apache/camel/component/cometd/cometds.json, components/camel-cometd/src/main/docs/cometd-component.adoc, components/camel-cometd/src/main/java/org/apache/camel/component/cometd/CometdComponent.java, components/camel-cometd/src/main/java/org/apache/camel/component/cometd/CometdEndpoint.java, components/camel-cometd/src/test/java/org/apache/camel/component/cometd/CometdAllowedTransportsTest.java
  • camel-jbang-mcp ← downstream of org.apache.camel:camel-catalog
  • camel-jbang-plugin-mcp ← downstream of org.apache.camel:camel-jbang-core
  • camel-jbang-plugin-tui ← downstream of org.apache.camel:camel-catalog
  • camel-jbang-plugin-validate ← downstream of org.apache.camel:camel-yaml-dsl-validator
  • camel-launcher-container ← downstream of org.apache.camel:camel-launcher
  • camel-yaml-dsl-validator ← downstream of org.apache.camel:camel-catalog
  • camel-yaml-dsl-validator-maven-plugin ← downstream of org.apache.camel:camel-yaml-dsl-validator
Modules with tests skipped (24)
  • apache-camel
  • camel-allcomponents
  • camel-catalog-console
  • camel-catalog-maven
  • camel-catalog-suggest
  • camel-componentdsl
  • camel-endpointdsl-support
  • camel-itest
  • camel-jbang-core
  • camel-jbang-it
  • camel-jbang-main
  • camel-jbang-plugin-edit
  • camel-jbang-plugin-generate
  • camel-jbang-plugin-kubernetes
  • camel-jbang-plugin-test
  • camel-kamelet-main
  • camel-launcher
  • camel-report-maven-plugin
  • camel-route-parser
  • camel-yaml-dsl
  • camel-yaml-dsl-deserializers
  • camel-yaml-dsl-maven-plugin
  • coverage
  • dummy-component

ℹ️ Shadow mode — Scalpel observes but does not affect test execution. Learn more

All tested modules (35 modules, 6m 16s total)

Total reactor time: 6m 16s

Module Duration Status
Camel :: Launcher 54.7s SUCCESS
Camel :: JBang :: MCP 45.7s SUCCESS
Camel :: JBang :: Plugin :: Validate 29.6s SUCCESS
Camel :: YAML DSL :: Validator 28.5s SUCCESS
Camel :: Catalog :: Camel Catalog 25.1s SUCCESS
Camel :: YAML DSL 24.1s SUCCESS
Camel :: Component DSL 21.6s SUCCESS
Camel :: Cometd 18.6s SUCCESS
Camel :: JBang :: Plugin :: Testing 17.8s SUCCESS
Camel :: JBang :: Plugin :: Kubernetes 17.5s SUCCESS
Camel :: Docs 15.3s SUCCESS
Camel :: Kamelet Main 13.1s SUCCESS
Camel :: Catalog :: Camel Report Maven Plugin 11.9s SUCCESS
Camel :: YAML DSL :: Deserializers 9.3s SUCCESS
Camel :: Catalog :: Camel Route Parser 9.0s SUCCESS
Camel :: YAML DSL :: Validator Maven Plugin 7.0s SUCCESS
Camel :: All Components Sync point 5.1s SUCCESS
Camel :: YAML DSL :: Maven Plugins 4.4s SUCCESS
Camel :: Catalog :: Maven 3.5s SUCCESS
Camel :: Catalog :: Suggest (deprecated) 2.0s SUCCESS
Camel :: Assembly 1.5s SUCCESS
Camel :: JBang :: Plugin :: Generate 1.5s SUCCESS
Camel :: Coverage 1.3s SUCCESS
Camel :: JBang :: Integration tests 1.2s SUCCESS
Camel :: Catalog :: Dummy Component 1.2s SUCCESS
Camel :: JBang :: Plugin :: MCP 1.1s SUCCESS
Camel :: Catalog :: Console 1.1s SUCCESS
Camel :: JBang :: Plugin :: Edit 1.0s SUCCESS
Camel :: Endpoint DSL :: Support 1.0s SUCCESS
Camel :: JBang :: Main 0.8s SUCCESS
Camel :: Launcher :: Container 0.8s SUCCESS
Camel :: Endpoint DSL n/a
Camel :: Integration Tests n/a
Camel :: JBang :: Core n/a
Camel :: JBang :: Plugin :: TUI n/a

Top 20 slowest modules:

  • Camel :: Launcher (54.7s)
  • Camel :: JBang :: MCP (45.7s)
  • Camel :: JBang :: Plugin :: Validate (29.6s)
  • Camel :: YAML DSL :: Validator (28.5s)
  • Camel :: Catalog :: Camel Catalog (25.1s)
  • Camel :: YAML DSL (24.1s)
  • Camel :: Component DSL (21.6s)
  • Camel :: Cometd (18.6s)
  • Camel :: JBang :: Plugin :: Testing (17.8s)
  • Camel :: JBang :: Plugin :: Kubernetes (17.5s)
  • Camel :: Docs (15.3s)
  • Camel :: Kamelet Main (13.1s)
  • Camel :: Catalog :: Camel Report Maven Plugin (11.9s)
  • Camel :: YAML DSL :: Deserializers (9.3s)
  • Camel :: Catalog :: Camel Route Parser (9.0s)
  • Camel :: YAML DSL :: Validator Maven Plugin (7.0s)
  • Camel :: All Components Sync point (5.1s)
  • Camel :: YAML DSL :: Maven Plugins (4.4s)
  • Camel :: Catalog :: Maven (3.5s)
  • Camel :: Catalog :: Suggest (deprecated) (2.0s)

⚙️ View full build and test results

@davsclaus davsclaus left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Andrea, this is a clean, focused change. Making callback-polling something users turn on, with a new endpoint option and an upgrade-guide note, is the right shape. The default only gets stricter, and the tests check the real HTTP behaviour on both sides (default and opted-in). I like that testDefaultTransportsAllowsLongPolling also checks that the handshake reply no longer offers callback-polling. None of the points below block the merge. They are small hardening and wording points.

1. Spaces in the list (CometdComponent.java:239)
CometD 9.0.1 (BayeuxServerImpl.initializeServerTransports) splits allowedTransports on , without trimming, and it silently drops any name it does not know. So allowedTransports=long-polling, callback-polling, written the way many Camel list options are, gives only long-polling, and JSONP stays off with no warning. If every name has a leading space, the servlet fails to start with "does not contain at least one configured server transport name". Can we normalise the value before passing it on?

if (ObjectHelper.isNotEmpty(endpoint.getAllowedTransports())) {
    String transports = Arrays.stream(endpoint.getAllowedTransports().split(","))
            .map(String::trim)
            .filter(s -> !s.isEmpty())
            .collect(Collectors.joining(","));
    holder.setInitParameter("allowedTransports", transports);
}

A test with spaces, e.g. allowedTransports=long-polling, callback-polling on the custom endpoint, would cover it.

2. The websocket entry and the upgrade-guide wording (camel-4x-upgrade-guide-4_24.adoc:3597)
Out of the box, CometD only creates a WebSocket transport when its Jakarta WebSocket transport (org.cometd.server.websocket.jakarta.WebSocketTransport) is on the classpath. camel-cometd ships cometd-java-server-websocket-jetty, which BayeuxServerImpl does not add by default. So with the default value, long-polling is the only active transport, and websocket in the list is a no-op unless a user adds that transport. Keeping it in the default is fine. However, "Only the websocket and long-polling transports are enabled out of the box" reads as if WebSocket works out of the box. Maybe: "Only long-polling (and websocket, when the CometD WebSocket transport is on the classpath) is enabled by default."

3. Option description (CometdEndpoint.java:95-97, 302-304)

  • It would help users to list the valid names (websocket, long-polling, callback-polling), say that the list is comma separated, and say that callback-polling is the JSONP transport.
  • Like timeout, interval and the CORS options, this value applies to the whole CometD server of a host and port. The endpoint that starts the server first sets it, and other endpoints on the same port cannot change it. A sentence about that avoids surprises when two routes share a port with different values.
  • The text is in both the description attribute and the setter javadoc. The other options of this endpoint use only the setter javadoc, so we can drop the attribute.

A short paragraph about transports/JSONP in cometd-component.adoc would also help users find the option (the catalog copy needs regenerating then).

4. Test assertion (CometdAllowedTransportsTest.java:47)
When no allowed transport accepts the request, CometD answers 400 Unknown Bayeux Transport. assertEquals(400, response.statusCode()) is stricter than the || form and gives a clearer failure message.

5. JIRA and PR description

  • CAMEL-25993 (open, fix version 4.24.0) asks for the same change. Its second part, null in allowedOrigins without credentials, already landed with CAMEL-25984 (isNamedOrigins). Can we link the two and close CAMEL-25993 when this is merged?
  • CAMEL-26335 has fix versions 4.18.6 and 4.22.3, and CAMEL-25993 proposed main only because the default changes. If this is ported, the same note belongs in the 4.18 and 4.22 upgrade guides on main.
  • The PR description says the init parameter is org.cometd.bayeux.server.BayeuxServer.allowedTransports, but the code (correctly) uses allowedTransports (BayeuxServerImpl.ALLOWED_TRANSPORTS_OPTION). A small fix to the description would help readers.

I checked the generated files (configurer, URI factory, catalog JSON, Endpoint DSL after the Regen commit). They match the new option.


Reviewed with Claude Code on behalf of davsclaus. This review was generated by an AI agent and may contain inaccuracies; please verify all suggestions before applying.

- CometdComponent: normalize allowedTransports by trimming spaces between transport names
- CometdEndpoint: enhance option javadoc and describe server-level scope
- Add Allowed Transports and JSONP documentation in cometd-component.adoc and sync catalog
- CometdAllowedTransportsTest: assert exact 400 status code on rejection and test spaced configuration
- Update upgrade guide wording regarding default enabled transports

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: Andrea Cosentino <ancosen@gmail.com>
@oscerd

oscerd commented Oct 27, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @davsclaus! Addressed the feedback in commit b92bcf2:

  1. Space normalisation: Normalized allowedTransports in CometdComponent by splitting on commas, trimming each entry, filtering empties, and joining back with commas. Tested with spaced configuration in CometdAllowedTransportsTest.
  2. Upgrade guide wording: Updated camel-4x-upgrade-guide-4_24.adoc to clarify that long-polling (and websocket when CometD WebSocket transport is on the classpath) is enabled by default.
  3. Option description: Dropped redundant description attribute from @UriParam in CometdEndpoint, updated setter Javadoc to document allowed values, JSONP role, and server-level scoping. Added an "Allowed Transports and JSONP" section in cometd-component.adoc and synchronized the catalog copy.
  4. Test assertion: Tightened the status code assertion in testDefaultTransportsRejectsJsonp to assertEquals(400, response.statusCode()).
  5. PR description: Corrected the servlet init parameter name to allowedTransports.

Claude Code on behalf of oscerd

@gnodet-bot gnodet-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. No issues found.

Shared-server semantics are consistent with all other init params — first endpoint wins, which the setter Javadoc documents accurately. Tests correctly use separate ports to avoid interference. Upgrade guide is accurate.

This review was generated by an AI agent, Hermès on behalf of @gnodet.

@davsclaus davsclaus added this to the 4.24.0 milestone Oct 27, 2026
@davsclaus
davsclaus merged commit 44700f0 into apache:main Oct 27, 2026
7 checks passed
@davsclaus davsclaus added port/camel-4.18.x Bug needs porting to camel-4.18.x port/camel-4.22.x Bug needs porting to camel-4.22.x labels Oct 27, 2026
@gnodet

gnodet commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

🔄 Backport Bot

Conflicts (🤖 agent dispatched to resolve):

  • ⚠️ camel-4.22.x — Cherry-pick conflict in: catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/cometd-component.adoc, components/camel-cometd/src/main/docs/cometd-component.adoc, docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
  • ⚠️ camel-4.18.x — Cherry-pick conflict in: catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/cometd-component.adoc, components/camel-cometd/src/main/docs/cometd-component.adoc, docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc

ℹ️ If you push additional commits after /port, use /port again to update the port PRs.

@gnodet

gnodet commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

✅ Backport to camel-4.22.x created: #28561

@gnodet

gnodet commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

✅ Backport to camel-4.18.x created: #28562

@gnodet gnodet removed the port/camel-4.18.x Bug needs porting to camel-4.18.x label Oct 27, 2026
@oscerd
oscerd deleted the fix/CAMEL-26335 branch October 28, 2026 10:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants