Skip to content

CAMEL-23936: Fix logHttpActivity losing Content-Encoding on gzip responses#24506

Merged
davsclaus merged 2 commits into
mainfrom
fix/CAMEL-23936
Jul 8, 2026
Merged

CAMEL-23936: Fix logHttpActivity losing Content-Encoding on gzip responses#24506
davsclaus merged 2 commits into
mainfrom
fix/CAMEL-23936

Conversation

@davsclaus

@davsclaus davsclaus commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Claude Code on behalf of davsclaus

When logHttpActivity is enabled and the HTTP server returns a gzip-encoded response, the response body is not decompressed, causing downstream processing (e.g., Jackson JSON parsing) to fail with JsonParseException: Illegal character (CTRL-CHAR, code 31).

Root cause: In LoggingHttpActivityListener, when the response entity's stream is consumed for logging and a replacement ByteArrayEntity is created, the original Content-Encoding (e.g., gzip) was not passed to the new entity. This caused Apache HttpClient's ContentCompressionExec to skip decompression, leaving the raw gzip bytes in the response body.

Fix: Pass the original content encoding as the third argument to the ByteArrayEntity constructor, preserving the encoding metadata for downstream decompression.

  • LoggingHttpActivityListener.java:208new ByteArrayEntity(arr, ct)new ByteArrayEntity(arr, ct, ce)

Test plan

  • HttpLoggingActivityGzipTest extends HttpCompressionTest — verifies gzip-encoded responses are correctly decompressed when logHttpActivity is enabled
  • Inherited tests from HttpCompressionTest also pass with logging enabled (bonus coverage)
  • Verified the test fails without the fix (raw gzip bytes reach the body)
  • All existing camel-http tests pass

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com

…onses

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Claus Ibsen <claus.ibsen@gmail.com>
@github-actions

github-actions Bot commented Jul 8, 2026

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 Jul 8, 2026

Copy link
Copy Markdown
Contributor

🧪 CI tested the following changed modules:

  • components/camel-http

ℹ️ Dependent modules were not tested because the total number of affected modules exceeded the threshold (50). Use the test-dependents label to force testing all dependents.


🔬 Scalpel shadow comparison — Scalpel: 61 tested, 29 compile-only — current: 61 all tested

Maveniverse Scalpel detected 90 affected modules (current approach: 61).

⚠️ Modules only in Scalpel (29)
  • apache-camel
  • camel-allcomponents
  • camel-catalog
  • camel-catalog-console
  • camel-catalog-lucene
  • camel-catalog-maven
  • camel-catalog-suggest
  • camel-componentdsl
  • camel-csimple-maven-plugin
  • camel-endpointdsl
  • 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
  • docs
  • dummy-component

Skip-tests mode would test 61 modules (1 direct + 60 downstream), skip tests for 29 (generated code, meta-modules)

Modules Scalpel would test (61)
  • camel-a2a
  • camel-as2
  • camel-clickup
  • camel-consul
  • camel-cxf-rest
  • camel-cxf-soap
  • camel-cxf-spring-rest
  • camel-cxf-spring-soap
  • camel-cxf-spring-transport
  • camel-cxf-transport
  • camel-graphql
  • camel-http
  • camel-java-joor-dsl
  • camel-jbang-mcp
  • camel-jbang-plugin-mcp
  • camel-jbang-plugin-route-parser
  • camel-jbang-plugin-tui
  • camel-jbang-plugin-validate
  • camel-jetty
  • camel-jsonpath
  • camel-kamelet
  • camel-knative-http
  • camel-kubernetes
  • camel-launcher-container
  • camel-lra
  • camel-micrometer-observability
  • camel-micrometer-prometheus
  • camel-netty-http
  • camel-oauth
  • camel-observability-services
  • camel-openapi-validator
  • camel-opentelemetry
  • camel-opentelemetry2
  • camel-platform-http
  • camel-platform-http-jolokia
  • camel-platform-http-main
  • camel-platform-http-vertx
  • camel-quickfix
  • camel-rest-openapi
  • camel-restdsl-openapi-plugin
  • camel-sap-netweaver
  • camel-slack
  • camel-soap
  • camel-spring-rabbitmq
  • camel-telegram
  • camel-telemetry
  • camel-telemetry-dev
  • camel-test-main-junit5
  • camel-test-main-junit6
  • camel-undertow
  • camel-undertow-spring-security
  • camel-vertx-http
  • camel-webhook
  • camel-whatsapp
  • camel-xml-io-dsl
  • camel-xml-jaxb-dsl
  • camel-xml-jaxb-dsl-test-definition
  • camel-xml-jaxb-dsl-test-spring
  • camel-yaml-dsl-validator
  • camel-yaml-dsl-validator-maven-plugin
  • camel-zookeeper
