fernandobalieiro opened a new pull request, #19664:
URL: https://github.com/apache/camel/pull/19664

   # Description
   
   The goal of this PR is to ensure that when `Content-Type` header is present, 
it's properly propagated into the Content-Type field of the raw AMQP Message.
   
   ## Motivation
   
   [SmallRye Reactive 
Messaging](https://smallrye.io/smallrye-reactive-messaging/smallrye-reactive-messaging/3.4/index.html)
 [relies on the raw AQMP 
Content-Type](https://github.com/smallrye/smallrye-reactive-messaging/blob/main/smallrye-reactive-messaging-amqp/src/main/java/io/smallrye/reactive/messaging/amqp/AmqpMessage.java#L146)
 to determine whether it should or not convert the payload into a 
[io.vertx.core.json.JsonObject](https://vertx.io/docs/apidocs/io/vertx/core/json/JsonObject.html):
   ```java
           if (body instanceof Data) {
               Binary bin = ((Data) body).getValue();
               byte[] bytes = new byte[bin.getLength()];
               System.arraycopy(bin.getArray(), bin.getArrayOffset(), bytes, 0, 
bin.getLength());
   
               if (APPLICATION_JSON.equalsIgnoreCase(msg.contentType())) {
                   return Buffer.buffer(bytes).toJson();
               }
               return bytes;
           }
   ```
   
   If the Content-Type `application/json` is not present, the conversion does 
not happen, and methods annotated with `@Incoming` with a JsonObject as 
parameter (such as the one below) break.
   
   In a scenario where Azure Service Bus Producers are migrated to use Apache 
Camel, all the Consumers that are relying on SmallRye Reactive Messaging will 
break.
   
   **Example method:**
   ```java
       @Incoming("my-subscription")
       public Uni<Void> handleMessage(final JsonObject messageJson) {
           return Uni.createFrom().item(messageJson)
               .call(() -> handle(messageJson))
               .replaceWithVoid();
       }
   ```
   
   **Stack Trace when consuming the message:**
   ```bash
   2025-10-22 12:24:34.665 ERROR io.sm.re.me.pr.AbstractMediator:166 
[vert.x-eventloop-thread-5-215] SRMSG00200: The method 
com.acme.MyEventHandler#handleMessage has thrown an exception: 
java.lang.ClassCastException: class [B cannot be cast to class 
io.vertx.core.json.JsonObject ([B is in module java.base of loader 'bootstrap'; 
io.vertx.core.json.JsonObject is in unnamed module of loader 
io.quarkus.bootstrap.classloading.QuarkusClassLoader @4f83df68)
           at 
com.acme.MyEventHandler_SmallRyeMessagingInvoker_handleMessage_23d540434dcfaa61d3f6031df6da3d9e581a58aa.invoke(Unknown
 Source)
           at 
io.smallrye.reactive.messaging.providers.AbstractMediator.invoke(AbstractMediator.java:164)
           at 
io.smallrye.reactive.messaging.providers.AbstractMediator.lambda$invokeOnMessageContext$13(AbstractMediator.java:172)
           at 
io.smallrye.reactive.messaging.providers.locals.LocalContextMetadata.lambda$invokeOnMessageContext$0(LocalContextMetadata.java:34)
           at 
io.smallrye.reactive.messaging.providers.locals.LocalContextMetadata.lambda$invokeOnMessageContext$1(LocalContextMetadata.java:53)
           at 
io.smallrye.reactive.messaging.providers.helpers.VertxContext.runOnContext(VertxContext.java:33)
           at 
io.smallrye.reactive.messaging.providers.locals.LocalContextMetadata.lambda$invokeOnMessageContext$2(LocalContextMetadata.java:51)
           at 
io.smallrye.context.impl.wrappers.SlowContextualConsumer.accept(SlowContextualConsumer.java:21)
           at 
io.smallrye.mutiny.operators.uni.builders.UniCreateWithEmitter.subscribe(UniCreateWithEmitter.java:22)
           at 
io.smallrye.mutiny.operators.AbstractUni.subscribe(AbstractUni.java:35)
           at 
io.smallrye.mutiny.operators.uni.UniOnItemTransformToUni.subscribe(UniOnItemTransformToUni.java:25)
           at 
io.smallrye.mutiny.operators.AbstractUni.subscribe(AbstractUni.java:35)
           at 
io.smallrye.mutiny.operators.uni.UniOnItemOrFailureFlatMap.subscribe(UniOnItemOrFailureFlatMap.java:27)
           at 
io.smallrye.mutiny.operators.AbstractUni.subscribe(AbstractUni.java:35)
           at 
io.smallrye.mutiny.converters.uni.UniToMultiPublisher$UniToMultiSubscription.request(UniToMultiPublisher.java:74)
           at 
io.smallrye.mutiny.operators.multi.MultiConcatMapOp$MainSubscriber.innerOnSubscribe(MultiConcatMapOp.java:109)
           at 
io.smallrye.mutiny.operators.multi.MultiConcatMapOp$MainSubscriber$InnerSubscriber.onSubscribe(MultiConcatMapOp.java:297)
           at 
io.smallrye.mutiny.converters.uni.UniToMultiPublisher.subscribe(UniToMultiPublisher.java:25)
           at 
io.smallrye.mutiny.groups.MultiCreate$1.subscribe(MultiCreate.java:165)
           at 
io.smallrye.mutiny.operators.multi.MultiConcatMapOp$MainSubscriber.onItem(MultiConcatMapOp.java:119)
           at 
io.smallrye.mutiny.operators.multi.MultiMapOp$MapProcessor.onItem(MultiMapOp.java:50)
           at 
io.smallrye.mutiny.operators.multi.MultiOnItemInvoke$MultiOnItemInvokeProcessor.onItem(MultiOnItemInvoke.java:41)
           at 
io.smallrye.mutiny.operators.multi.MultiOperatorProcessor.onItem(MultiOperatorProcessor.java:100)
           at 
io.smallrye.reactive.messaging.providers.locals.ContextOperator$ContextMulti$ContextProcessor.lambda$onItem$1(ContextOperator.java:71)
           at 
io.smallrye.reactive.messaging.providers.helpers.VertxContext.lambda$runOnContext$0(VertxContext.java:35)
           at 
io.vertx.core.impl.ContextInternal.dispatch(ContextInternal.java:270)
           at 
io.vertx.core.impl.ContextInternal.dispatch(ContextInternal.java:252)
           at 
io.vertx.core.impl.ContextInternal.lambda$runOnContext$0(ContextInternal.java:50)
           at 
io.netty.util.concurrent.AbstractEventExecutor.runTask(AbstractEventExecutor.java:173)
           at 
io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:166)
           at 
io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:472)
           at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:569)
           at 
io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:998)
           at 
io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
           at 
io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
           at java.base/java.lang.Thread.run(Thread.java:1583)
   
   ```
   
   # Target
   
   - [X] I checked that the commit is targeting the correct branch (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](https://issues.apache.org/jira/browse/CAMEL) filed for 
the change (usually before you start working on it).
   
   <!--
   # *Note*: trivial changes like, typos, minor documentation fixes and other 
small items do not require a JIRA issue. In this case your pull request should 
address just this issue, without pulling in other changes.
   -->
   
   # Apache Camel coding standards and style
   
   - [X] I checked that each commit in the pull request has a meaningful 
subject line and body.
   
   <!--
   If you're unsure, you can format the pull request title like `[CAMEL-XXX] 
Fixes bug in camel-file component`, where you replace `CAMEL-XXX` with the 
appropriate JIRA issue.
   -->
   
   - [X] I have run `mvn clean install -DskipTests` locally from root folder 
and I have committed all auto-generated changes.
   
   <!--
   You can run the aforementioned command in your module so that the build 
auto-formats your code. This will also be verified as part of the checks and 
your PR may be rejected if if there are uncommited changes after running `mvn 
clean install -DskipTests`.
   
   You can learn more about the contribution guidelines at 
https://github.com/apache/camel/blob/main/CONTRIBUTING.md
   -->
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to