Author: dkulp
Date: Wed Jul 13 14:59:49 2011
New Revision: 1146086
URL: http://svn.apache.org/viewvc?rev=1146086&view=rev
Log:
Merged revisions 1146057 via svnmerge from
https://svn.apache.org/repos/asf/camel/trunk
........
r1146057 | davsclaus | 2011-07-13 10:31:26 -0400 (Wed, 13 Jul 2011) | 1 line
CAMEL-4222: Ref component throws better error message if endpoint could not
be found in registry.
........
Added:
camel/branches/camel-2.7.x/camel-core/src/test/java/org/apache/camel/component/ref/RefInvalidTest.java
- copied unchanged from r1146057,
camel/trunk/camel-core/src/test/java/org/apache/camel/component/ref/RefInvalidTest.java
Modified:
camel/branches/camel-2.7.x/ (props changed)
camel/branches/camel-2.7.x/camel-core/src/main/java/org/apache/camel/NoSuchBeanException.java
camel/branches/camel-2.7.x/camel-core/src/main/java/org/apache/camel/component/ref/RefComponent.java
camel/branches/camel-2.7.x/camel-core/src/main/java/org/apache/camel/util/CamelContextHelper.java
camel/branches/camel-2.7.x/camel-core/src/test/java/org/apache/camel/impl/CamelPostProcessorHelperTest.java
camel/branches/camel-2.7.x/camel-core/src/test/java/org/apache/camel/impl/DefaultComponentTest.java
camel/branches/camel-2.7.x/components/camel-jdbc/src/test/java/org/apache/camel/component/jdbc/JdbcOptionsTest.java
Propchange: camel/branches/camel-2.7.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Jul 13 14:59:49 2011
@@ -1 +1 @@
-/camel/trunk:1083696,1083723-1083724,1084150,1085277,1085543,1085549,1085905,1085909,1086165,1086231,1087005,1087276,1087612,1087620,1087856,1088583,1088916-1088917,1089275,1089348,1090166,1090204,1090564,1090960-1090969,1091082,1091518,1091771,1091799,1092034,1092068,1092577,1092667,1093978,1093980,1093999,1094123,1094147,1094156,1095405,1095469,1095471,1095475-1095476,1096346,1096736,1097761,1097909,1097912,1097978,1098032,1098628,1098630,1099228,1099417,1100711,1100975,1102162,1102177,1102181,1104076,1124497,1127744,1127988,1128315,1128970,1131411,1132961,1134252,1134260,1134404,1134441,1134501,1134626,1134681,1134714-1134911,1135223,1135364,1136065,1136290,1137696,1138285,1139163,1139747,1139749,1140096-1140102,1141783,1142500,1142654,1142721,1143332,1143925,1144248,1144324
+/camel/trunk:1083696,1083723-1083724,1084150,1085277,1085543,1085549,1085905,1085909,1086165,1086231,1087005,1087276,1087612,1087620,1087856,1088583,1088916-1088917,1089275,1089348,1090166,1090204,1090564,1090960-1090969,1091082,1091518,1091771,1091799,1092034,1092068,1092577,1092667,1093978,1093980,1093999,1094123,1094147,1094156,1095405,1095469,1095471,1095475-1095476,1096346,1096736,1097761,1097909,1097912,1097978,1098032,1098628,1098630,1099228,1099417,1100711,1100975,1102162,1102177,1102181,1104076,1124497,1127744,1127988,1128315,1128970,1131411,1132961,1134252,1134260,1134404,1134441,1134501,1134626,1134681,1134714-1134911,1135223,1135364,1136065,1136290,1137696,1138285,1139163,1139747,1139749,1140096-1140102,1141783,1142500,1142654,1142721,1143332,1143925,1144248,1144324,1146057
Propchange: camel/branches/camel-2.7.x/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified:
camel/branches/camel-2.7.x/camel-core/src/main/java/org/apache/camel/NoSuchBeanException.java
URL:
http://svn.apache.org/viewvc/camel/branches/camel-2.7.x/camel-core/src/main/java/org/apache/camel/NoSuchBeanException.java?rev=1146086&r1=1146085&r2=1146086&view=diff
==============================================================================
---
camel/branches/camel-2.7.x/camel-core/src/main/java/org/apache/camel/NoSuchBeanException.java
(original)
+++
camel/branches/camel-2.7.x/camel-core/src/main/java/org/apache/camel/NoSuchBeanException.java
Wed Jul 13 14:59:49 2011
@@ -30,6 +30,11 @@ public class NoSuchBeanException extends
this.name = name;
}
+ public NoSuchBeanException(String name, String type) {
+ super("No bean could be found in the registry for: " + name + " of
type: " + type);
+ this.name = name;
+ }
+
public NoSuchBeanException(String name, Throwable cause) {
super("No bean could be found in the registry for: " + name + ".
Cause: " + cause.getMessage(), cause);
this.name = name;
Modified:
camel/branches/camel-2.7.x/camel-core/src/main/java/org/apache/camel/component/ref/RefComponent.java
URL:
http://svn.apache.org/viewvc/camel/branches/camel-2.7.x/camel-core/src/main/java/org/apache/camel/component/ref/RefComponent.java?rev=1146086&r1=1146085&r2=1146086&view=diff
==============================================================================
---
camel/branches/camel-2.7.x/camel-core/src/main/java/org/apache/camel/component/ref/RefComponent.java
(original)
+++
camel/branches/camel-2.7.x/camel-core/src/main/java/org/apache/camel/component/ref/RefComponent.java
Wed Jul 13 14:59:49 2011
@@ -20,6 +20,7 @@ import java.util.Map;
import org.apache.camel.Endpoint;
import org.apache.camel.impl.DefaultComponent;
+import org.apache.camel.util.CamelContextHelper;
/**
* Component for lookup of existing endpoints bound in the {@link
org.apache.camel.spi.Registry}.
@@ -42,13 +43,15 @@ public class RefComponent extends Defaul
}
/**
- * Looks up an endpoint for a given name.
- *
+ * Looks up a mandatory endpoint for a given name.
+ * <p/>
* Derived classes could use this name as a logical name and look it up on
some registry.
+ * <p/>
+ * The default implementation will do a mandatory look up the name in the
{@link org.apache.camel.spi.Registry}.
*
- * The default implementation will look up the name in the registry of the
{@link #getCamelContext()} property
+ * @throws org.apache.camel.NoSuchBeanException if not found in the {@link
org.apache.camel.spi.Registry}
*/
protected Endpoint lookupEndpoint(String name, Map<String, Object>
parameters) {
- return getCamelContext().getRegistry().lookup(name, Endpoint.class);
+ return CamelContextHelper.mandatoryLookup(getCamelContext(), name,
Endpoint.class);
}
}
Modified:
camel/branches/camel-2.7.x/camel-core/src/main/java/org/apache/camel/util/CamelContextHelper.java
URL:
http://svn.apache.org/viewvc/camel/branches/camel-2.7.x/camel-core/src/main/java/org/apache/camel/util/CamelContextHelper.java?rev=1146086&r1=1146085&r2=1146086&view=diff
==============================================================================
---
camel/branches/camel-2.7.x/camel-core/src/main/java/org/apache/camel/util/CamelContextHelper.java
(original)
+++
camel/branches/camel-2.7.x/camel-core/src/main/java/org/apache/camel/util/CamelContextHelper.java
Wed Jul 13 14:59:49 2011
@@ -19,6 +19,7 @@ package org.apache.camel.util;
import org.apache.camel.CamelContext;
import org.apache.camel.Endpoint;
import org.apache.camel.Exchange;
+import org.apache.camel.NoSuchBeanException;
import org.apache.camel.NoSuchEndpointException;
import static org.apache.camel.util.ObjectHelper.isEmpty;
@@ -107,21 +108,25 @@ public final class CamelContextHelper {
/**
* Look up the given named bean in the {@link
org.apache.camel.spi.Registry} on the
- * {@link CamelContext} or throws IllegalArgumentException if not found.
+ * {@link CamelContext} or throws NoSuchBeanException if not found.
*/
public static Object mandatoryLookup(CamelContext context, String name) {
Object answer = lookup(context, name);
- notNull(answer, "registry entry called " + name);
+ if (answer == null) {
+ throw new NoSuchBeanException(name);
+ }
return answer;
}
/**
* Look up the given named bean of the given type in the {@link
org.apache.camel.spi.Registry} on the
- * {@link CamelContext} or throws IllegalArgumentException if not found.
+ * {@link CamelContext} or throws NoSuchBeanException if not found.
*/
public static <T> T mandatoryLookup(CamelContext context, String name,
Class<T> beanType) {
T answer = lookup(context, name, beanType);
- notNull(answer, "registry entry called " + name + " of type " +
beanType.getName());
+ if (answer == null) {
+ throw new NoSuchBeanException(name, beanType.getName());
+ }
return answer;
}
Modified:
camel/branches/camel-2.7.x/camel-core/src/test/java/org/apache/camel/impl/CamelPostProcessorHelperTest.java
URL:
http://svn.apache.org/viewvc/camel/branches/camel-2.7.x/camel-core/src/test/java/org/apache/camel/impl/CamelPostProcessorHelperTest.java?rev=1146086&r1=1146085&r2=1146086&view=diff
==============================================================================
---
camel/branches/camel-2.7.x/camel-core/src/test/java/org/apache/camel/impl/CamelPostProcessorHelperTest.java
(original)
+++
camel/branches/camel-2.7.x/camel-core/src/test/java/org/apache/camel/impl/CamelPostProcessorHelperTest.java
Wed Jul 13 14:59:49 2011
@@ -23,6 +23,7 @@ import org.apache.camel.Consume;
import org.apache.camel.ContextTestSupport;
import org.apache.camel.EndpointInject;
import org.apache.camel.Exchange;
+import org.apache.camel.NoSuchBeanException;
import org.apache.camel.PollingConsumer;
import org.apache.camel.Processor;
import org.apache.camel.Produce;
@@ -251,8 +252,8 @@ public class CamelPostProcessorHelperTes
try {
helper.getInjectionValue(type, endpointInject.uri(),
endpointInject.ref(), propertyName, bean, "foo");
fail("Should throw exception");
- } catch (IllegalArgumentException e) {
- assertEquals("registry entry called unknown of type
org.apache.camel.Endpoint must be specified", e.getMessage());
+ } catch (NoSuchBeanException e) {
+ assertEquals("No bean could be found in the registry for: unknown
of type: org.apache.camel.Endpoint", e.getMessage());
}
}
Modified:
camel/branches/camel-2.7.x/camel-core/src/test/java/org/apache/camel/impl/DefaultComponentTest.java
URL:
http://svn.apache.org/viewvc/camel/branches/camel-2.7.x/camel-core/src/test/java/org/apache/camel/impl/DefaultComponentTest.java?rev=1146086&r1=1146085&r2=1146086&view=diff
==============================================================================
---
camel/branches/camel-2.7.x/camel-core/src/test/java/org/apache/camel/impl/DefaultComponentTest.java
(original)
+++
camel/branches/camel-2.7.x/camel-core/src/test/java/org/apache/camel/impl/DefaultComponentTest.java
Wed Jul 13 14:59:49 2011
@@ -25,6 +25,7 @@ import java.util.Map;
import org.apache.camel.CamelContext;
import org.apache.camel.ContextTestSupport;
import org.apache.camel.Endpoint;
+import org.apache.camel.NoSuchBeanException;
/**
* Unit test for helper methods on the DefaultComponent.
@@ -99,8 +100,8 @@ public class DefaultComponentTest extend
try {
my.resolveAndRemoveReferenceParameter(parameters, "date",
Date.class);
fail("returned without finding object in registry");
- } catch (IllegalArgumentException e) {
- // test passes
+ } catch (NoSuchBeanException e) {
+ assertEquals("No bean could be found in the registry for: somewhen
of type: java.util.Date", e.getMessage());
}
}
@@ -184,8 +185,8 @@ public class DefaultComponentTest extend
try {
my.resolveAndRemoveReferenceListParameter(parameters, "dates",
Date.class);
fail("returned without finding object in registry");
- } catch (IllegalArgumentException e) {
- // test passes
+ } catch (NoSuchBeanException e) {
+ assertEquals("No bean could be found in the registry for: bean3 of
type: java.util.Date", e.getMessage());
}
}
Modified:
camel/branches/camel-2.7.x/components/camel-jdbc/src/test/java/org/apache/camel/component/jdbc/JdbcOptionsTest.java
URL:
http://svn.apache.org/viewvc/camel/branches/camel-2.7.x/components/camel-jdbc/src/test/java/org/apache/camel/component/jdbc/JdbcOptionsTest.java?rev=1146086&r1=1146085&r2=1146086&view=diff
==============================================================================
---
camel/branches/camel-2.7.x/components/camel-jdbc/src/test/java/org/apache/camel/component/jdbc/JdbcOptionsTest.java
(original)
+++
camel/branches/camel-2.7.x/components/camel-jdbc/src/test/java/org/apache/camel/component/jdbc/JdbcOptionsTest.java
Wed Jul 13 14:59:49 2011
@@ -58,7 +58,7 @@ public class JdbcOptionsTest extends Cam
template.sendBody("jdbc:xxx", "Hello World");
fail("Should have thrown a ResolveEndpointFailedException");
} catch (ResolveEndpointFailedException e) {
- assertEquals("registry entry called xxx of type
javax.sql.DataSource must be specified",
+ assertEquals("No bean could be found in the registry for: xxx of
type: javax.sql.DataSource",
e.getCause().getMessage());
}
}