Claus Ibsen created CAMEL-27715:
-----------------------------------
Summary: camel-google-functions: NPE without project/location,
null service URL, no component options
Key: CAMEL-27715
URL: https://issues.apache.org/jira/browse/CAMEL-27715
Project: Camel
Issue Type: Bug
Components: camel-google-functions
Reporter: Claus Ibsen
Fix For: 4.24.0
Found while improving the option descriptions of camel-google-functions for
CAMEL-23832 (commit
https://github.com/apache/camel/commit/8c1fc0006f29a8e34341232d14b14fd25547e07c).
These are separate problems of the component; the descriptions commit only
documents the current behavior.
h4. 1. Missing project or location fails with a bare NullPointerException
Without pojoRequest, every operation builds a {{LocationName}} or
{{CloudFunctionName}} from the {{project}} and {{location}} options in
{{GoogleCloudFunctionsProducer}} (for example {{listFunctions()}} and
{{callFunction()}}). The SDK builders check their fields with
{{Preconditions.checkNotNull}}, so when one of the options is not set, the
first message fails with a {{NullPointerException}} that does not name the
option. The options are not marked as required.
Proposed change: check both options when the endpoint starts and pojoRequest is
false, and fail with a message that names the missing option.
h4. 2. getServiceUrl() returns functions:null:<name>:null
{{GoogleCloudFunctionsEndpoint.getServiceUrl()}} wraps a boolean in
{{ObjectHelper.isNotEmpty(...)}}:
{code:java}
if (ObjectHelper.isNotEmpty(configuration.getFunctionName()) &&
ObjectHelper.isNotEmpty(
ObjectHelper.isNotEmpty(configuration.getProject()) &&
ObjectHelper.isNotEmpty(configuration.getLocation()))) {
{code}
A boxed {{Boolean}} is never empty, so the inner check is always true. Without
project or location, the endpoint reports the service URL
{{functions:null:<functionName>:null}} instead of no URL.
Proposed change: drop the outer {{ObjectHelper.isNotEmpty}}.
h4. 3. No option can be set on the component
{{GoogleCloudFunctionsComponent}} has a {{configuration}} field with
{{@Metadata}}, and {{createEndpoint()}} copies it, but there is no setter. So
the component has only lazyStartProducer and autowiredEnabled, and
serviceAccountKey, project, location or client cannot be configured once for
all endpoints (for example with {{camel.component.google-functions.project}}).
Other Google components, such as google-storage and google-firestore, have
{{setConfiguration()}}.
Proposed change: add {{setConfiguration()}} so the configuration options become
component options too.
h4. 4. getFunction in POJO mode takes a CloudFunctionName
With pojoRequest=true, every operation reads its request class from the body
({{ListFunctionsRequest}}, {{CallFunctionRequest}}, {{DeleteFunctionRequest}},
...), but {{GoogleCloudFunctionsProducer.getFunction()}} reads a
{{CloudFunctionName}} instead of a {{GetFunctionRequest}}. A
{{GetFunctionRequest}} body fails with an {{InvalidPayloadException}}.
Proposed change: also accept a {{GetFunctionRequest}} body, and keep
{{CloudFunctionName}} for compatibility.
h4. 5. operation has no defaultValue
{{GoogleCloudFunctionsProducer.determineOperation()}} uses callFunction when
neither the header nor the option is set, but the {{operation}} option has no
{{defaultValue}}, so the catalog and tools do not show the default.
Proposed change: add {{defaultValue = "callFunction"}}.
h4. 6. pojoRequest has no label
The {{pojoRequest}} option of {{GoogleCloudFunctionsConfiguration}} has no
label, so it is listed as a common option, while only the producer reads it
(the component is producer only).
Proposed change: set {{label = "producer"}}.
h4. 7. Doc examples use a serviceAccountKey without a prefix
The examples in {{google-functions-component.adoc}} use
{{serviceAccountKey=/home/user/Downloads/my-key.json}}. The key is loaded with
{{ResourceHelper.resolveMandatoryResourceAsInputStream()}}, which reads a value
without a prefix from the classpath, so these examples do not read the file
from the file system.
Proposed change: use {{file:/home/user/Downloads/my-key.json}} in the examples.
_Claude Code on behalf of davsclaus_
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)