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.git
commit b68b1fff46684352192fb69a86cea4d2965fe31e Author: Claus Ibsen <[email protected]> AuthorDate: Mon Oct 17 11:40:23 2022 +0200 camel-rest - Fix NPE with better exception if component not on classpath --- .../apache/camel/support/RestProducerFactoryHelper.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/core/camel-support/src/main/java/org/apache/camel/support/RestProducerFactoryHelper.java b/core/camel-support/src/main/java/org/apache/camel/support/RestProducerFactoryHelper.java index 2910e835a5c..d8cc9cf4015 100644 --- a/core/camel-support/src/main/java/org/apache/camel/support/RestProducerFactoryHelper.java +++ b/core/camel-support/src/main/java/org/apache/camel/support/RestProducerFactoryHelper.java @@ -42,21 +42,19 @@ public final class RestProducerFactoryHelper { public static void setupComponentFor( final String url, final CamelContext camelContext, - final Map<String, Object> componentProperties) - throws Exception { - final String scheme = StringHelper.before(url, ":"); + final Map<String, Object> componentProperties) { + final String scheme = StringHelper.before(url, ":"); setupComponent(scheme, camelContext, componentProperties); } public static Component setupComponent( final String componentName, final CamelContext camelContext, - final Map<String, Object> componentProperties) - throws Exception { + final Map<String, Object> componentProperties) { + if (componentName == null) { return null; } - if (componentProperties == null || componentProperties.isEmpty()) { return camelContext.getComponent(componentName); } @@ -76,6 +74,11 @@ public final class RestProducerFactoryHelper { // component was not added to the context we can configure it final Component newlyCreated = camelContext.getComponent(componentName, true, false); + if (newlyCreated == null) { + throw new IllegalArgumentException( + "Cannot find component with name " + componentName + + ". Make sure you have the component on the classpath"); + } PropertyBindingSupport.build().withRemoveParameters(false).withIgnoreCase(true) .withConfigurer(newlyCreated.getComponentPropertyConfigurer()) .bind(camelContext, newlyCreated, componentProperties);
