Andrea Cosentino created CAMEL-24342:
----------------------------------------

             Summary: camel-google-storage: producer sets wrong blob metadata 
and NPEs on missing objects
                 Key: CAMEL-24342
                 URL: https://issues.apache.org/jira/browse/CAMEL-24342
             Project: Camel
          Issue Type: Bug
          Components: camel-google-storage
            Reporter: Andrea Cosentino
            Assignee: Andrea Cosentino


Several defects in the google-storage producer and consumer:

1. Copy/paste in {{processFile}} - the Content-Type variable is used for two 
other fields:
{code:java}
// GoogleCloudStorageProducer.java:137-148
String ce = objectMetadata.remove("Content-Encoding");
if (ce != null) { builder.setContentEncoding(ct); }
...
String cc = objectMetadata.remove("Cache-Control");
if (cc != null) { builder.setCacheControl(ct); }
{code}
Uploaded objects get Content-Encoding and Cache-Control set to the content type 
(or to null when no Content-Type header was supplied).

2. {{getObject}} does not null-check the blob:
{code:java}
// GoogleCloudStorageProducer.java:328-330
Blob blob = storage.get(BlobId.of(bucketName, objectName));
message.setBody(blob.getContent(Blob.BlobSourceOption.generationMatch()));
{code}
A missing object gives an NPE instead of a clear error.

3. The consumer has the same problem on the single-object path:
{code:java}
// GoogleCloudStorageConsumer.java:95-97
Blob blob = getStorageClient().get(bucketName, fileName);
exchanges = createExchanges(blob, fileName);
{code}
When the configured objectName does not exist the poll throws an NPE on every 
cycle. That path also never calls {{forceConsumerAsReady()}} (only the list 
path at :110 does), so the consumer health check never becomes ready when 
objectName is set.

4. Header/configuration precedence is inverted between the two lookups:
{code:java}
// determineObjectName:374-383 - configuration first
String key = getConfiguration().getObjectName();
if (ObjectHelper.isEmpty(key)) { key = exchange.getIn().getHeader(OBJECT_NAME, 
String.class); }

// determineBucketName:385-394 - header first
String bucketName = exchange.getMessage().getHeader(OVERRIDE_BUCKET_NAME, 
String.class);
if (ObjectHelper.isEmpty(bucketName)) { bucketName = 
getConfiguration().getBucketName(); }
{code}
{{CamelGoogleCloudStorageObjectName}} is documented as "The object Name which 
will be used for the current operation" but is ignored whenever the endpoint 
configures objectName. Note this one is a behaviour change and may deserve an 
upgrade-guide note.

Minor items in the same file: {{createDownloadLink}} (:234-241) has an 
unreachable else-branch because the header lookup already supplies a 300000L 
default, and the file uses a {{java.util.*}} wildcard import.

Found during a source audit of the {{components/camel-google}} module family 
against main @ c3b01310be15.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to