You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2021/01/16 10:01:12 UTC

[camel] branch camel-3.7.x updated: CAMEL-16032: camel-dataformat should create new instance instead of reusing previous/existing which then can become re-configured from endpoint parameters.

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch camel-3.7.x
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/camel-3.7.x by this push:
     new b0281f9  CAMEL-16032: camel-dataformat should create new instance instead of reusing previous/existing which then can become re-configured from endpoint parameters.
b0281f9 is described below

commit b0281f946c77f43e32aeb3463c027c00905b2113
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Sat Jan 16 10:59:59 2021 +0100

    CAMEL-16032: camel-dataformat should create new instance instead of reusing previous/existing which then can become re-configured from endpoint parameters.
---
 .../component/dataformat/DataFormatComponent.java    | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)

diff --git a/components/camel-dataformat/src/main/java/org/apache/camel/component/dataformat/DataFormatComponent.java b/components/camel-dataformat/src/main/java/org/apache/camel/component/dataformat/DataFormatComponent.java
index f75085f..86a86a1 100644
--- a/components/camel-dataformat/src/main/java/org/apache/camel/component/dataformat/DataFormatComponent.java
+++ b/components/camel-dataformat/src/main/java/org/apache/camel/component/dataformat/DataFormatComponent.java
@@ -37,23 +37,21 @@ public class DataFormatComponent extends DefaultComponent {
 
     @Override
     protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
-        String name = StringHelper.before(remaining, ":");
+        String operation = StringHelper.after(remaining, ":");
+        if (!"marshal".equals(operation) && !"unmarshal".equals(operation)) {
+            throw new IllegalArgumentException("Operation must be either marshal or unmarshal, was: " + operation);
+        }
 
-        // try to lookup data format in the registry or create it from resource
-        DataFormat df = getCamelContext().resolveDataFormat(name);
+        // create new data format as it is configured from the given parameters
+        String name = StringHelper.before(remaining, ":");
+        DataFormat df = getCamelContext().createDataFormat(name);
         if (df == null) {
-            // if not, try to find a factory in the registry
-            df = getCamelContext().createDataFormat(name);
+            // if not, try to lookup existing data format
+            df = getCamelContext().resolveDataFormat(name);
         }
         if (df == null) {
             throw new IllegalArgumentException("Cannot find data format with name: " + name);
         }
-
-        String operation = StringHelper.after(remaining, ":");
-        if (!"marshal".equals(operation) && !"unmarshal".equals(operation)) {
-            throw new IllegalArgumentException("Operation must be either marshal or unmarshal, was: " + operation);
-        }
-
         PropertyBindingSupport.bindProperties(getCamelContext(), df, parameters);
 
         DataFormatEndpoint endpoint = new DataFormatEndpoint(uri, this, df);