Claus Ibsen created CAMEL-25956:
-----------------------------------
Summary: camel-google-pubsub - the producer sends any body other
than text or bytes through Java serialization, so a stream or a file fails and
no body publishes a serialized null
Key: CAMEL-25956
URL: https://issues.apache.org/jira/browse/CAMEL-25956
Project: Camel
Issue Type: Bug
Components: camel-google-pubsub
Affects Versions: 4.18.0, 4.22.0, 4.23.0
Reporter: Claus Ibsen
Fix For: 4.24.0
The google-pubsub producer sends a String as UTF-8 and a byte[] as it is, and
passes any other body to the serializer ({{GooglePubsubProducer}}, main
e6885df7894d, lines 98-106). The default serializer is Java serialization
({{DefaultGooglePubsubSerializer.serialize}}, lines 29-34, set by
{{GooglePubsubEndpoint}} line 155), and the body is never converted first. So:
* a stream fails with {{java.io.NotSerializableException:
org.apache.camel.converter.stream.ByteArrayInputStreamCache}}. With stream
caching on, as it is by default, that is the body of a route that starts with
an HTTP request or reads a stream;
* the GenericFile of the file consumer fails with
{{java.io.NotSerializableException:
org.apache.camel.component.file.GenericFile}}, so
{{from("file:inbox").to("google-pubsub:project:topic")}} does not work;
* a {{java.io.File}} is Serializable, so the message holds the serialized File
object, its path, and not the content of the file;
* no body publishes 5 bytes, a serialized null ({{AC ED 00 05 70}});
* a Map or a POJO is sent as Java-serialized bytes, which only a Java reader
with an ObjectInputStream can read.
Checked on 4.24.0-SNAPSHOT against the Pub/Sub emulator ({{camel infra run
google pub-sub}}): text and bytes arrive as they were sent, a Map arrives as
216 bytes that start with AC ED, and the other cases fail or arrive as
described. The documentation says "Everything else will be serialised into a
byte[] array" ({{google-pubsub-component.adoc}}).
*Proposed change*: convert a body that is not a String or a byte[] to a byte[]
with the type converter, as other producers do, and use the serializer only for
a body that does not convert; fail when there is no body.
_Claude Code on behalf of davsclaus_
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)