From 140cc41bb1934dafd0c14c9bc2f09f74bd32072a Mon Sep 17 00:00:00 2001 From: lburgazzoli Date: Tue, 3 Sep 2019 00:25:59 +0200 Subject: [PATCH] Update to Camel RC1 #134 --- .../groovy/dsl/ComponentConfiguration.groovy | 14 ++++++---- .../js/dsl/IntegrationConfiguration.java | 2 +- .../k/loader/js/dsl/ProcessorSupport.java | 28 +++++++++++++++++++ .../k/loader/js/dsl/IntegrationTest.java | 8 ++---- .../test/resources/routes-with-processors.js | 12 ++++++-- .../knative/KnativeSourceRoutesLoader.java | 4 +-- camel-k-loader-yaml/README.adoc | 2 +- .../k/loader/yaml/parser/StepParser.java | 8 +++--- .../loader/yaml/parser/StepParserSupport.java | 11 ++++++-- .../camel/k/support/PropertiesSupport.java | 15 +++++----- .../camel/k/support/RuntimeSupport.java | 17 ++++++----- .../knative/http/KnativeHttpComponent.java | 10 ++++--- camel-knative/pom.xml | 2 +- .../component/knative/KnativeComponent.java | 22 ++++++++++----- .../component/knative/KnativeEndpoint.java | 2 -- .../component/knative/CloudEventsV01Test.java | 4 +-- .../component/knative/CloudEventsV02Test.java | 4 +-- .../knative/KnativeComponentTest.java | 4 +-- pom.xml | 2 +- .../maven/processors/CatalogProcessor3x.java | 2 +- .../processors/CatalogProcessor3Test.java | 6 ++-- 21 files changed, 114 insertions(+), 65 deletions(-) create mode 100644 camel-k-loader-js/src/main/java/org/apache/camel/k/loader/js/dsl/ProcessorSupport.java diff --git a/camel-k-loader-groovy/src/main/groovy/org/apache/camel/k/loader/groovy/dsl/ComponentConfiguration.groovy b/camel-k-loader-groovy/src/main/groovy/org/apache/camel/k/loader/groovy/dsl/ComponentConfiguration.groovy index d81d91497..8380c6039 100644 --- a/camel-k-loader-groovy/src/main/groovy/org/apache/camel/k/loader/groovy/dsl/ComponentConfiguration.groovy +++ b/camel-k-loader-groovy/src/main/groovy/org/apache/camel/k/loader/groovy/dsl/ComponentConfiguration.groovy @@ -16,8 +16,7 @@ */ package org.apache.camel.k.loader.groovy.dsl - -import org.apache.camel.support.IntrospectionSupport +import org.apache.camel.ExtendedCamelContext import org.apache.camel.support.PropertyBindingSupport class ComponentConfiguration { @@ -49,20 +48,23 @@ class ComponentConfiguration { } } - if (!PropertyBindingSupport.bindProperty(component.camelContext, component, name, value)) { + if (!PropertyBindingSupport.build().withCamelContext(component.camelContext).withTarget(component).withProperty(name, value).bind()) { throw new MissingMethodException(name, this.component.class, args as Object[]) } } def propertyMissing(String name, value) { - if (!PropertyBindingSupport.bindProperty(component.camelContext, component, name, value,)) { + if (!PropertyBindingSupport.build().withCamelContext(component.camelContext).withTarget(component).withProperty(name, value).bind()) { throw new MissingMethodException(name, this.component.class, value) } } def propertyMissing(String name) { - def properties = IntrospectionSupport.getProperties(component, properties, null, false) + def props = new HashMap() + def context = component.getCamelContext().adapt(ExtendedCamelContext.class) + + context.getBeanIntrospection().getProperties(component, props, null, false) - return properties[name] + return props[name] } } diff --git a/camel-k-loader-js/src/main/java/org/apache/camel/k/loader/js/dsl/IntegrationConfiguration.java b/camel-k-loader-js/src/main/java/org/apache/camel/k/loader/js/dsl/IntegrationConfiguration.java index 11fee49f9..904170b73 100644 --- a/camel-k-loader-js/src/main/java/org/apache/camel/k/loader/js/dsl/IntegrationConfiguration.java +++ b/camel-k-loader-js/src/main/java/org/apache/camel/k/loader/js/dsl/IntegrationConfiguration.java @@ -30,7 +30,7 @@ import org.apache.camel.model.rest.RestDefinition; import org.apache.camel.spi.Registry; -public class IntegrationConfiguration extends BuilderSupport implements EndpointBuilderFactory { +public class IntegrationConfiguration extends BuilderSupport implements EndpointBuilderFactory, ProcessorSupport { public final Registry registry; public final Components components; public final EndpointRouteBuilder builder; diff --git a/camel-k-loader-js/src/main/java/org/apache/camel/k/loader/js/dsl/ProcessorSupport.java b/camel-k-loader-js/src/main/java/org/apache/camel/k/loader/js/dsl/ProcessorSupport.java new file mode 100644 index 000000000..a7127f1b3 --- /dev/null +++ b/camel-k-loader-js/src/main/java/org/apache/camel/k/loader/js/dsl/ProcessorSupport.java @@ -0,0 +1,28 @@ +/* + * 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.k.loader.js.dsl; + +import java.util.function.Consumer; + +import org.apache.camel.Exchange; +import org.apache.camel.Processor; + +public interface ProcessorSupport { + default Processor processor(Consumer consumer) { + return e -> consumer.accept(e); + } +} \ No newline at end of file diff --git a/camel-k-loader-js/src/test/java/org/apache/camel/k/loader/js/dsl/IntegrationTest.java b/camel-k-loader-js/src/test/java/org/apache/camel/k/loader/js/dsl/IntegrationTest.java index 3f5545564..4e14a290d 100644 --- a/camel-k-loader-js/src/test/java/org/apache/camel/k/loader/js/dsl/IntegrationTest.java +++ b/camel-k-loader-js/src/test/java/org/apache/camel/k/loader/js/dsl/IntegrationTest.java @@ -108,11 +108,9 @@ public void testProcessors() throws Exception { runtime.addListener(Runtime.Phase.Started, r -> { ProducerTemplate template = r.getCamelContext().createProducerTemplate(); - String a = template.requestBody("direct:arrow", "", String.class); - assertThat(a).isEqualTo("arrow"); - - String f = template.requestBody("direct:function", "", String.class); - assertThat(f).isEqualTo("function"); + assertThat(template.requestBody("direct:arrow", "")).isEqualTo("arrow"); + assertThat(template.requestBody("direct:wrapper", "")).isEqualTo("wrapper"); + assertThat(template.requestBody("direct:function", "")).isEqualTo("function"); runtime.stop(); }); diff --git a/camel-k-loader-js/src/test/resources/routes-with-processors.js b/camel-k-loader-js/src/test/resources/routes-with-processors.js index 9d3514718..a4fe408c2 100644 --- a/camel-k-loader-js/src/test/resources/routes-with-processors.js +++ b/camel-k-loader-js/src/test/resources/routes-with-processors.js @@ -1,7 +1,15 @@ +const Processor = Java.type("org.apache.camel.Processor"); +const p = Java.extend(Processor); +const f = new p(function(e) { e.getMessage().setBody('function') }); +const a = new p(e => { e.getMessage().setBody('arrow') }); +const w = processor(e => { e.getMessage().setBody('wrapper') }); from('direct:function') - .process(function(e) { e.getMessage().setBody('function') }); + .process(f); from('direct:arrow') - .process(e => { e.getMessage().setBody('arrow') }); + .process(a); + +from('direct:wrapper') + .process(w); diff --git a/camel-k-loader-knative/src/main/java/org/apache/camel/k/loader/knative/KnativeSourceRoutesLoader.java b/camel-k-loader-knative/src/main/java/org/apache/camel/k/loader/knative/KnativeSourceRoutesLoader.java index dd7392cb7..be67dc93c 100644 --- a/camel-k-loader-knative/src/main/java/org/apache/camel/k/loader/knative/KnativeSourceRoutesLoader.java +++ b/camel-k-loader-knative/src/main/java/org/apache/camel/k/loader/knative/KnativeSourceRoutesLoader.java @@ -20,8 +20,8 @@ import java.util.List; import org.apache.camel.CamelContext; +import org.apache.camel.ExtendedCamelContext; import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.impl.engine.AbstractCamelContext; import org.apache.camel.k.RoutesLoader; import org.apache.camel.k.Source; import org.apache.camel.k.support.RuntimeSupport; @@ -90,7 +90,7 @@ public void addRoutesToCamelContext(CamelContext context) throws Exception { // to be registered to the camel registry but as the // original builder is masked by this wrapping builder, // beans can't be automatically discovered - context.adapt(AbstractCamelContext.class) + context.adapt(ExtendedCamelContext.class) .getBeanPostProcessor() .postProcessBeforeInitialization(builder, builder.getClass().getName()); diff --git a/camel-k-loader-yaml/README.adoc b/camel-k-loader-yaml/README.adoc index 587dcdaf9..1ee9b30ff 100644 --- a/camel-k-loader-yaml/README.adoc +++ b/camel-k-loader-yaml/README.adoc @@ -172,7 +172,7 @@ import org.apache.camel.k.loader.yaml.parser.ProcessorStepParser;public class Ac // create the definition ToDefinition to = new ToDefinition() - to.setUri(String.format("http4://%s:%d/fixed/path"), definition.host, definition.port) + to.setUri(String.format("http://%s:%d/fixed/path"), definition.host, definition.port) return to; } diff --git a/camel-k-loader-yaml/src/main/java/org/apache/camel/k/loader/yaml/parser/StepParser.java b/camel-k-loader-yaml/src/main/java/org/apache/camel/k/loader/yaml/parser/StepParser.java index 89888050b..1deeb25a2 100644 --- a/camel-k-loader-yaml/src/main/java/org/apache/camel/k/loader/yaml/parser/StepParser.java +++ b/camel-k-loader-yaml/src/main/java/org/apache/camel/k/loader/yaml/parser/StepParser.java @@ -32,10 +32,10 @@ public interface StepParser { static T lookup(CamelContext camelContext, Class type, String stepId) throws NoFactoryAvailableException { T converter = camelContext.getRegistry().lookupByNameAndType(stepId, type); if (converter == null) { - converter = (T) camelContext.adapt(ExtendedCamelContext.class).getFactoryFinder(RESOURCE_PATH).newInstance(stepId); - } - if (converter == null) { - throw new IllegalStateException("No handler for step with id: " + stepId); + converter = camelContext.adapt(ExtendedCamelContext.class) + .getFactoryFinder(RESOURCE_PATH) + .newInstance(stepId, type) + .orElseThrow(() -> new RuntimeException("No handler for step with id: " + stepId)); } return converter; diff --git a/camel-k-loader-yaml/src/main/java/org/apache/camel/k/loader/yaml/parser/StepParserSupport.java b/camel-k-loader-yaml/src/main/java/org/apache/camel/k/loader/yaml/parser/StepParserSupport.java index 7f5387a6b..38f395aec 100644 --- a/camel-k-loader-yaml/src/main/java/org/apache/camel/k/loader/yaml/parser/StepParserSupport.java +++ b/camel-k-loader-yaml/src/main/java/org/apache/camel/k/loader/yaml/parser/StepParserSupport.java @@ -16,15 +16,17 @@ */ package org.apache.camel.k.loader.yaml.parser; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; import org.apache.camel.CamelContext; +import org.apache.camel.ExtendedCamelContext; import org.apache.camel.k.loader.yaml.model.Step; import org.apache.camel.model.OutputNode; import org.apache.camel.model.ProcessorDefinition; -import org.apache.camel.support.IntrospectionSupport; +import org.apache.camel.spi.BeanIntrospection; import org.apache.camel.support.PropertyBindingSupport; import org.apache.camel.util.ObjectHelper; @@ -51,9 +53,12 @@ public static , I> T adaptProcessor(CamelContex } final T answer = context.getInjector().newInstance(type); - final Map properties = IntrospectionSupport.getNonNullProperties(instance); + final Map properties = new HashMap<>(); + final BeanIntrospection introspection = context.adapt(ExtendedCamelContext.class).getBeanIntrospection(); - PropertyBindingSupport.bindProperties(context, answer, properties); + if (introspection.getProperties(instance, properties, null, false)) { + PropertyBindingSupport.build().withCamelContext(context).withTarget(answer).withProperties(properties).bind(); + } return answer; } diff --git a/camel-k-runtime-core/src/main/java/org/apache/camel/k/support/PropertiesSupport.java b/camel-k-runtime-core/src/main/java/org/apache/camel/k/support/PropertiesSupport.java index 81ecf28b0..80427cb1b 100644 --- a/camel-k-runtime-core/src/main/java/org/apache/camel/k/support/PropertiesSupport.java +++ b/camel-k-runtime-core/src/main/java/org/apache/camel/k/support/PropertiesSupport.java @@ -25,7 +25,6 @@ import java.nio.file.Paths; import java.nio.file.SimpleFileVisitor; import java.nio.file.attribute.BasicFileAttributes; -import java.util.HashMap; import java.util.Map; import java.util.Objects; import java.util.Properties; @@ -41,6 +40,7 @@ public final class PropertiesSupport { private PropertiesSupport() { } + @SuppressWarnings("unchecked") public static boolean bindProperties(CamelContext context, Object target, String prefix) { final PropertiesComponent component = context.getComponent("properties", PropertiesComponent.class); final Properties properties = component.loadProperties(); @@ -49,12 +49,13 @@ public static boolean bindProperties(CamelContext context, Object target, String return false; } - Map props = new HashMap<>(); - for (String key : properties.stringPropertyNames()) { - props.put(key, properties.get(key)); - } - - return PropertyBindingSupport.bindProperties(context, target, props, prefix); + return PropertyBindingSupport.build() + .withCamelContext(context) + .withTarget(target) + .withProperties((Map)properties) + .withOptionPrefix(prefix) + .withRemoveParameters(false) + .bind(); } public static Properties loadProperties() { diff --git a/camel-k-runtime-core/src/main/java/org/apache/camel/k/support/RuntimeSupport.java b/camel-k-runtime-core/src/main/java/org/apache/camel/k/support/RuntimeSupport.java index 796b96ed0..e9ded8377 100644 --- a/camel-k-runtime-core/src/main/java/org/apache/camel/k/support/RuntimeSupport.java +++ b/camel-k-runtime-core/src/main/java/org/apache/camel/k/support/RuntimeSupport.java @@ -34,7 +34,6 @@ import org.apache.camel.k.ContextCustomizer; import org.apache.camel.k.RoutesLoader; import org.apache.camel.k.Source; -import org.apache.camel.spi.FactoryFinder; import org.apache.camel.util.ObjectHelper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -114,7 +113,10 @@ public static ContextCustomizer lookupCustomizerByID(CamelContext context, Strin ContextCustomizer customizer = context.getRegistry().lookupByNameAndType(customizerId, ContextCustomizer.class); if (customizer == null) { try { - customizer = (ContextCustomizer) context.adapt(ExtendedCamelContext.class).getFactoryFinder(Constants.CONTEXT_CUSTOMIZER_RESOURCE_PATH).newInstance(customizerId); + customizer = context.adapt(ExtendedCamelContext.class) + .getFactoryFinder(Constants.CONTEXT_CUSTOMIZER_RESOURCE_PATH) + .newInstance(customizerId, ContextCustomizer.class) + .orElseThrow(() -> new RuntimeException("Error creating instance for customizer: " + customizerId)); } catch (NoFactoryAvailableException e) { throw new RuntimeException(e); } @@ -177,16 +179,13 @@ public static RoutesLoader lookupLoaderByLanguage(CamelContext context, String l } public static RoutesLoader lookupLoaderFromResource(CamelContext context, String loaderId) { - final FactoryFinder finder; - final RoutesLoader loader; - try { - finder = context.adapt(ExtendedCamelContext.class).getFactoryFinder(Constants.ROUTES_LOADER_RESOURCE_PATH); - loader = (RoutesLoader)finder.newInstance(loaderId); + return context.adapt(ExtendedCamelContext.class) + .getFactoryFinder(Constants.ROUTES_LOADER_RESOURCE_PATH) + .newInstance(loaderId, RoutesLoader.class) + .orElseThrow(() -> new RuntimeException("Error creating instance of loader: " + loaderId)); } catch (NoFactoryAvailableException e) { throw new IllegalArgumentException("Unable to find loader for: " + loaderId, e); } - - return loader; } } diff --git a/camel-knative-http/src/main/java/org/apache/camel/component/knative/http/KnativeHttpComponent.java b/camel-knative-http/src/main/java/org/apache/camel/component/knative/http/KnativeHttpComponent.java index 24edb27c2..c03e6b8e9 100644 --- a/camel-knative-http/src/main/java/org/apache/camel/component/knative/http/KnativeHttpComponent.java +++ b/camel-knative-http/src/main/java/org/apache/camel/component/knative/http/KnativeHttpComponent.java @@ -24,6 +24,8 @@ import java.util.concurrent.Future; import java.util.regex.Matcher; +import static java.lang.Integer.*; + import io.vertx.core.Vertx; import io.vertx.core.VertxOptions; import io.vertx.core.http.HttpServerOptions; @@ -32,8 +34,8 @@ import org.apache.camel.spi.Metadata; import org.apache.camel.spi.annotations.Component; import org.apache.camel.support.DefaultComponent; -import org.apache.camel.support.IntrospectionSupport; import org.apache.camel.util.ObjectHelper; +import org.apache.camel.util.PropertiesHelper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -135,7 +137,7 @@ protected Endpoint createEndpoint(String uri, String remaining, Map org.apache.camel - camel-http4 + camel-http test diff --git a/camel-knative/src/main/java/org/apache/camel/component/knative/KnativeComponent.java b/camel-knative/src/main/java/org/apache/camel/component/knative/KnativeComponent.java index fa2405d3d..145ca9b07 100644 --- a/camel-knative/src/main/java/org/apache/camel/component/knative/KnativeComponent.java +++ b/camel-knative/src/main/java/org/apache/camel/component/knative/KnativeComponent.java @@ -23,15 +23,16 @@ import org.apache.camel.Endpoint; import org.apache.camel.spi.annotations.Component; import org.apache.camel.support.DefaultComponent; -import org.apache.camel.support.IntrospectionSupport; import org.apache.camel.support.PropertyBindingSupport; +import org.apache.camel.util.ObjectHelper; +import org.apache.camel.util.PropertiesHelper; import org.apache.camel.util.StringHelper; @Component("knative") public class KnativeComponent extends DefaultComponent { public static final String CONFIGURATION_ENV_VARIABLE = "CAMEL_KNATIVE_CONFIGURATION"; - private final KnativeConfiguration configuration; + private KnativeConfiguration configuration; private String environmentPath; public KnativeComponent() { @@ -50,6 +51,17 @@ public KnativeComponent(CamelContext context) { // // ************************ + public KnativeConfiguration getConfiguration() { + return configuration; + } + + /** + * Set the configuration. + */ + public void setConfiguration(KnativeConfiguration configuration) { + this.configuration = ObjectHelper.notNull(configuration, "configuration"); + } + public String getEnvironmentPath() { return environmentPath; } @@ -61,10 +73,6 @@ public void setEnvironmentPath(String environmentPath) { this.environmentPath = environmentPath; } - public KnativeConfiguration getConfiguration() { - return configuration; - } - public KnativeEnvironment getEnvironment() { return configuration.getEnvironment(); } @@ -116,7 +124,7 @@ protected Endpoint createEndpoint(String uri, String remaining, MapUTF-8 1.8 1.8 - 3.0.0-M4 + 3.0.0-RC1 ${camel.version} 5.5.1 0.9.12 diff --git a/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/processors/CatalogProcessor3x.java b/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/processors/CatalogProcessor3x.java index 9e83a103a..71046730d 100644 --- a/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/processors/CatalogProcessor3x.java +++ b/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/processors/CatalogProcessor3x.java @@ -335,7 +335,7 @@ public void process(MavenProject project, CamelCatalog catalog, Map { + artifacts.computeIfPresent("camel-http", (key, artifact) -> { artifact.addDependency("org.apache.camel", "camel-file"); return artifact; }); diff --git a/tooling/camel-k-maven-plugin/src/test/java/org/apache/camel/k/tooling/maven/processors/CatalogProcessor3Test.java b/tooling/camel-k-maven-plugin/src/test/java/org/apache/camel/k/tooling/maven/processors/CatalogProcessor3Test.java index daa06a22d..aec3841c3 100644 --- a/tooling/camel-k-maven-plugin/src/test/java/org/apache/camel/k/tooling/maven/processors/CatalogProcessor3Test.java +++ b/tooling/camel-k-maven-plugin/src/test/java/org/apache/camel/k/tooling/maven/processors/CatalogProcessor3Test.java @@ -78,7 +78,7 @@ public void testArtifactsEnrichment() { CatalogProcessor processor = new CatalogProcessor3x(); CamelCatalog catalog = versionCamelCatalog("3.0.0"); Map artifactMap = new HashMap<>(); - artifactMap.put("camel-http4", new CamelArtifact()); + artifactMap.put("camel-http", new CamelArtifact()); assertThat(processor.accepts(catalog)).isTrue(); processor.process(new MavenProject(), catalog, artifactMap); @@ -121,7 +121,7 @@ public void testArtifactsEnrichment() { ); }); - assertThat(artifactMap.get("camel-http4")).satisfies(a -> { + assertThat(artifactMap.get("camel-http")).satisfies(a -> { assertThat(a.getDependencies()).anyMatch( d -> d.getGroupId().equals("org.apache.camel") && d.getArtifactId().equals("camel-file") ); @@ -133,7 +133,7 @@ public void testLegacyArtifactsEnrichment() { CatalogProcessor processor = new CatalogProcessor3x(); CamelCatalog catalog = versionCamelCatalog("3.0.0"); Map artifactMap = new HashMap<>(); - artifactMap.put("camel-http4", new CamelArtifact()); + artifactMap.put("camel-http", new CamelArtifact()); assertThat(processor.accepts(catalog)).isTrue(); processor.process(new MavenProject(), catalog, artifactMap);