You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by "christophd (via GitHub)" <gi...@apache.org> on 2023/06/26 10:19:30 UTC

[GitHub] [camel] christophd opened a new pull request, #10493: CAMEL-18698: Add support for multiple input/output data types on components

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

   # Description
   
   <!--
   - Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
   -->
   
   This PR enhances the mechanism of input/output DataType and Transformer in order to support multiple data types on components as described in https://issues.apache.org/jira/browse/CAMEL-18698
   
   The existing Transformer and DataType support is enhanced with
   
   - Add data type to transform EIP resulting in a transformation from given type to target type using a matching transformer implementation
   - Enhance data type transformer resolving mechanism to support:
     - Lazy loading of transformer implementations via resource path factory finder
     - Add annotation based transformer loader (adds possibility to load transformer implementations with classpath scan)
   - Add possibility to configure preloading of default Camel transformer implementations
   - Add default Camel transformer implementations for String and byte[]
   - Add CloudEvents transformer implementation to transform any Camel Exchange into CloudEvent using Http or Json binding
   - Add AWS S3 CloudEvents transformer implementation to transform getObject response into proper CloudEvent
   
   The idea is to add Transformer implementations to Camel components that match data type information given on the route as an input/output type. Based on that data type contract the Camel internal advice will automatically resolve matching transformer implementations and apply its data type transformation logic as part of the route. Transformer implementations may be preloaded via Camel context configuration or lazy loaded via factory finder resource path lookup.
   
   Users may also explicitly use a transform EIP as part of the route and provide a target data type as an outcome of the transformation. Based on that data type information the same Transformer resolving mechanism may find a matching transformer implementation and apply its logic.
   
   This enhances the declarative contract based data type transformation in routes and suits best for usage in KameletBindings where the user declaratively specifies input/output data types as part of a binding. Each Kamelet may expose supported supported data type specifications for input and output and leverage the provided transformer implementations in Camel components.
   
   As an example this PR adds transformer implementations for CloudEvents (Http and Json binding) so users may transform any Exchange data into a proper CloudEvent by just specifying the respective data type (`http:application/cloudevents` or `application/cloudevents+json`). The AWS S3 component also adds a new transformer implementation (`aws2-s3:application-cloudevents`) to create a proper CloudEvent with attributes filled from the data coming from the AWS S3 getObject response. This way the user is able to use the same AWS S3 component to properly create CloudEvent data type format.
   
   Example:
   ```yaml
   apiVersion: camel.apache.org/v1alpha1
   kind: KameletBinding
   metadata:
     name: aws-s3-cloudevents-source                  
   spec:
     source:
       ref:
         kind: Kamelet
         apiVersion: camel.apache.org/v1
         name: aws2-s3-source
       dataTypes:
         out:
           format: aws2-s3:application/cloudevents
       properties:
         [...]
     sink:
       ref:
         kind: Kamelet
         apiVersion: camel.apache.org/v1
         name: http-sink
       dataTypes:
         in:
           format: application/cloudevents+json
       properties:
         url: http:localhost:8080
   ```
   
   The binding uses the component specific `aws2-s3:application/cloudevents` data type in order to apply the CloudEvent transformation provided in the aws2-s3 component (sets CloudEvent attributes with data from the getObject response). Then in the sink the `application/cloudevents+json` input data type is used to transform the S3 event into a proper CloudEvent Json binding.
   
   Successor PR for #8694
   Closes #8694 
   
   # Target
   
   - [x] I checked that the commit is targeting the correct branch (note that Camel 3 uses `camel-3.x`, whereas Camel 4 uses the `main` branch)
   
   # Tracking
   - [x] 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).
   https://issues.apache.org/jira/browse/CAMEL-18698
   
   <!--
   # *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 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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel] github-actions[bot] commented on pull request #10493: CAMEL-18698: Add support for multiple input/output data types on components

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #10493:
URL: https://github.com/apache/camel/pull/10493#issuecomment-1611796489

   :leftwards_arrow_with_hook: There are either **too many** changes to be tested in this PR or the code **needs be rebased**: (30 components likely to be affected)


-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel] christophd commented on a diff in pull request #10493: CAMEL-18698: Add support for multiple input/output data types on components

