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 c028439  Revert "CAMEL-16032 [camel-main] autoconfiguration does not 
bind dataformat in the registry (#4887)"
c028439 is described below

commit c028439311e4672725e288720c2047410b90c3f9
Author: Claus Ibsen <claus.ib...@gmail.com>
AuthorDate: Fri Jan 15 15:42:06 2021 +0100

    Revert "CAMEL-16032 [camel-main] autoconfiguration does not bind dataformat 
in the registry (#4887)"
    
    This reverts commit 837926ab18716cb7bd79e7e0835069758847c351.
---
 .../camel/impl/engine/AbstractCamelContext.java    | 26 ++++-----
 .../dataformat/DataFormatRegistrationTest.java     | 57 --------------------
 .../camel/model/dataformat/DummyDataformat.java    | 63 ----------------------
 .../services/org/apache/camel/dataformat/dummy     |  1 -
 4 files changed, 13 insertions(+), 134 deletions(-)

diff --git 
a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
 
b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
index c4488fe..b5d7364 100644
--- 
a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
+++ 
b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
@@ -29,7 +29,6 @@ import java.util.LinkedHashMap;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
-import java.util.Optional;
 import java.util.Properties;
 import java.util.Set;
 import java.util.TreeMap;
@@ -3782,24 +3781,25 @@ public abstract class AbstractCamelContext extends 
BaseService
 
     @Override
     public DataFormat resolveDataFormat(String name) {
-        final DataFormat answer = dataformats.computeIfAbsent(name, s -> {
-            DataFormat df = Optional
-                    
.ofNullable(ResolverHelper.lookupDataFormatInRegistryWithFallback(getCamelContextReference(),
 name))
-                    .orElseGet(() -> 
getDataFormatResolver().createDataFormat(name, getCamelContextReference()));
+        final DataFormat answer = dataformats.computeIfAbsent(name, new 
Function<String, DataFormat>() {
+            @Override
+            public DataFormat apply(String s) {
+                DataFormat df = 
ResolverHelper.lookupDataFormatInRegistryWithFallback(getCamelContextReference(),
 name);
 
-            if (df != null) {
-                // inject CamelContext if aware
-                CamelContextAware.trySetCamelContext(df, 
getCamelContextReference());
+                if (df != null) {
+                    // inject CamelContext if aware
+                    CamelContextAware.trySetCamelContext(df, 
getCamelContextReference());
 
-                for (LifecycleStrategy strategy : lifecycleStrategies) {
-                    strategy.onDataFormatCreated(name, df);
+                    for (LifecycleStrategy strategy : lifecycleStrategies) {
+                        strategy.onDataFormatCreated(name, df);
+                    }
                 }
-            }
 
-            return df;
+                return df;
+            }
         });
 
-        return answer;
+        return answer != null ? answer : createDataFormat(name);
     }
 
     @Override
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/model/dataformat/DataFormatRegistrationTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/model/dataformat/DataFormatRegistrationTest.java
deleted file mode 100644
index 8cafddd..0000000
--- 
a/core/camel-core/src/test/java/org/apache/camel/model/dataformat/DataFormatRegistrationTest.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * 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.dataformat;
-
-import java.lang.reflect.Field;
-import java.util.Map;
-
-import org.apache.camel.ContextTestSupport;
-import org.apache.camel.impl.engine.AbstractCamelContext;
-import org.apache.camel.spi.DataFormat;
-import org.junit.jupiter.api.Test;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-//CAMEL-16032
-public class DataFormatRegistrationTest extends ContextTestSupport {
-
-    @Test
-    public void shouldRegisterDataformatInCacheTest() throws Exception {
-        DummyDataformat df = (DummyDataformat) 
context.resolveDataFormat("dummy");
-        df.setName("DUMMMY");
-        df.setVersion("2.3.6");
-        Field field = 
AbstractCamelContext.class.getDeclaredField("dataformats");
-        field.setAccessible(true);
-        Map<String, DataFormat> dataformats = (Map) field.get(context);
-        assertThat(dataformats).containsKey("dummy");
-
-        DummyDataformat df2 = (DummyDataformat) 
context.resolveDataFormat("dummy");
-        dataformats = (Map) field.get(context);
-        assertThat(dataformats).containsKey("dummy");
-        assertThat(df2.getName()).isEqualTo(df.getName()).isEqualTo("DUMMMY");
-        
assertThat(df2.getVersion()).isEqualTo(df.getVersion()).isEqualTo("2.3.6");
-    }
-
-    @Test
-    public void missingDataformatTest() throws Exception {
-        DataFormat df = context.resolveDataFormat("nonExistent");
-        Field field = 
AbstractCamelContext.class.getDeclaredField("dataformats");
-        field.setAccessible(true);
-        Map<String, DataFormat> dataformats = (Map) field.get(context);
-        assertThat(dataformats).isEmpty();
-    }
-}
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/model/dataformat/DummyDataformat.java
 
b/core/camel-core/src/test/java/org/apache/camel/model/dataformat/DummyDataformat.java
deleted file mode 100644
index a736d23..0000000
--- 
a/core/camel-core/src/test/java/org/apache/camel/model/dataformat/DummyDataformat.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * 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.dataformat;
-
-import java.io.InputStream;
-import java.io.OutputStream;
-
-import org.apache.camel.Exchange;
-import org.apache.camel.spi.DataFormat;
-import org.apache.camel.spi.DataFormatName;
-import org.apache.camel.support.service.ServiceSupport;
-
-public class DummyDataformat extends ServiceSupport implements DataFormat, 
DataFormatName {
-
-    private String name;
-
-    private String version;
-
-    @Override
-    public void marshal(Exchange exchange, Object graph, OutputStream stream) 
throws Exception {
-
-    }
-
-    @Override
-    public Object unmarshal(Exchange exchange, InputStream stream) throws 
Exception {
-        return null;
-    }
-
-    @Override
-    public String getDataFormatName() {
-        return "dummy";
-    }
-
-    public String getName() {
-        return name;
-    }
-
-    public void setName(String name) {
-        this.name = name;
-    }
-
-    public String getVersion() {
-        return version;
-    }
-
-    public void setVersion(String version) {
-        this.version = version;
-    }
-}
diff --git 
a/core/camel-core/src/test/resources/META-INF/services/org/apache/camel/dataformat/dummy
 
b/core/camel-core/src/test/resources/META-INF/services/org/apache/camel/dataformat/dummy
deleted file mode 100644
index 3a22a41..0000000
--- 
a/core/camel-core/src/test/resources/META-INF/services/org/apache/camel/dataformat/dummy
+++ /dev/null
@@ -1 +0,0 @@
-class=org.apache.camel.model.dataformat.DummyDataformat
\ No newline at end of file

Reply via email to