Modules with tests skipped (29)
  • apache-camel
  • camel-allcomponents
  • camel-catalog
  • camel-catalog-console
  • camel-catalog-lucene
  • camel-catalog-maven
  • camel-catalog-suggest
  • camel-componentdsl
  • camel-csimple-maven-plugin
  • camel-endpointdsl
  • 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
  • docs
  • dummy-component

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

Build reactor — dependencies compiled but only changed modules were tested (90 modules)
  • Camel :: AI :: A2A
  • Camel :: AS2 :: Component
  • Camel :: All Components Sync point
  • Camel :: Assembly
  • Camel :: CXF :: REST
  • Camel :: CXF :: REST :: Spring
  • Camel :: CXF :: SOAP
  • Camel :: CXF :: SOAP :: Spring
  • Camel :: CXF :: Transport
  • Camel :: CXF :: Transport :: Spring
  • Camel :: Catalog :: CSimple Maven Plugin (deprecated)
  • Camel :: Catalog :: Camel Catalog
  • Camel :: Catalog :: Camel Report Maven Plugin
  • Camel :: Catalog :: Camel Route Parser
  • Camel :: Catalog :: Console
  • Camel :: Catalog :: Dummy Component
  • Camel :: Catalog :: Lucene (deprecated)
  • Camel :: Catalog :: Maven
  • Camel :: Catalog :: Suggest
  • Camel :: ClickUp
  • Camel :: Common Telemetry
  • Camel :: Component DSL
  • Camel :: Consul
  • Camel :: Coverage
  • Camel :: Docs
  • Camel :: Endpoint DSL
  • Camel :: Endpoint DSL :: Support
  • Camel :: GraphQL
  • Camel :: HTTP
  • Camel :: Integration Tests
  • Camel :: JBang :: Core
  • Camel :: JBang :: Integration tests
  • Camel :: JBang :: MCP
  • Camel :: JBang :: Main
  • Camel :: JBang :: Plugin :: Edit
  • Camel :: JBang :: Plugin :: Generate
  • Camel :: JBang :: Plugin :: Kubernetes
  • Camel :: JBang :: Plugin :: MCP
  • Camel :: JBang :: Plugin :: Route Parser
  • Camel :: JBang :: Plugin :: TUI
  • Camel :: JBang :: Plugin :: Testing
  • Camel :: JBang :: Plugin :: Validate
  • Camel :: JSon Path
  • Camel :: Java DSL with jOOR
  • Camel :: Jetty
  • Camel :: Kamelet
  • Camel :: Kamelet Main
  • Camel :: Knative HTTP
  • Camel :: Kubernetes
  • Camel :: Launcher
  • Camel :: Launcher :: Container
  • Camel :: Long-Running-Action
  • Camel :: Maven Plugins :: OpenApi REST DSL Generator
  • Camel :: Micrometer :: Observability 2
  • Camel :: Micrometer :: Prometheus
  • Camel :: Netty HTTP
  • Camel :: OAuth
  • Camel :: Observability Services
  • Camel :: OpenAPI :: Validator
  • Camel :: OpenTelemetry (deprecated)
  • Camel :: Opentelemetry 2
  • Camel :: Platform HTTP
  • Camel :: Platform HTTP :: Jolokia
  • Camel :: Platform HTTP :: Main
  • Camel :: Platform HTTP :: Vert.x
  • Camel :: QuickFIX/J
  • Camel :: REST OpenApi
  • Camel :: SAP NetWeaver
  • Camel :: SOAP
  • Camel :: Slack
  • Camel :: Spring RabbitMQ
  • Camel :: Telegram
  • Camel :: Telemetry :: Dev
  • Camel :: Test :: Main :: JUnit5
  • Camel :: Test :: Main :: JUnit6
  • Camel :: Undertow
  • Camel :: Undertow Spring Security
  • Camel :: Vert.x :: HTTP
  • Camel :: Webhook
  • Camel :: Whatsapp
  • Camel :: XML DSL Jaxb :: Test :: Definition
  • Camel :: XML DSL Jaxb :: Test :: Spring
  • Camel :: XML DSL with camel-xml-io
  • Camel :: XML DSL with camel-xml-jaxb
  • Camel :: YAML DSL
  • Camel :: YAML DSL :: Deserializers
  • Camel :: YAML DSL :: Maven Plugins
  • Camel :: YAML DSL :: Validator
  • Camel :: YAML DSL :: Validator Maven Plugin
  • Camel :: Zookeeper