Posted by "christophd (via GitHub)" <gi...@apache.org>.
christophd commented on code in PR #10493:
URL: https://github.com/apache/camel/pull/10493#discussion_r1243660472


##########
core/camel-core-model/src/main/java/org/apache/camel/model/transformer/LoadTransformerDefinition.java:
##########
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.model.transformer;
+
+import jakarta.xml.bind.annotation.XmlAccessType;
+import jakarta.xml.bind.annotation.XmlAccessorType;
+import jakarta.xml.bind.annotation.XmlAttribute;
+import jakarta.xml.bind.annotation.XmlType;
+
+import org.apache.camel.spi.Metadata;
+
+/**
+ * Loads one to many {@link org.apache.camel.spi.Transformer} via {@link org.apache.camel.spi.TransformerLoader}.
+ * Supports classpath scan to load transformer implementations configured for instance via annotation configuration.
+ */
+@Metadata(label = "transformation")
+@XmlType(name = "loadTransformer")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class LoadTransformerDefinition extends TransformerDefinition {
+
+    @XmlAttribute
+    private String packageScan;
+
+    @XmlAttribute
+    private Boolean defaults = false;

Review Comment:
   good point. will do, thx



-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel] oscerd commented on pull request #10493: CAMEL-18698: Add support for multiple input/output data types on components

Posted by "oscerd (via GitHub)" <gi...@apache.org>.
oscerd commented on PR #10493:
URL: https://github.com/apache/camel/pull/10493#issuecomment-1619763218

   I'm fine with merging and see how it goes on CI. Go ahead.


-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel] github-actions[bot] commented on pull request #10493: CAMEL-18698: Add support for multiple input/output data types on components

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #10493:
URL: https://github.com/apache/camel/pull/10493#issuecomment-1611510636

   ### Components test results:
   
   | Total | Tested | Failed :x: | Passed :white_check_mark: | 
   | --- | --- | --- |  --- |
   | 6 | 6 | 1 | 5 |


-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel] github-actions[bot] commented on pull request #10493: CAMEL-18698: Add support for multiple input/output data types on components

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #10493:
URL: https://github.com/apache/camel/pull/10493#issuecomment-1611510675

   ### Core test results:
   
   | Tested | Failed :x: | Passed :white_check_mark: | 
   | --- | --- |  --- |
   | 1 | 1 | 0 |


-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel] github-actions[bot] commented on pull request #10493: CAMEL-18698: Add support for multiple input/output data types on components

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #10493:
URL: https://github.com/apache/camel/pull/10493#issuecomment-1611796526

   ### Core test results:
   
   | Tested | Failed :x: | Passed :white_check_mark: | 
   | --- | --- |  --- |
   | 1 | 1 | 0 |


-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel] christophd commented on pull request #10493: CAMEL-18698: Add support for multiple input/output data types on components

Posted by "christophd (via GitHub)" <gi...@apache.org>.
christophd commented on PR #10493:
URL: https://github.com/apache/camel/pull/10493#issuecomment-1612605033

   @oscerd I was able to fix a broken `xref:` link in the documentation but the failing unit tests in `camel-core` seem to not be related to my changes. is that possible?
   
   ```
   [camel-core] [ERROR] Failures: 
   [camel-core] [ERROR]   FileConsumerMoveExpressionTest.testRenameToId mock://result Body of message: 0. Expected: <Hello World> but was: <>
   [camel-core] [ERROR]   SchedulerNoPolledMessagesTest.testSchedulerNoPolledMessages Assertion error at index 1 on mock mock://result with predicate: arrives no later than 500 milliseconds before next (delta: 535 millis) exchange on Exchange[C9EA20FDC190658-0000000000000001]
   [camel-core] [ERROR]   DurationRoutePolicyFactoryTest.testDurationRoutePolicyFactory:40->ContextTestSupport.assertMockEndpointsSatisfied:357 mock://foo Received message count 1, expected at least 10
   [camel-core] [ERROR]   DurationRoutePolicyMaxSecondsTest.testDurationRoutePolicy:40->ContextTestSupport.assertMockEndpointsSatisfied:357 mock://foo Received message count 1, expected at least 10
   [camel-core] [ERROR]   LimitedPollingConsumerPollStrategyTest.testRestartManuallyLimitedPollingConsumerPollStrategy:189 Should still be started ==> expected: <true> but was: <false>
   [camel-core] [ERROR]   ScheduledPollConsumerTest.testRetryAtMostThreeTimes:114 expected: <4> but was: <8>
   [camel-core] [ERROR]   ResequenceStreamRejectOldExchangesTest.testDuplicateAfterCapacityReached:52->ContextTestSupport.assertMockEndpointsSatisfied:357 mock://result Received message count. Expected: <3> but was: <4>
   [camel-core] [ERROR]   AsyncProcessorAwaitManagerInterruptWithRedeliveryTest.testAsyncAwaitInterrupt:66 Should throw exception
   [camel-core] [ERROR] Errors: 
   [camel-core] [ERROR] org.apache.camel.processor.SplitParallelTimeoutTest.testSplitParallelTimeout
   [camel-core] [ERROR]   Run 1: SplitParallelTimeoutTest.testSplitParallelTimeout ยป Timeout testSplitParallelTimeout() timed out after 50 seconds
   ```


-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel] christophd commented on pull request #10493: CAMEL-18698: Add support for multiple input/output data types on components

Posted by "christophd (via GitHub)" <gi...@apache.org>.
christophd commented on PR #10493:
URL: https://github.com/apache/camel/pull/10493#issuecomment-1619689470

   @oscerd have you seen such errors in other PRs too or is this something specific to this one?


-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel] christophd commented on pull request #10493: CAMEL-18698: Add support for multiple input/output data types on components

Posted by "christophd (via GitHub)" <gi...@apache.org>.
christophd commented on PR #10493:
URL: https://github.com/apache/camel/pull/10493#issuecomment-1607159966

   FYI @igarashitm 


-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel] github-actions[bot] commented on pull request #10493: CAMEL-18698: Add support for multiple input/output data types on components

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #10493:
URL: https://github.com/apache/camel/pull/10493#issuecomment-1610905761

   ### Components test results:
   
   | Total | Tested | Failed :x: | Passed :white_check_mark: | 
   | --- | --- | --- |  --- |
   | 6 | 6 | 1 | 5 |


-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel] github-actions[bot] commented on pull request #10493: CAMEL-18698: Add support for multiple input/output data types on components

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #10493:
URL: https://github.com/apache/camel/pull/10493#issuecomment-1607159881

   :star2: Thank you for your contribution to the Apache Camel project! :star2: 
   
   :camel: Maintainers, please note that first-time contributors *require manual approval* for the GitHub Actions to run.
   
   :warning: Please note that the changes on this PR may be **tested automatically** if they change components.
   
   :robot: Use the command `/component-test (camel-)component-name1 (camel-)component-name2..` to request a test from the test bot.
   
   If necessary Apache Camel Committers may access logs and test results in the job summaries!


-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel] christophd commented on pull request #10493: CAMEL-18698: Add support for multiple input/output data types on components

Posted by "christophd (via GitHub)" <gi...@apache.org>.
christophd commented on PR #10493:
URL: https://github.com/apache/camel/pull/10493#issuecomment-1619758012

   I have had a look and all these unit tests relate to some kind of timing (e.g. timeouts, waiting periods, etc.). I guess the GitHub actions workflow is just pretty darn slow. All tests run successfully on my local machine and as it seems also in ci-builds.apache.org


-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel] github-actions[bot] commented on pull request #10493: CAMEL-18698: Add support for multiple input/output data types on components

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #10493:
URL: https://github.com/apache/camel/pull/10493#issuecomment-1611864466

   ### Core test results:
   
   | Tested | Failed :x: | Passed :white_check_mark: | 
   | --- | --- |  --- |
   | 1 | 1 | 0 |


-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel] christophd commented on pull request #10493: CAMEL-18698: Add support for multiple input/output data types on components

Posted by "christophd (via GitHub)" <gi...@apache.org>.
christophd commented on PR #10493:
URL: https://github.com/apache/camel/pull/10493#issuecomment-1609655283

   @davsclaus many thanks for your review! Done with incorporating the changes
   
   You even had a good antenna for the additional plain route YAML DSL test. There was a YAML deserializer option missing for these data types. So now it is working as expected!


-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel] christophd commented on a diff in pull request #10493: CAMEL-18698: Add support for multiple input/output data types on components

Posted by "christophd (via GitHub)" <gi...@apache.org>.
christophd commented on code in PR #10493:
URL: https://github.com/apache/camel/pull/10493#discussion_r1243662025


##########
core/camel-core-reifier/src/main/java/org/apache/camel/reifier/TransformReifier.java:
##########
@@ -31,6 +32,10 @@ public TransformReifier(Route route, ProcessorDefinition<?> definition) {
 
     @Override
     public Processor createProcessor() throws Exception {
+        if (definition.getToType() != null) {
+            return new DataTypeProcessor(definition.getFromType(), definition.getToType());

Review Comment:
   yes ๐Ÿ‘ 



-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel] github-actions[bot] commented on pull request #10493: CAMEL-18698: Add support for multiple input/output data types on components

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #10493:
URL: https://github.com/apache/camel/pull/10493#issuecomment-1611864445

   :leftwards_arrow_with_hook: There are either **too many** changes to be tested in this PR or the code **needs be rebased**: (30 components likely to be affected)


-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel] christophd merged pull request #10493: CAMEL-18698: Add support for multiple input/output data types on components

Posted by "christophd (via GitHub)" <gi...@apache.org>.
christophd merged PR #10493:
URL: https://github.com/apache/camel/pull/10493


-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel] oscerd commented on pull request #10493: CAMEL-18698: Add support for multiple input/output data types on components

Posted by "oscerd (via GitHub)" <gi...@apache.org>.
oscerd commented on PR #10493:
URL: https://github.com/apache/camel/pull/10493#issuecomment-1619692845

   No and on CI there is no trace of these failures:
   https://ci-builds.apache.org/job/Camel/job/Camel%20JDK17/job/main/976/#showFailuresLink


-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel] github-actions[bot] commented on pull request #10493: CAMEL-18698: Add support for multiple input/output data types on components

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #10493:
URL: https://github.com/apache/camel/pull/10493#issuecomment-1610905795

   ### Core test results:
   
   | Tested | Failed :x: | Passed :white_check_mark: | 
   | --- | --- |  --- |
   | 1 | 1 | 0 |


-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel] christophd commented on a diff in pull request #10493: CAMEL-18698: Add support for multiple input/output data types on components

Posted by "christophd (via GitHub)" <gi...@apache.org>.
christophd commented on code in PR #10493:
URL: https://github.com/apache/camel/pull/10493#discussion_r1243661158


##########
core/camel-core-processor/src/main/java/org/apache/camel/processor/transformer/bytes/ByteArrayDataTypeTransformer.java:
##########
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.camel.processor.transformer.bytes;

Review Comment:
   moving to parent package is ok



-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel] davsclaus commented on a diff in pull request #10493: CAMEL-18698: Add support for multiple input/output data types on components

Posted by "davsclaus (via GitHub)" <gi...@apache.org>.
davsclaus commented on code in PR #10493:
URL: https://github.com/apache/camel/pull/10493#discussion_r1243143710


##########
core/camel-core-model/src/main/java/org/apache/camel/model/transformer/LoadTransformerDefinition.java:
##########
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.model.transformer;
+
+import jakarta.xml.bind.annotation.XmlAccessType;
+import jakarta.xml.bind.annotation.XmlAccessorType;
+import jakarta.xml.bind.annotation.XmlAttribute;
+import jakarta.xml.bind.annotation.XmlType;
+
+import org.apache.camel.spi.Metadata;
+
+/**
+ * Loads one to many {@link org.apache.camel.spi.Transformer} via {@link org.apache.camel.spi.TransformerLoader}.
+ * Supports classpath scan to load transformer implementations configured for instance via annotation configuration.
+ */
+@Metadata(label = "transformation")
+@XmlType(name = "loadTransformer")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class LoadTransformerDefinition extends TransformerDefinition {
+
+    @XmlAttribute
+    private String packageScan;
+
+    @XmlAttribute
+    private Boolean defaults = false;

Review Comment:
   Use String type, as all options in EIP should be configurable via placeholder. See other EIPs how they do it for "boolean" types.



##########
core/camel-core-processor/src/main/java/org/apache/camel/processor/transformer/bytes/ByteArrayDataTypeTransformer.java:
##########
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.camel.processor.transformer.bytes;

Review Comment:
   Do you really need this to be in its own package for just 1 class? IMHO move it to parent package



##########
core/camel-core-processor/src/main/java/org/apache/camel/processor/transformer/text/StringDataTypeTransformer.java:
##########
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.camel.processor.transformer.text;

Review Comment:
   Do you really need this to be in its own package for just 1 class? IMHO move it to parent package



##########
docs/user-manual/modules/ROOT/pages/transformer.adoc:
##########
@@ -134,6 +175,66 @@ XML DSL:
 <customTransformer className="com.example.MyCustomTransformer" fromType="xml" toType="json"/>
 ----
 
+== Load Transformer Options
+
+Users are able to preload known default transformers. Also users may load transformers via classpath scan.
+
+[width="100%",cols="25%,75%",options="header",]
+|===
+| Name | Description
+| defaults | Loads known default transformer implementations (e.g. plain-text, application-octet-stream)
+| location | Classpath location to scan for transformer implementations. Transformer implementations must use the `org.apache.camel.spi.DataTypeTransformer` annotation to get recognized by the scanner.
+|===
+
+Here is an example to load default Transformer classes:
+
+Java DSL:

Review Comment:
   Same here with TABs



##########
core/camel-core-reifier/src/main/java/org/apache/camel/reifier/TransformReifier.java:
##########
@@ -31,6 +32,10 @@ public TransformReifier(Route route, ProcessorDefinition<?> definition) {
 
     @Override
     public Processor createProcessor() throws Exception {
+        if (definition.getToType() != null) {
+            return new DataTypeProcessor(definition.getFromType(), definition.getToType());

Review Comment:
   Hmm I think we may need to throw an illegal argument exception if you have configured toType and also expression. It seems that this is not possible.



##########
docs/user-manual/modules/ROOT/pages/transformer.adoc:
##########
@@ -30,20 +31,60 @@ a wildcard.
 | Data Format Transformer | Transform with using Data Format
 | Endpoint Transformer | Transform with using Endpoint
 | Custom Transformer | Transform with using custom transformer class. Transformer must be a subclass of `org.apache.camel.spi.Transformer`
+| Loading Transformer | Loads multiple transformer implementations (e.g. via annotation classpath scan). Also preloads known default Camel transformer implementations.
 |===
 
 === Common Options
 
-All transformers have following common options to specify which data type is supported by the transformer. `scheme` or both of `fromType` and `toType` must be specified.
+All transformers have following common options to specify which data type is supported by the transformer. `name` or both of `fromType` and `toType` must be specified.
 
 [width="100%",cols="25%,75%",options="header",]
 |===
 | Name | Description
-| scheme | Type of data model like `xml` or `json`. For example if `xml` is specified, the transformer is applied for all java -&gt; xml and xml -&gt; java transformation.
+| scheme | The supported data type scheme. It is possible to just reference a scheme like `xml` or `json`. For example if `xml` is specified, the transformer is applied for all java -&gt; xml and xml -&gt; java transformation.
+| name | The name of the transformer. If name is specified users may use a combination of a scheme and name (e.g. `xml:Order`) to reference the transformer in a route.
 | fromType | xref:transformer.adoc[Data type] to transform from.
 | toType | xref:transformer.adoc[Data type] to transform to.
 |===
 
+Transformer implementations may use `scheme:name` or the combination of `fromType/toType` as an identifier.
+
+When using the `scheme:name` identifier users may reference the transformer by its full name in a route.
+
+Java DSL:

Review Comment:
   Use the new TABS for having examples in different DSLs



##########
dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/groovy/org/apache/camel/dsl/yaml/KameletBindingLoaderTest.groovy:
##########
@@ -621,4 +622,100 @@ class KameletBindingLoaderTest extends YamlTestSupport {
         context.resolvePropertyPlaceholders("{{MY_ENV}}") == "cheese"
     }
 
+    def "kamelet binding with input/output data types"() {

Review Comment:
   Can you also add tests that are not kamelet bindings, eg a plain route



-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org