You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2012/01/10 15:46:46 UTC
svn commit: r1229565 - in /camel/trunk/components:
camel-blueprint/src/main/java/org/apache/camel/blueprint/
camel-spring/src/main/java/org/apache/camel/spring/
camel-spring/src/test/java/org/apache/camel/spring/issues/packagescan/
camel-spring/src/tes...
Author: davsclaus
Date: Tue Jan 10 14:46:45 2012
New Revision: 1229565
URL: http://svn.apache.org/viewvc?rev=1229565&view=rev
Log:
CAMEL-4875: Package scan for RouteBuilder classes should skip non public classes, such as anonymous inner classes.
Added:
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/issues/packagescan/
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/issues/packagescan/MyCoolRoute.java
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/issues/packagescan/SkipNonPublicRouteBuilderTest.java
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/issues/packagescan/
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/issues/packagescan/camelContext.xml
- copied, changed from r1229151, camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/issues/MisspelledRouteRefTest.xml
Modified:
camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/PackageScanRouteBuilderFinder.java
camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/PackageScanRouteBuilderFinder.java
Modified: camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/PackageScanRouteBuilderFinder.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/PackageScanRouteBuilderFinder.java?rev=1229565&r1=1229564&r2=1229565&view=diff
==============================================================================
--- camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/PackageScanRouteBuilderFinder.java (original)
+++ camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/PackageScanRouteBuilderFinder.java Tue Jan 10 14:46:45 2012
@@ -38,14 +38,12 @@ public class PackageScanRouteBuilderFind
private final String[] packages;
private final PackageScanClassResolver resolver;
private final BlueprintContainer blueprintContainer;
-// private final BeanPostProcessor beanPostProcessor;
public PackageScanRouteBuilderFinder(BlueprintCamelContext camelContext, String[] packages, ClassLoader classLoader,
- /*BeanPostProcessor postProcessor,*/ PackageScanClassResolver resolver) {
+ PackageScanClassResolver resolver) {
this.camelContext = camelContext;
this.blueprintContainer = camelContext.getBlueprintContainer();
this.packages = packages;
-// this.beanPostProcessor = postProcessor;
this.resolver = resolver;
// add our provided loader as well
resolver.addClassLoader(classLoader);
@@ -72,10 +70,6 @@ public class PackageScanRouteBuilderFind
// type is valid so create and instantiate the builder
RoutesBuilder builder = instantiateBuilder(aClass);
-// if (beanPostProcessor != null) {
- // Inject the annotated resource
-// beanPostProcessor.postProcessBeforeInitialization(builder, builder.toString());
-// }
LOG.debug("Adding instantiated RouteBuilder: {}", builder);
list.add(builder);
}
@@ -98,9 +92,14 @@ public class PackageScanRouteBuilderFind
}
/**
- * Returns true if the object is non-abstract and supports a zero argument constructor
+ * Returns <tt>true</tt>if the class is a public, non-abstract class
*/
protected boolean isValidClass(Class type) {
+ // should skip non public classes
+ if (!Modifier.isPublic(type.getModifiers())) {
+ return false;
+ }
+
if (!Modifier.isAbstract(type.getModifiers()) && !type.isInterface()) {
return true;
}
Modified: camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/PackageScanRouteBuilderFinder.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/PackageScanRouteBuilderFinder.java?rev=1229565&r1=1229564&r2=1229565&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/PackageScanRouteBuilderFinder.java (original)
+++ camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/PackageScanRouteBuilderFinder.java Tue Jan 10 14:46:45 2012
@@ -94,9 +94,14 @@ public class PackageScanRouteBuilderFind
}
/**
- * Returns true if the object is non-abstract and supports a zero argument constructor
+ * Returns <tt>true</tt>if the class is a public, non-abstract class
*/
protected boolean isValidClass(Class type) {
+ // should skip non public classes
+ if (!Modifier.isPublic(type.getModifiers())) {
+ return false;
+ }
+
if (!Modifier.isAbstract(type.getModifiers()) && !type.isInterface()) {
return true;
}
Added: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/issues/packagescan/MyCoolRoute.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/issues/packagescan/MyCoolRoute.java?rev=1229565&view=auto
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/issues/packagescan/MyCoolRoute.java (added)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/issues/packagescan/MyCoolRoute.java Tue Jan 10 14:46:45 2012
@@ -0,0 +1,30 @@
+/**
+ * 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.spring.issues.packagescan;
+
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ *
+ */
+public class MyCoolRoute extends RouteBuilder {
+
+ @Override
+ public void configure() throws Exception {
+ from("direct:cool").routeId("cool").to("mock:cool");
+ }
+}
Added: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/issues/packagescan/SkipNonPublicRouteBuilderTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/issues/packagescan/SkipNonPublicRouteBuilderTest.java?rev=1229565&view=auto
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/issues/packagescan/SkipNonPublicRouteBuilderTest.java (added)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/issues/packagescan/SkipNonPublicRouteBuilderTest.java Tue Jan 10 14:46:45 2012
@@ -0,0 +1,53 @@
+/**
+ * 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.spring.issues.packagescan;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.spring.SpringTestSupport;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+/**
+ *
+ */
+public class SkipNonPublicRouteBuilderTest extends SpringTestSupport {
+
+ @Override
+ protected AbstractXmlApplicationContext createApplicationContext() {
+ return new ClassPathXmlApplicationContext("org/apache/camel/spring/issues/packagescan/camelContext.xml");
+ }
+
+ public void testSkipNonPublicRouteBuilder() throws Exception {
+ context.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:bar").routeId("bar").to("mock:bar");
+ }
+ });
+ context.startRoute("bar");
+
+ getMockEndpoint("mock:foo").expectedMessageCount(1);
+ getMockEndpoint("mock:cool").expectedMessageCount(1);
+ getMockEndpoint("mock:bar").expectedMessageCount(1);
+
+ template.sendBody("direct:foo", "Hello World");
+ template.sendBody("direct:cool", "Bye World");
+ template.sendBody("direct:bar", "Hello Camel");
+
+ assertMockEndpointsSatisfied();
+ }
+}
Copied: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/issues/packagescan/camelContext.xml (from r1229151, camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/issues/MisspelledRouteRefTest.xml)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/issues/packagescan/camelContext.xml?p2=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/issues/packagescan/camelContext.xml&p1=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/issues/MisspelledRouteRefTest.xml&r1=1229151&r2=1229565&rev=1229565&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/issues/MisspelledRouteRefTest.xml (original)
+++ camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/issues/packagescan/camelContext.xml Tue Jan 10 14:46:45 2012
@@ -23,9 +23,11 @@
">
<camelContext xmlns="http://camel.apache.org/schema/spring">
- <routeBuilder ref="xxxroute"/>
+ <package>org.apache.camel.spring.issues.packagescan</package>
+ <route id="foo">
+ <from uri="direct:foo"/>
+ <to uri="mock:foo"/>
+ </route>
</camelContext>
- <bean id="route" class="org.apache.camel.spring.issues.MyRouteBuilder"/>
-
</beans>