⚙️ View full build and test results

@davsclaus davsclaus left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Clean, well-targeted bug fix. The one-line change at LoggingHttpActivityListener.java:208 correctly preserves the Content-Encoding when re-creating the ByteArrayEntity after logging consumes the entity stream. Without this, ContentCompressionExec skips gzip decompression and downstream processing fails.

The ce variable correctly holds the original content encoding in both request and response paths, and the ByteArrayEntity(byte[], ContentType, String) constructor handles null safely for the non-compressed case.

Test coverage is good — HttpLoggingActivityGzipTest exercises the exact bug scenario with a local gzip-compressing HTTP server.

Minor suggestion (non-blocking): The new test duplicates ~130 lines of server infrastructure (inner interceptor classes and entity wrappers) from HttpCompressionTest. It could extend HttpCompressionTest instead, overriding only createCamelContext() and adding the logging-specific test method. But the current approach is consistent with the self-contained test pattern used elsewhere in the module.

This review was generated by an AI agent (Claude Code on behalf of davsclaus) and may contain inaccuracies. Please verify all suggestions before applying.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Claus Ibsen <claus.ibsen@gmail.com>

@oscerd oscerd 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 for the fix, Claus — reviewed against main and it looks correct.

  • The one-line change in LoggingHttpActivityListener (new ByteArrayEntity(arr, ct)new ByteArrayEntity(arr, ct, ce)) correctly re-attaches the Content-Encoding to the re-created entity. arr holds the raw gzip bytes and the separate local data decompression used only for logging is untouched, so there is no double-decode and the non-logging path is unaffected (the listener runs only when logHttpActivity=true).
  • Good regression coverage: HttpLoggingActivityGzipTest extends HttpCompressionTest, no Thread.sleep, and CI is green.
  • Commit convention and attribution/sign-off trailers are correct.

LGTM.

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

@davsclaus davsclaus added bug Something isn't working and removed components labels Jul 8, 2026
@davsclaus davsclaus self-assigned this Jul 8, 2026
@davsclaus davsclaus added this to the 4.22.0 milestone Jul 8, 2026
@davsclaus davsclaus merged commit 90713ca into main Jul 8, 2026
5 checks passed
@davsclaus davsclaus deleted the fix/CAMEL-23936 branch July 8, 2026 13:21
davsclaus added a commit that referenced this pull request Jul 8, 2026
…onses

Backport of #24506. When logHttpActivity is enabled and the HTTP server
returns a gzip-encoded response, the replacement ByteArrayEntity created
during logging did not preserve the original Content-Encoding, causing
HttpClient to skip decompression. Pass the content encoding to the
ByteArrayEntity constructor.

Closes #24507

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Claus Ibsen <claus.ibsen@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants