This is an automated email from the ASF dual-hosted git repository. gnodet pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
commit fa5eaad050e2caaef1182f84a3bf14e456e019d4 Author: Guillaume Nodet <[email protected]> AuthorDate: Tue Mar 3 19:48:20 2020 +0100 Use a single class instead of various resolvers --- .../camel/component/file/GenericFileEndpoint.java | 11 +--- .../org/apache/camel/ExtendedCamelContext.java | 3 +- .../java/org/apache/camel/spi/FactoryFinder.java | 2 + .../apache/camel/spi/FactoryFinderResolver.java | 4 +- .../component/properties/PropertiesComponent.java | 3 - .../camel/impl/engine/AbstractCamelContext.java | 36 ++++------ .../camel/impl/engine/BaseServiceResolver.java | 64 ++++++++++++++++++ .../impl/engine/BeanProcessorFactoryResolver.java | 72 -------------------- .../impl/engine/BeanProxyFactoryResolver.java | 72 -------------------- .../impl/engine/CamelPostProcessorHelper.java | 3 - .../impl/engine/DefaultFactoryFinderResolver.java | 5 -- .../impl/engine/HeadersMapFactoryResolver.java | 76 ---------------------- .../engine/PropertiesComponentFactoryResolver.java | 72 -------------------- .../impl/engine/ReactiveExecutorResolver.java | 73 --------------------- .../impl/engine/RestRegistryFactoryResolver.java | 75 --------------------- .../impl/engine/RuntimeCamelCatalogResolver.java | 76 ---------------------- .../org/apache/camel/builder/ProxyBuilder.java | 3 - .../org/apache/camel/impl/DefaultCamelContext.java | 55 +++++++++++----- .../camel/impl/ModelToXMLDumperResolver.java | 75 --------------------- .../impl/XMLRoutesDefinitionLoaderResolver.java | 76 ---------------------- .../java/org/apache/camel/reifier/BeanReifier.java | 3 - .../reifier/dataformat/DataFormatReifier.java | 20 ++---- .../camel/core/osgi/OsgiFactoryFinderResolver.java | 5 -- 23 files changed, 131 insertions(+), 753 deletions(-) diff --git a/components/camel-file/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.java b/components/camel-file/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.java index d5e1c4a..81c5e3d 100644 --- a/components/camel-file/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.java +++ b/components/camel-file/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.java @@ -489,14 +489,9 @@ public abstract class GenericFileEndpoint<T> extends ScheduledPollEndpoint imple */ @SuppressWarnings("unchecked") protected GenericFileProcessStrategy<T> createGenericFileStrategy() { - Class<?> factory = null; - try { - FactoryFinder finder = getCamelContext().adapt(ExtendedCamelContext.class).getFactoryFinder("META-INF/services/org/apache/camel/component/"); - LOG.trace("Using FactoryFinder: {}", finder); - factory = finder.findClass(getScheme(), "strategy.factory.", CamelContext.class).orElse(null); - } catch (IOException e) { - LOG.trace("No strategy factory defined in 'META-INF/services/org/apache/camel/component/'", e); - } + FactoryFinder finder = getCamelContext().adapt(ExtendedCamelContext.class).getFactoryFinder("META-INF/services/org/apache/camel/component/"); + LOG.trace("Using FactoryFinder: {}", finder); + Class<?> factory = finder.findClass(getScheme(), "strategy.factory.", CamelContext.class).orElse(null); if (factory == null) { // use default diff --git a/core/camel-api/src/main/java/org/apache/camel/ExtendedCamelContext.java b/core/camel-api/src/main/java/org/apache/camel/ExtendedCamelContext.java index 60c5458..3e7dad2 100644 --- a/core/camel-api/src/main/java/org/apache/camel/ExtendedCamelContext.java +++ b/core/camel-api/src/main/java/org/apache/camel/ExtendedCamelContext.java @@ -312,9 +312,8 @@ public interface ExtendedCamelContext extends CamelContext { * * @param path the META-INF path * @return the factory finder - * @throws NoFactoryAvailableException is thrown if a factory could not be found */ - FactoryFinder getFactoryFinder(String path) throws NoFactoryAvailableException; + FactoryFinder getFactoryFinder(String path); /** * Sets the factory finder resolver to use. diff --git a/core/camel-api/src/main/java/org/apache/camel/spi/FactoryFinder.java b/core/camel-api/src/main/java/org/apache/camel/spi/FactoryFinder.java index ddd9948..6e5e584 100644 --- a/core/camel-api/src/main/java/org/apache/camel/spi/FactoryFinder.java +++ b/core/camel-api/src/main/java/org/apache/camel/spi/FactoryFinder.java @@ -23,6 +23,8 @@ import java.util.Optional; */ public interface FactoryFinder { + String DEFAULT_PATH = "META-INF/services/org/apache/camel/"; + /** * Gets the resource classpath. * diff --git a/core/camel-api/src/main/java/org/apache/camel/spi/FactoryFinderResolver.java b/core/camel-api/src/main/java/org/apache/camel/spi/FactoryFinderResolver.java index 6136127..e487d06 100644 --- a/core/camel-api/src/main/java/org/apache/camel/spi/FactoryFinderResolver.java +++ b/core/camel-api/src/main/java/org/apache/camel/spi/FactoryFinderResolver.java @@ -27,7 +27,9 @@ public interface FactoryFinderResolver { * @param classResolver the class resolver to use * @return a factory finder. */ - FactoryFinder resolveDefaultFactoryFinder(ClassResolver classResolver); + default FactoryFinder resolveDefaultFactoryFinder(ClassResolver classResolver) { + return resolveFactoryFinder(classResolver, FactoryFinder.DEFAULT_PATH); + } /** * Creates a new factory finder. diff --git a/core/camel-base/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java b/core/camel-base/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java index a3c50db..78feca3 100644 --- a/core/camel-base/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java +++ b/core/camel-base/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java @@ -30,7 +30,6 @@ import java.util.stream.Collectors; import org.apache.camel.CamelContext; import org.apache.camel.CamelContextAware; import org.apache.camel.ExtendedCamelContext; -import org.apache.camel.NoFactoryAvailableException; import org.apache.camel.StaticService; import org.apache.camel.api.management.ManagedAttribute; import org.apache.camel.api.management.ManagedResource; @@ -548,8 +547,6 @@ public class PropertiesComponent extends ServiceSupport implements org.apache.ca LOG.warn("PropertiesComponent cannot add custom PropertiesSource as the type is not a org.apache.camel.component.properties.PropertiesSource but: " + type.getName()); } } - } catch (NoFactoryAvailableException e) { - // ignore } catch (Exception e) { LOG.debug("Error discovering and using custom PropertiesSource due to " + e.getMessage() + ". This exception is ignored", e); } diff --git a/core/camel-base/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java b/core/camel-base/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java index 1094d8f..160b839 100644 --- a/core/camel-base/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java +++ b/core/camel-base/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java @@ -58,7 +58,6 @@ import org.apache.camel.FluentProducerTemplate; import org.apache.camel.GlobalEndpointConfiguration; import org.apache.camel.IsSingleton; import org.apache.camel.MultipleConsumersSupport; -import org.apache.camel.NoFactoryAvailableException; import org.apache.camel.NoSuchEndpointException; import org.apache.camel.Processor; import org.apache.camel.ProducerTemplate; @@ -264,7 +263,6 @@ public abstract class AbstractCamelContext extends ServiceSupport implements Ext private volatile ProcessorFactory processorFactory; private volatile MessageHistoryFactory messageHistoryFactory; private volatile FactoryFinderResolver factoryFinderResolver; - private volatile FactoryFinder defaultFactoryFinder; private volatile StreamCachingStrategy streamCachingStrategy; private volatile InflightRepository inflightRepository; private volatile AsyncProcessorAwaitManager asyncProcessorAwaitManager; @@ -2727,12 +2725,6 @@ public abstract class AbstractCamelContext extends ServiceSupport implements Ext forceLazyInitialization(); - // if camel-bean is on classpath then we can load its bean proxy factory - BeanProxyFactory beanProxyFactory = new BeanProxyFactoryResolver().resolve(this); - if (beanProxyFactory != null) { - addService(beanProxyFactory); - } - // re-create endpoint registry as the cache size limit may be set after the constructor of this instance was called. // and we needed to create endpoints up-front as it may be accessed before this context is started endpoints = doAddService(createEndpointRegistry(endpoints)); @@ -3528,7 +3520,11 @@ public abstract class AbstractCamelContext extends ServiceSupport implements Ext getAsyncProcessorAwaitManager(); getShutdownStrategy(); getPackageScanClassResolver(); - getRestRegistryFactory(); + try { + getRestRegistryFactory(); + } catch (IllegalStateException e) { + // ignore in case camel-rest is not on the classpath + } getReactiveExecutor(); getBeanIntrospection(); getPropertiesComponent(); @@ -3557,8 +3553,12 @@ public abstract class AbstractCamelContext extends ServiceSupport implements Ext getUuidGenerator(); getUnitOfWorkFactory(); getRouteController(); - getBeanProxyFactory(); - getBeanProcessorFactory(); + try { + addService(getBeanProxyFactory()); + getBeanProcessorFactory(); + } catch (Exception e) { + // ignore in case camel-bean is not on the classpath + } getBeanPostProcessor(); } @@ -3628,14 +3628,7 @@ public abstract class AbstractCamelContext extends ServiceSupport implements Ext @Override public FactoryFinder getDefaultFactoryFinder() { - if (defaultFactoryFinder == null) { - synchronized (lock) { - if (defaultFactoryFinder == null) { - defaultFactoryFinder = getFactoryFinderResolver().resolveDefaultFactoryFinder(getClassResolver()); - } - } - } - return defaultFactoryFinder; + return getFactoryFinder(FactoryFinder.DEFAULT_PATH); } @Override @@ -3656,7 +3649,7 @@ public abstract class AbstractCamelContext extends ServiceSupport implements Ext } @Override - public FactoryFinder getFactoryFinder(String path) throws NoFactoryAvailableException { + public FactoryFinder getFactoryFinder(String path) { return factories.computeIfAbsent(path, this::createFactoryFinder); } @@ -4207,9 +4200,6 @@ public abstract class AbstractCamelContext extends ServiceSupport implements Ext protected RestRegistry createRestRegistry() { RestRegistryFactory factory = getRestRegistryFactory(); - if (factory == null) { - throw new IllegalStateException("No RestRegistryFactory implementation found. You need to add camel-rest to the classpath."); - } return factory.createRegistry(); } diff --git a/core/camel-base/src/main/java/org/apache/camel/impl/engine/BaseServiceResolver.java b/core/camel-base/src/main/java/org/apache/camel/impl/engine/BaseServiceResolver.java new file mode 100644 index 0000000..810b99a --- /dev/null +++ b/core/camel-base/src/main/java/org/apache/camel/impl/engine/BaseServiceResolver.java @@ -0,0 +1,64 @@ +/* + * 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.impl.engine; + +import java.util.Optional; + +import org.apache.camel.CamelContext; +import org.apache.camel.ExtendedCamelContext; +import org.apache.camel.spi.FactoryFinder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class BaseServiceResolver<T> { + + protected final Logger LOG = LoggerFactory.getLogger(getClass()); + + protected final String factoryKey; + protected final Class<T> factoryClass; + + public BaseServiceResolver(String factoryKey, Class<T> factoryClass) { + this.factoryKey = factoryKey; + this.factoryClass = factoryClass; + } + + public Optional<T> resolve(CamelContext context) { + // use factory finder to find a custom implementations + Class<?> type = null; + try { + FactoryFinder finder = context.adapt(ExtendedCamelContext.class).getFactoryFinder(FactoryFinder.DEFAULT_PATH); + type = finder.findClass(factoryKey).orElse(null); + } catch (Exception e) { + // ignore + } + + if (type != null) { + if (LOG.isDebugEnabled()) { + LOG.debug("Found {}: {} via: {}{}", factoryClass.getSimpleName(), type.getName(), FactoryFinder.DEFAULT_PATH, factoryKey); + } + if (factoryClass.isAssignableFrom(type)) { + T answer = factoryClass.cast(context.getInjector().newInstance(type, false)); + LOG.debug("Detected and using {}: {}", factoryClass.getSimpleName(), answer); + return Optional.of(answer); + } else { + throw new IllegalArgumentException("Type is not a " + factoryClass.getSimpleName() + " implementation. Found: " + type.getName()); + } + } + return Optional.empty(); + } + +} diff --git a/core/camel-base/src/main/java/org/apache/camel/impl/engine/BeanProcessorFactoryResolver.java b/core/camel-base/src/main/java/org/apache/camel/impl/engine/BeanProcessorFactoryResolver.java deleted file mode 100644 index df2945d..0000000 --- a/core/camel-base/src/main/java/org/apache/camel/impl/engine/BeanProcessorFactoryResolver.java +++ /dev/null @@ -1,72 +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.impl.engine; - -import java.io.IOException; - -import org.apache.camel.CamelContext; -import org.apache.camel.ExtendedCamelContext; -import org.apache.camel.spi.BeanProcessorFactory; -import org.apache.camel.spi.FactoryFinder; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Factory resolver to find the {@link org.apache.camel.spi.BeanProcessorFactory} from the classpath in camel-bean. - */ -public class BeanProcessorFactoryResolver { - - public static final String RESOURCE_PATH = "META-INF/services/org/apache/camel/"; - - private static final Logger LOG = LoggerFactory.getLogger(BeanProcessorFactoryResolver.class); - - private FactoryFinder factoryFinder; - - public BeanProcessorFactory resolve(CamelContext context) { - // use factory finder to find a custom implementations - Class<?> type = null; - try { - type = findFactory(BeanProcessorFactory.FACTORY, context); - } catch (Exception e) { - // ignore - } - - if (type != null) { - if (LOG.isDebugEnabled()) { - LOG.debug("Found BeanProxyFactory: {} via: {}{}", type.getName(), factoryFinder.getResourcePath(), "bean-processor-factory"); - } - if (BeanProcessorFactory.class.isAssignableFrom(type)) { - BeanProcessorFactory answer = (BeanProcessorFactory) context.getInjector().newInstance(type, false); - LOG.debug("Detected and using BeanProcessorFactory: {}", answer); - return answer; - } else { - throw new IllegalArgumentException("Type is not a BeanProcessorFactory implementation. Found: " + type.getName()); - } - } - - LOG.debug("Cannot find BeanProcessorFactory. Make sure camel-bean is on the classpath."); - return null; - } - - private Class<?> findFactory(String name, CamelContext context) throws IOException { - if (factoryFinder == null) { - factoryFinder = context.adapt(ExtendedCamelContext.class).getFactoryFinder(RESOURCE_PATH); - } - return factoryFinder.findClass(name).orElse(null); - } - -} diff --git a/core/camel-base/src/main/java/org/apache/camel/impl/engine/BeanProxyFactoryResolver.java b/core/camel-base/src/main/java/org/apache/camel/impl/engine/BeanProxyFactoryResolver.java deleted file mode 100644 index 78a9a98..0000000 --- a/core/camel-base/src/main/java/org/apache/camel/impl/engine/BeanProxyFactoryResolver.java +++ /dev/null @@ -1,72 +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.impl.engine; - -import java.io.IOException; - -import org.apache.camel.CamelContext; -import org.apache.camel.ExtendedCamelContext; -import org.apache.camel.spi.BeanProxyFactory; -import org.apache.camel.spi.FactoryFinder; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Factory resolver to find the {@link BeanProxyFactory} from the classpath in camel-bean. - */ -public class BeanProxyFactoryResolver { - - public static final String RESOURCE_PATH = "META-INF/services/org/apache/camel/"; - - private static final Logger LOG = LoggerFactory.getLogger(BeanProxyFactoryResolver.class); - - private FactoryFinder factoryFinder; - - public BeanProxyFactory resolve(CamelContext context) { - // use factory finder to find a custom implementations - Class<?> type = null; - try { - type = findFactory(BeanProxyFactory.FACTORY, context); - } catch (Exception e) { - // ignore - } - - if (type != null) { - if (LOG.isDebugEnabled()) { - LOG.debug("Found BeanProxyFactory: {} via: {}{}", type.getName(), factoryFinder.getResourcePath(), "bean-proxy-factory"); - } - if (BeanProxyFactory.class.isAssignableFrom(type)) { - BeanProxyFactory answer = (BeanProxyFactory) context.getInjector().newInstance(type, false); - LOG.debug("Detected and using BeanProxyFactory: {}", answer); - return answer; - } else { - throw new IllegalArgumentException("Type is not a BeanProxyFactory implementation. Found: " + type.getName()); - } - } - - LOG.debug("Cannot find BeanProxyFactory. Make sure camel-bean is on the classpath."); - return null; - } - - private Class<?> findFactory(String name, CamelContext context) throws IOException { - if (factoryFinder == null) { - factoryFinder = context.adapt(ExtendedCamelContext.class).getFactoryFinder(RESOURCE_PATH); - } - return factoryFinder.findClass(name).orElse(null); - } - -} diff --git a/core/camel-base/src/main/java/org/apache/camel/impl/engine/CamelPostProcessorHelper.java b/core/camel-base/src/main/java/org/apache/camel/impl/engine/CamelPostProcessorHelper.java index 7bf8641..da743bc 100644 --- a/core/camel-base/src/main/java/org/apache/camel/impl/engine/CamelPostProcessorHelper.java +++ b/core/camel-base/src/main/java/org/apache/camel/impl/engine/CamelPostProcessorHelper.java @@ -238,9 +238,6 @@ public class CamelPostProcessorHelper implements CamelContextAware { try { // use proxy service BeanProxyFactory factory = endpoint.getCamelContext().adapt(ExtendedCamelContext.class).getBeanProxyFactory(); - if (factory == null) { - throw new IllegalArgumentException("Cannot find BeanProxyFactory. Make sure camel-bean is on the classpath."); - } return factory.createProxy(endpoint, binding, type); } catch (Exception e) { throw createProxyInstantiationRuntimeException(type, endpoint, e); diff --git a/core/camel-base/src/main/java/org/apache/camel/impl/engine/DefaultFactoryFinderResolver.java b/core/camel-base/src/main/java/org/apache/camel/impl/engine/DefaultFactoryFinderResolver.java index 7fc2fb5..027dead 100644 --- a/core/camel-base/src/main/java/org/apache/camel/impl/engine/DefaultFactoryFinderResolver.java +++ b/core/camel-base/src/main/java/org/apache/camel/impl/engine/DefaultFactoryFinderResolver.java @@ -26,11 +26,6 @@ import org.apache.camel.spi.FactoryFinderResolver; public class DefaultFactoryFinderResolver implements FactoryFinderResolver { @Override - public FactoryFinder resolveDefaultFactoryFinder(ClassResolver classResolver) { - return resolveFactoryFinder(classResolver, "META-INF/services/org/apache/camel/"); - } - - @Override public FactoryFinder resolveFactoryFinder(ClassResolver classResolver, String resourcePath) { return new DefaultFactoryFinder(classResolver, resourcePath); } diff --git a/core/camel-base/src/main/java/org/apache/camel/impl/engine/HeadersMapFactoryResolver.java b/core/camel-base/src/main/java/org/apache/camel/impl/engine/HeadersMapFactoryResolver.java deleted file mode 100644 index a2059bb..0000000 --- a/core/camel-base/src/main/java/org/apache/camel/impl/engine/HeadersMapFactoryResolver.java +++ /dev/null @@ -1,76 +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.impl.engine; - -import java.io.IOException; - -import org.apache.camel.CamelContext; -import org.apache.camel.ExtendedCamelContext; -import org.apache.camel.spi.FactoryFinder; -import org.apache.camel.spi.HeadersMapFactory; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Factory to create the {@link HeadersMapFactory} implementation to be used. - * - * @see HeadersMapFactory - */ -public class HeadersMapFactoryResolver { - - public static final String RESOURCE_PATH = "META-INF/services/org/apache/camel/"; - - private static final Logger LOG = LoggerFactory.getLogger(HeadersMapFactoryResolver.class); - - private FactoryFinder factoryFinder; - - public HeadersMapFactory resolve(CamelContext context) { - // use factory finder to find a custom implementations - Class<?> type = null; - try { - type = findFactory(HeadersMapFactory.FACTORY, context); - } catch (Exception e) { - // ignore - } - - if (type != null) { - if (LOG.isDebugEnabled()) { - LOG.debug("Found HeadersMapFactory: {} via: {}{}", type.getName(), factoryFinder.getResourcePath(), "headers-map-factory"); - } - if (HeadersMapFactory.class.isAssignableFrom(type)) { - HeadersMapFactory answer = (HeadersMapFactory) context.getInjector().newInstance(type, false); - LOG.info("Detected and using HeadersMapFactory: {}", answer); - return answer; - } else { - throw new IllegalArgumentException("Type is not a HeadersMapFactory implementation. Found: " + type.getName()); - } - } - - // fallback to default - LOG.debug("Creating default HeadersMapFactory"); - return new DefaultHeadersMapFactory(); - } - - private Class<?> findFactory(String name, CamelContext context) throws IOException { - if (factoryFinder == null) { - factoryFinder = context.adapt(ExtendedCamelContext.class).getFactoryFinder(RESOURCE_PATH); - } - return factoryFinder.findClass(name).orElse(null); - } - -} - diff --git a/core/camel-base/src/main/java/org/apache/camel/impl/engine/PropertiesComponentFactoryResolver.java b/core/camel-base/src/main/java/org/apache/camel/impl/engine/PropertiesComponentFactoryResolver.java deleted file mode 100644 index 1da4e68..0000000 --- a/core/camel-base/src/main/java/org/apache/camel/impl/engine/PropertiesComponentFactoryResolver.java +++ /dev/null @@ -1,72 +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.impl.engine; - -import java.io.IOException; - -import org.apache.camel.CamelContext; -import org.apache.camel.ExtendedCamelContext; -import org.apache.camel.spi.FactoryFinder; -import org.apache.camel.spi.PropertiesComponent; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Factory resolver to find the {@link org.apache.camel.spi.PropertiesComponent} from the classpath. - */ -public class PropertiesComponentFactoryResolver { - - public static final String RESOURCE_PATH = "META-INF/services/org/apache/camel/"; - - private static final Logger LOG = LoggerFactory.getLogger(PropertiesComponentFactoryResolver.class); - - private FactoryFinder factoryFinder; - - public PropertiesComponent resolve(CamelContext context) { - // use factory finder to find a custom implementations - Class<?> type = null; - try { - type = findFactory(PropertiesComponent.FACTORY, context); - } catch (Exception e) { - // ignore - } - - if (type != null) { - if (LOG.isDebugEnabled()) { - LOG.debug("Found PropertiesComponent: {} via: {}{}", type.getName(), factoryFinder.getResourcePath(), "properties-component-factory"); - } - if (PropertiesComponent.class.isAssignableFrom(type)) { - PropertiesComponent answer = (PropertiesComponent) context.getInjector().newInstance(type, false); - LOG.debug("Detected and using PropertiesComponent: {}", answer); - return answer; - } else { - throw new IllegalArgumentException("Type is not a PropertiesComponent implementation. Found: " + type.getName()); - } - } - - // use default component - return new org.apache.camel.component.properties.PropertiesComponent(); - } - - private Class<?> findFactory(String name, CamelContext context) throws IOException { - if (factoryFinder == null) { - factoryFinder = context.adapt(ExtendedCamelContext.class).getFactoryFinder(RESOURCE_PATH); - } - return factoryFinder.findClass(name).orElse(null); - } - -} diff --git a/core/camel-base/src/main/java/org/apache/camel/impl/engine/ReactiveExecutorResolver.java b/core/camel-base/src/main/java/org/apache/camel/impl/engine/ReactiveExecutorResolver.java deleted file mode 100644 index 563c803..0000000 --- a/core/camel-base/src/main/java/org/apache/camel/impl/engine/ReactiveExecutorResolver.java +++ /dev/null @@ -1,73 +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.impl.engine; - -import java.io.IOException; - -import org.apache.camel.CamelContext; -import org.apache.camel.ExtendedCamelContext; -import org.apache.camel.spi.FactoryFinder; -import org.apache.camel.spi.ReactiveExecutor; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Factory resolver to create the {@link org.apache.camel.spi.ReactiveExecutor} to be used. - */ -public class ReactiveExecutorResolver { - - public static final String RESOURCE_PATH = "META-INF/services/org/apache/camel/"; - - private static final Logger LOG = LoggerFactory.getLogger(ReactiveExecutorResolver.class); - - private FactoryFinder factoryFinder; - - public ReactiveExecutor resolve(CamelContext context) { - // use factory finder to find a custom implementations - Class<?> type = null; - try { - type = findFactory(ReactiveExecutor.FACTORY, context); - } catch (Exception e) { - // ignore - } - - if (type != null) { - if (LOG.isDebugEnabled()) { - LOG.debug("Found ReactiveExecutor: {} via: {}{}", type.getName(), factoryFinder.getResourcePath(), "reactive-executor"); - } - if (ReactiveExecutor.class.isAssignableFrom(type)) { - ReactiveExecutor answer = (ReactiveExecutor) context.getInjector().newInstance(type, false); - LOG.info("Detected and using ReactiveExecutor: {}", answer); - return answer; - } else { - throw new IllegalArgumentException("Type is not a ReactiveExecutor implementation. Found: " + type.getName()); - } - } - - // fallback to default - LOG.debug("Creating default ReactiveExecutor"); - return new DefaultReactiveExecutor(); - } - - private Class<?> findFactory(String name, CamelContext context) throws IOException { - if (factoryFinder == null) { - factoryFinder = context.adapt(ExtendedCamelContext.class).getFactoryFinder(RESOURCE_PATH); - } - return factoryFinder.findClass(name).orElse(null); - } - -} diff --git a/core/camel-base/src/main/java/org/apache/camel/impl/engine/RestRegistryFactoryResolver.java b/core/camel-base/src/main/java/org/apache/camel/impl/engine/RestRegistryFactoryResolver.java deleted file mode 100644 index 2726bca..0000000 --- a/core/camel-base/src/main/java/org/apache/camel/impl/engine/RestRegistryFactoryResolver.java +++ /dev/null @@ -1,75 +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.impl.engine; - -import java.io.IOException; - -import org.apache.camel.CamelContext; -import org.apache.camel.ExtendedCamelContext; -import org.apache.camel.spi.FactoryFinder; -import org.apache.camel.spi.RestRegistryFactory; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Factory to create the {@link RestRegistryFactory} implementation to be used. - * - * @see RestRegistryFactory - */ -public class RestRegistryFactoryResolver { - - public static final String RESOURCE_PATH = "META-INF/services/org/apache/camel/"; - - private static final Logger LOG = LoggerFactory.getLogger(RestRegistryFactoryResolver.class); - - private FactoryFinder factoryFinder; - - public RestRegistryFactory resolve(CamelContext context) { - // use factory finder to find a custom implementations - Class<?> type = null; - try { - type = findFactory(RestRegistryFactory.FACTORY, context); - } catch (Exception e) { - // ignore - } - - if (type != null) { - if (LOG.isDebugEnabled()) { - LOG.debug("Found RestRegistryFactory: {} via: {}{}", type.getName(), factoryFinder.getResourcePath(), "rest-registry-factory"); - } - if (RestRegistryFactory.class.isAssignableFrom(type)) { - RestRegistryFactory answer = (RestRegistryFactory) context.getInjector().newInstance(type, false); - LOG.debug("Detected and using RestRegistryFactory: {}", answer); - return answer; - } else { - throw new IllegalArgumentException("Type is not a RestRegistryFactory implementation. Found: " + type.getName()); - } - } - - LOG.debug("Cannot find RestRegistryFactory. Make sure camel-rest is on the classpath."); - return null; - } - - private Class<?> findFactory(String name, CamelContext context) throws IOException { - if (factoryFinder == null) { - factoryFinder = context.adapt(ExtendedCamelContext.class).getFactoryFinder(RESOURCE_PATH); - } - return factoryFinder.findClass(name).orElse(null); - } - -} - diff --git a/core/camel-base/src/main/java/org/apache/camel/impl/engine/RuntimeCamelCatalogResolver.java b/core/camel-base/src/main/java/org/apache/camel/impl/engine/RuntimeCamelCatalogResolver.java deleted file mode 100644 index 8c97cf0..0000000 --- a/core/camel-base/src/main/java/org/apache/camel/impl/engine/RuntimeCamelCatalogResolver.java +++ /dev/null @@ -1,76 +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.impl.engine; - -import java.io.IOException; - -import org.apache.camel.CamelContext; -import org.apache.camel.ExtendedCamelContext; -import org.apache.camel.catalog.RuntimeCamelCatalog; -import org.apache.camel.spi.FactoryFinder; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Factory to create the {@link org.apache.camel.catalog.RuntimeCamelCatalog} implementation to be used. - * - * @see RuntimeCamelCatalog - */ -public class RuntimeCamelCatalogResolver { - - public static final String RESOURCE_PATH = "META-INF/services/org/apache/camel/"; - - private static final Logger LOG = LoggerFactory.getLogger(RuntimeCamelCatalogResolver.class); - - private FactoryFinder factoryFinder; - - public RuntimeCamelCatalog resolve(CamelContext context) { - // use factory finder to find a custom implementations - Class<?> type = null; - try { - type = findFactory(RuntimeCamelCatalog.FACTORY, context); - } catch (Exception e) { - // ignore - } - - if (type != null) { - if (LOG.isDebugEnabled()) { - LOG.debug("Found RuntimeCamelCatalog: {} via: {}{}", type.getName(), factoryFinder.getResourcePath(), "runtime-camelcatalog"); - } - if (RuntimeCamelCatalog.class.isAssignableFrom(type)) { - RuntimeCamelCatalog answer = (RuntimeCamelCatalog) context.getInjector().newInstance(type, false); - answer.setCamelContext(context); - LOG.info("Detected and using RuntimeCamelCatalog: {}", answer); - return answer; - } else { - throw new IllegalArgumentException("Type is not a RuntimeCamelCatalog implementation. Found: " + type.getName()); - } - } - - // fallback to default - throw new IllegalArgumentException("Cannot find RuntimeCamelCatalog on classpath. Add camel-core-catalog to classpath."); - } - - private Class<?> findFactory(String name, CamelContext context) throws IOException { - if (factoryFinder == null) { - factoryFinder = context.adapt(ExtendedCamelContext.class).getFactoryFinder(RESOURCE_PATH); - } - return factoryFinder.findClass(name).orElse(null); - } - -} - diff --git a/core/camel-core-engine/src/main/java/org/apache/camel/builder/ProxyBuilder.java b/core/camel-core-engine/src/main/java/org/apache/camel/builder/ProxyBuilder.java index 23178c6..6676fc3 100644 --- a/core/camel-core-engine/src/main/java/org/apache/camel/builder/ProxyBuilder.java +++ b/core/camel-core-engine/src/main/java/org/apache/camel/builder/ProxyBuilder.java @@ -83,9 +83,6 @@ public final class ProxyBuilder { ObjectHelper.notNull(endpoint, "endpoint"); // use proxy service BeanProxyFactory factory = camelContext.adapt(ExtendedCamelContext.class).getBeanProxyFactory(); - if (factory == null) { - throw new IllegalArgumentException("Cannot find BeanProxyFactory. Make sure camel-bean is on the classpath."); - } return factory.createProxy(endpoint, binding, interfaceClasses); } diff --git a/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultCamelContext.java b/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultCamelContext.java index cf731f8..ede62b8 100644 --- a/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultCamelContext.java +++ b/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultCamelContext.java @@ -26,8 +26,6 @@ import org.apache.camel.TypeConverter; import org.apache.camel.catalog.RuntimeCamelCatalog; import org.apache.camel.health.HealthCheckRegistry; import org.apache.camel.impl.converter.DefaultTypeConverter; -import org.apache.camel.impl.engine.BeanProcessorFactoryResolver; -import org.apache.camel.impl.engine.BeanProxyFactoryResolver; import org.apache.camel.impl.engine.DefaultAsyncProcessorAwaitManager; import org.apache.camel.impl.engine.DefaultBeanIntrospection; import org.apache.camel.impl.engine.DefaultCamelBeanPostProcessor; @@ -38,6 +36,7 @@ import org.apache.camel.impl.engine.DefaultConfigurerResolver; import org.apache.camel.impl.engine.DefaultDataFormatResolver; import org.apache.camel.impl.engine.DefaultEndpointRegistry; import org.apache.camel.impl.engine.DefaultFactoryFinderResolver; +import org.apache.camel.impl.engine.DefaultHeadersMapFactory; import org.apache.camel.impl.engine.DefaultInflightRepository; import org.apache.camel.impl.engine.DefaultInjector; import org.apache.camel.impl.engine.DefaultLanguageResolver; @@ -47,6 +46,7 @@ import org.apache.camel.impl.engine.DefaultNodeIdFactory; import org.apache.camel.impl.engine.DefaultPackageScanClassResolver; import org.apache.camel.impl.engine.DefaultPackageScanResourceResolver; import org.apache.camel.impl.engine.DefaultProcessorFactory; +import org.apache.camel.impl.engine.DefaultReactiveExecutor; import org.apache.camel.impl.engine.DefaultRouteController; import org.apache.camel.impl.engine.DefaultShutdownStrategy; import org.apache.camel.impl.engine.DefaultStreamCachingStrategy; @@ -54,12 +54,8 @@ import org.apache.camel.impl.engine.DefaultTracer; import org.apache.camel.impl.engine.DefaultUnitOfWorkFactory; import org.apache.camel.impl.engine.DefaultUuidGenerator; import org.apache.camel.impl.engine.EndpointKey; -import org.apache.camel.impl.engine.HeadersMapFactoryResolver; -import org.apache.camel.impl.engine.PropertiesComponentFactoryResolver; -import org.apache.camel.impl.engine.ReactiveExecutorResolver; -import org.apache.camel.impl.engine.RestRegistryFactoryResolver; -import org.apache.camel.impl.engine.RuntimeCamelCatalogResolver; import org.apache.camel.impl.engine.WebSpherePackageScanClassResolver; +import org.apache.camel.impl.engine.BaseServiceResolver; import org.apache.camel.impl.health.DefaultHealthCheckRegistry; import org.apache.camel.spi.AsyncProcessorAwaitManager; import org.apache.camel.spi.BeanIntrospection; @@ -170,7 +166,8 @@ public class DefaultCamelContext extends AbstractModelCamelContext { @Override protected TypeConverter createTypeConverter() { - return new DefaultTypeConverter(this, getPackageScanClassResolver(), getInjector(), getDefaultFactoryFinder(), isLoadTypeConverters()); + return new DefaultTypeConverter(this, getPackageScanClassResolver(), getInjector(), + getDefaultFactoryFinder(), isLoadTypeConverters()); } @Override @@ -194,7 +191,9 @@ public class DefaultCamelContext extends AbstractModelCamelContext { @Override protected PropertiesComponent createPropertiesComponent() { - return new PropertiesComponentFactoryResolver().resolve(this); + return new BaseServiceResolver<>(PropertiesComponent.FACTORY, PropertiesComponent.class) + .resolve(this) + .orElseGet(org.apache.camel.component.properties.PropertiesComponent::new); } @Override @@ -307,7 +306,10 @@ public class DefaultCamelContext extends AbstractModelCamelContext { @Override protected RuntimeCamelCatalog createRuntimeCamelCatalog() { - return new RuntimeCamelCatalogResolver().resolve(this); + return new BaseServiceResolver<>(RuntimeCamelCatalog.FACTORY, RuntimeCamelCatalog.class) + .resolve(this) + .orElseThrow(() -> new IllegalArgumentException("Cannot find RuntimeCamelCatalog on classpath. " + + "Add camel-core-catalog to classpath.")); } @Override @@ -322,17 +324,25 @@ public class DefaultCamelContext extends AbstractModelCamelContext { @Override protected HeadersMapFactory createHeadersMapFactory() { - return new HeadersMapFactoryResolver().resolve(this); + return new BaseServiceResolver<>(HeadersMapFactory.FACTORY, HeadersMapFactory.class) + .resolve(this) + .orElseGet(DefaultHeadersMapFactory::new); } @Override protected BeanProxyFactory createBeanProxyFactory() { - return new BeanProxyFactoryResolver().resolve(this); + return new BaseServiceResolver<>(BeanProxyFactory.FACTORY, BeanProxyFactory.class) + .resolve(this) + .orElseThrow(() -> new IllegalArgumentException("Cannot find BeanProxyFactory on classpath. " + + "Add camel-bean to classpath.")); } @Override protected BeanProcessorFactory createBeanProcessorFactory() { - return new BeanProcessorFactoryResolver().resolve(this); + return new BaseServiceResolver<>(BeanProcessorFactory.FACTORY, BeanProcessorFactory.class) + .resolve(this) + .orElseThrow(() -> new IllegalArgumentException("Cannot find BeanProcessorFactory on classpath. " + + "Add camel-bean to classpath.")); } @Override @@ -342,12 +352,18 @@ public class DefaultCamelContext extends AbstractModelCamelContext { @Override protected XMLRoutesDefinitionLoader createXMLRoutesDefinitionLoader() { - return new XMLRoutesDefinitionLoaderResolver().resolve(this); + return new BaseServiceResolver<>(XMLRoutesDefinitionLoader.FACTORY, XMLRoutesDefinitionLoader.class) + .resolve(this) + .orElseThrow(() -> new IllegalArgumentException("Cannot find XMLRoutesDefinitionLoader on classpath. " + + "Add either camel-xml-io or camel-xml-jaxb to classpath.")); } @Override protected ModelToXMLDumper createModelToXMLDumper() { - return new ModelToXMLDumperResolver().resolve(this); + return new BaseServiceResolver<>(ModelToXMLDumper.FACTORY, ModelToXMLDumper.class) + .resolve(this) + .orElseThrow(() -> new IllegalArgumentException("Cannot find ModelToXMLDumper on classpath. " + + "Add camel-xml-jaxb to classpath.")); } @Override @@ -382,7 +398,10 @@ public class DefaultCamelContext extends AbstractModelCamelContext { @Override protected RestRegistryFactory createRestRegistryFactory() { - return new RestRegistryFactoryResolver().resolve(this); + return new BaseServiceResolver<>(RestRegistryFactory.FACTORY, RestRegistryFactory.class) + .resolve(this) + .orElseThrow(() -> new IllegalArgumentException("Cannot find RestRegistryFactory on classpath. " + + "Add camel-rest to classpath.")); } @Override @@ -397,7 +416,9 @@ public class DefaultCamelContext extends AbstractModelCamelContext { @Override protected ReactiveExecutor createReactiveExecutor() { - return new ReactiveExecutorResolver().resolve(this); + return new BaseServiceResolver<>(ReactiveExecutor.FACTORY, ReactiveExecutor.class) + .resolve(this) + .orElseGet(DefaultReactiveExecutor::new); } } diff --git a/core/camel-core-engine/src/main/java/org/apache/camel/impl/ModelToXMLDumperResolver.java b/core/camel-core-engine/src/main/java/org/apache/camel/impl/ModelToXMLDumperResolver.java deleted file mode 100644 index 57ac62f..0000000 --- a/core/camel-core-engine/src/main/java/org/apache/camel/impl/ModelToXMLDumperResolver.java +++ /dev/null @@ -1,75 +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.impl; - -import java.io.IOException; - -import org.apache.camel.CamelContext; -import org.apache.camel.ExtendedCamelContext; -import org.apache.camel.RuntimeCamelException; -import org.apache.camel.spi.FactoryFinder; -import org.apache.camel.spi.ModelToXMLDumper; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Factory to create the {@link ModelToXMLDumper} implementation to be used. - * - * @see ModelToXMLDumper - */ -public class ModelToXMLDumperResolver { - - public static final String RESOURCE_PATH = "META-INF/services/org/apache/camel/"; - - private static final Logger LOG = LoggerFactory.getLogger(ModelToXMLDumperResolver.class); - - private FactoryFinder factoryFinder; - - public ModelToXMLDumper resolve(CamelContext context) { - // use factory finder to find a custom implementations - Class<?> type = null; - try { - type = findFactory(ModelToXMLDumper.FACTORY, context); - } catch (Exception e) { - // ignore - } - - if (type != null) { - if (LOG.isDebugEnabled()) { - LOG.debug("Found ModelToXMLDumper: {} via: {}{}", type.getName(), factoryFinder.getResourcePath(), "modelxml-dumper"); - } - if (ModelToXMLDumper.class.isAssignableFrom(type)) { - ModelToXMLDumper answer = (ModelToXMLDumper) context.getInjector().newInstance(type, false); - LOG.info("Detected and using ModelToXMLDumper: {}", answer); - return answer; - } else { - throw new IllegalArgumentException("Type is not a ModelToXMLDumper implementation. Found: " + type.getName()); - } - } - - throw new RuntimeCamelException("Cannot find XML routes dumper in classpath. Add camel-xml-jaxb to the classpath."); - } - - private Class<?> findFactory(String name, CamelContext context) throws IOException { - if (factoryFinder == null) { - factoryFinder = context.adapt(ExtendedCamelContext.class).getFactoryFinder(RESOURCE_PATH); - } - return factoryFinder.findClass(name).orElse(null); - } - -} - diff --git a/core/camel-core-engine/src/main/java/org/apache/camel/impl/XMLRoutesDefinitionLoaderResolver.java b/core/camel-core-engine/src/main/java/org/apache/camel/impl/XMLRoutesDefinitionLoaderResolver.java deleted file mode 100644 index 000c7cb..0000000 --- a/core/camel-core-engine/src/main/java/org/apache/camel/impl/XMLRoutesDefinitionLoaderResolver.java +++ /dev/null @@ -1,76 +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.impl; - -import java.io.IOException; - -import org.apache.camel.CamelContext; -import org.apache.camel.ExtendedCamelContext; -import org.apache.camel.NoFactoryAvailableException; -import org.apache.camel.RuntimeCamelException; -import org.apache.camel.spi.FactoryFinder; -import org.apache.camel.spi.XMLRoutesDefinitionLoader; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Factory to create the {@link XMLRoutesDefinitionLoader} implementation to be used. - * - * @see XMLRoutesDefinitionLoader - */ -public class XMLRoutesDefinitionLoaderResolver { - - public static final String RESOURCE_PATH = "META-INF/services/org/apache/camel/"; - - private static final Logger LOG = LoggerFactory.getLogger(XMLRoutesDefinitionLoaderResolver.class); - - private FactoryFinder factoryFinder; - - public XMLRoutesDefinitionLoader resolve(CamelContext context) { - // use factory finder to find a custom implementations - Class<?> type = null; - try { - type = findFactory(XMLRoutesDefinitionLoader.FACTORY, context); - } catch (Exception e) { - // ignore - } - - if (type != null) { - if (LOG.isDebugEnabled()) { - LOG.debug("Found XMLRoutesDefinitionLoader: {} via: {}{}", type.getName(), factoryFinder.getResourcePath(), "xmlroutes-loader"); - } - if (XMLRoutesDefinitionLoader.class.isAssignableFrom(type)) { - XMLRoutesDefinitionLoader answer = (XMLRoutesDefinitionLoader) context.getInjector().newInstance(type, false); - LOG.info("Detected and using XMLRoutesDefinitionLoader: {}", answer); - return answer; - } else { - throw new IllegalArgumentException("Type is not a XMLRoutesDefinitionLoader implementation. Found: " + type.getName()); - } - } - - throw new RuntimeCamelException("Cannot find XML routes loader in classpath. Add either camel-xml-io or camel-xml-jaxb to the classpath."); - } - - private Class<?> findFactory(String name, CamelContext context) throws IOException { - if (factoryFinder == null) { - factoryFinder = context.adapt(ExtendedCamelContext.class).getFactoryFinder(RESOURCE_PATH); - } - return factoryFinder.findClass(name).orElse(null); - } - -} - diff --git a/core/camel-core-engine/src/main/java/org/apache/camel/reifier/BeanReifier.java b/core/camel-core-engine/src/main/java/org/apache/camel/reifier/BeanReifier.java index 4fa6126..8e32da5 100644 --- a/core/camel-core-engine/src/main/java/org/apache/camel/reifier/BeanReifier.java +++ b/core/camel-core-engine/src/main/java/org/apache/camel/reifier/BeanReifier.java @@ -39,9 +39,6 @@ public class BeanReifier extends ProcessorReifier<BeanDefinition> { Class<?> beanClass = definition.getBeanClass(); BeanProcessorFactory fac = camelContext.adapt(ExtendedCamelContext.class).getBeanProcessorFactory(); - if (fac == null) { - throw new IllegalStateException("Cannot find BeanProcessorFactory. Make sure camel-bean is on the classpath."); - } // use singleton as default scope BeanScope scope = BeanScope.Singleton; if (definition.getScope() != null) { diff --git a/core/camel-core-engine/src/main/java/org/apache/camel/reifier/dataformat/DataFormatReifier.java b/core/camel-core-engine/src/main/java/org/apache/camel/reifier/dataformat/DataFormatReifier.java index 0707c79..02fb328 100644 --- a/core/camel-core-engine/src/main/java/org/apache/camel/reifier/dataformat/DataFormatReifier.java +++ b/core/camel-core-engine/src/main/java/org/apache/camel/reifier/dataformat/DataFormatReifier.java @@ -23,8 +23,6 @@ import java.util.function.BiFunction; import org.apache.camel.CamelContext; import org.apache.camel.ExtendedCamelContext; -import org.apache.camel.NoFactoryAvailableException; -import org.apache.camel.RuntimeCamelException; import org.apache.camel.model.DataFormatDefinition; import org.apache.camel.model.Model; import org.apache.camel.model.dataformat.ASN1DataFormat; @@ -271,18 +269,14 @@ public abstract class DataFormatReifier<T extends DataFormatDefinition> extends } } if (configurer == null) { - try { - Class<?> clazz = camelContext.adapt(ExtendedCamelContext.class).getFactoryFinder(RESOURCE_PATH) - .findOptionalClass(name + "-dataformat-configurer", null) - .orElse(null); - if (clazz != null) { - configurer = org.apache.camel.support.ObjectHelper.newInstance(clazz, PropertyConfigurer.class); - if (LOG.isDebugEnabled() && configurer != null) { - LOG.debug("Discovered dataformat property configurer using the FactoryFinder: {} -> {}", name, configurer); - } + Class<?> clazz = camelContext.adapt(ExtendedCamelContext.class).getFactoryFinder(RESOURCE_PATH) + .findOptionalClass(name + "-dataformat-configurer", null) + .orElse(null); + if (clazz != null) { + configurer = org.apache.camel.support.ObjectHelper.newInstance(clazz, PropertyConfigurer.class); + if (LOG.isDebugEnabled() && configurer != null) { + LOG.debug("Discovered dataformat property configurer using the FactoryFinder: {} -> {}", name, configurer); } - } catch (NoFactoryAvailableException e) { - throw new RuntimeCamelException("Unable to retrieve dataformat property configurer factory finder", e); } } return configurer; diff --git a/core/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiFactoryFinderResolver.java b/core/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiFactoryFinderResolver.java index 8bed373..631c190 100644 --- a/core/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiFactoryFinderResolver.java +++ b/core/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiFactoryFinderResolver.java @@ -30,11 +30,6 @@ public class OsgiFactoryFinderResolver implements FactoryFinderResolver { } @Override - public FactoryFinder resolveDefaultFactoryFinder(ClassResolver classResolver) { - return resolveFactoryFinder(classResolver, "META-INF/services/org/apache/camel/"); - } - - @Override public FactoryFinder resolveFactoryFinder(ClassResolver classResolver, String resourcePath) { return new OsgiFactoryFinder(bundleContext, classResolver, resourcePath); }
