This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel-spring-boot.git
The following commit(s) were added to refs/heads/main by this push: new 817f9b50379 CAMEL-18425: camel-cli - Make regular Camel applications work with Camel CLI 817f9b50379 is described below commit 817f9b50379ba3e4d1e013d28773a3499848c9ca Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Sat Aug 27 09:20:45 2022 +0200 CAMEL-18425: camel-cli - Make regular Camel applications work with Camel CLI --- .../connector/CliConnectorAutoConfiguration.java | 19 ++++++----- .../cli/connector/SpringCliConnectorFactory.java | 39 ++++++++++++++++++++++ .../cli/connector/SpringLocalCliConnector.java | 38 +++++++++++++++++++++ 3 files changed, 87 insertions(+), 9 deletions(-) diff --git a/components-starter/camel-cli-connector-starter/src/main/java/org/apache/camel/springboot/cli/connector/CliConnectorAutoConfiguration.java b/components-starter/camel-cli-connector-starter/src/main/java/org/apache/camel/springboot/cli/connector/CliConnectorAutoConfiguration.java index e11d4a38e47..c3ca214dd29 100644 --- a/components-starter/camel-cli-connector-starter/src/main/java/org/apache/camel/springboot/cli/connector/CliConnectorAutoConfiguration.java +++ b/components-starter/camel-cli-connector-starter/src/main/java/org/apache/camel/springboot/cli/connector/CliConnectorAutoConfiguration.java @@ -16,8 +16,11 @@ */ package org.apache.camel.springboot.cli.connector; -import org.apache.camel.CamelContext; -import org.apache.camel.cli.connector.DefaultCliConnectorFactory; +import java.io.InputStream; +import java.net.URL; +import java.util.Enumeration; +import java.util.jar.Manifest; + import org.apache.camel.spi.CliConnectorFactory; import org.springframework.boot.SpringBootVersion; import org.springframework.boot.autoconfigure.AutoConfigureAfter; @@ -27,11 +30,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; - -import java.io.InputStream; -import java.net.URL; -import java.util.Enumeration; -import java.util.jar.Manifest; +import org.springframework.context.support.AbstractApplicationContext; @Configuration(proxyBeanMethods = false) @ConditionalOnProperty(name = "camel.cli.enabled", matchIfMissing = true) @@ -42,8 +41,10 @@ public class CliConnectorAutoConfiguration { @Bean @ConditionalOnMissingBean(CliConnectorFactory.class) - public CliConnectorFactory cliConnectorFactory(CamelContext camelContext, CliConnectorConfiguration config) { - CliConnectorFactory answer = new DefaultCliConnectorFactory(); + public CliConnectorFactory cliConnectorFactory(AbstractApplicationContext applicationContext, + CliConnectorConfiguration config) { + + CliConnectorFactory answer = new SpringCliConnectorFactory(applicationContext); answer.setEnabled(config.getEnabled()); answer.setRuntime("Spring Boot"); answer.setRuntimeVersion(SpringBootVersion.getVersion()); diff --git a/components-starter/camel-cli-connector-starter/src/main/java/org/apache/camel/springboot/cli/connector/SpringCliConnectorFactory.java b/components-starter/camel-cli-connector-starter/src/main/java/org/apache/camel/springboot/cli/connector/SpringCliConnectorFactory.java new file mode 100644 index 00000000000..dbcb2e93e11 --- /dev/null +++ b/components-starter/camel-cli-connector-starter/src/main/java/org/apache/camel/springboot/cli/connector/SpringCliConnectorFactory.java @@ -0,0 +1,39 @@ +/* + * 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.springboot.cli.connector; + +import org.apache.camel.cli.connector.DefaultCliConnectorFactory; +import org.apache.camel.spi.CliConnector; +import org.springframework.context.support.AbstractApplicationContext; + +public class SpringCliConnectorFactory extends DefaultCliConnectorFactory { + + private final AbstractApplicationContext applicationContext; + + public SpringCliConnectorFactory(AbstractApplicationContext applicationContext) { + this.applicationContext = applicationContext; + } + + @Override + public CliConnector createConnector() { + if (isEnabled()) { + return new SpringLocalCliConnector(applicationContext); + } else { + return null; + } + } +} diff --git a/components-starter/camel-cli-connector-starter/src/main/java/org/apache/camel/springboot/cli/connector/SpringLocalCliConnector.java b/components-starter/camel-cli-connector-starter/src/main/java/org/apache/camel/springboot/cli/connector/SpringLocalCliConnector.java new file mode 100644 index 00000000000..8edfe228609 --- /dev/null +++ b/components-starter/camel-cli-connector-starter/src/main/java/org/apache/camel/springboot/cli/connector/SpringLocalCliConnector.java @@ -0,0 +1,38 @@ +/* + * 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.springboot.cli.connector; + +import org.apache.camel.cli.connector.LocalCliConnector; +import org.springframework.context.support.AbstractApplicationContext; + +public class SpringLocalCliConnector extends LocalCliConnector { + + private final AbstractApplicationContext applicationContext; + + public SpringLocalCliConnector(AbstractApplicationContext applicationContext) { + this.applicationContext = applicationContext; + } + + @Override + public void sigterm() { + try { + super.sigterm(); + } finally { + applicationContext.stop(); + } + } +}