Claus Ibsen created CAMEL-27189:
-----------------------------------

             Summary: camel-google-storage - no type converter from String to 
StorageClass
                 Key: CAMEL-27189
                 URL: https://issues.apache.org/jira/browse/CAMEL-27189
             Project: Camel
          Issue Type: Bug
          Components: camel-google-storage
            Reporter: Claus Ibsen


h3. What happens

The {{storageClass}} option (component and endpoint) is typed 
{{com.google.cloud.storage.StorageClass}}. That class is not a Java enum but a 
{{com.google.cloud.StringEnumValue}} with static constants and 
{{valueOf(String)}}, and Camel has no type converter for it. So the option 
cannot be set from an endpoint URI or a property, even with the value the 
catalog shows as default ({{STANDARD}}):

{code}
google-storage://coldbucket?autoCreateBucket=true&storageClass=NEARLINE&storageLocation=EU
{code}

{noformat}
org.apache.camel.ResolveEndpointFailedException: Failed to resolve endpoint: 
google-storage://coldbucket?autoCreateBucket=true&storageClass=NEARLINE&storageLocation=EU
 due to: Error binding property (storageClass=NEARLINE) with name: storageClass 
on bean: google-storage://coldbucket?... with value: NEARLINE: No type 
converter available to convert from type: java.lang.String to the required 
type: com.google.cloud.storage.StorageClass
{noformat}

Only a bean reference ({{#bean:...}}) or Java DSL configuration works. The 
Kamelet {{google-storage-sink}} cannot offer a {{storageClass}} option because 
of this.

h3. Where

* 
{{components/camel-google/camel-google-storage/src/main/java/org/apache/camel/component/google/storage/GoogleCloudStorageConfiguration.java}}:
 {{private StorageClass storageClass = StorageClass.STANDARD}} / 
{{setStorageClass(StorageClass)}}.
* The component has no {{@Converter}} class.

h3. Suggested fix

Add a type converter in camel-google-storage, e.g.

{code:java}
@Converter(generateLoader = true)
public final class GoogleCloudStorageConverter {
    @Converter
    public static StorageClass toStorageClass(String value) {
        return 
StorageClass.valueOfStrict(value.trim().toUpperCase(Locale.ROOT));
    }
}
{code}

({{valueOfStrict}} rejects an unknown class instead of creating one.) 
Optionally list the known values ({{STANDARD}}, {{NEARLINE}}, {{COLDLINE}}, 
{{ARCHIVE}}, ...) as {{enums}} in the {{@UriParam}} so tooling can offer them.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to