Author: davsclaus
Date: Sat Jun 12 16:54:41 2010
New Revision: 954036
URL: http://svn.apache.org/viewvc?rev=954036&view=rev
Log:
CAMEL-2705: Added new class component.
Added:
camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/ClassComponent.java
(with props)
camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/component/class
camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/ClassComponentInvalidConfigurationTest.java
(with props)
camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/ClassComponentTest.java
(with props)
camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/ClassComponentWithPropertiesLookupSetFromEndpointTest.java
(with props)
camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/ClassComponentWithPropertiesSetFromEndpointTest.java
(with props)
camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/MyPrefixBean.java
(with props)
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanComponent.java
camel/trunk/camel-core/src/main/java/org/apache/camel/spi/Injector.java
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanComponent.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanComponent.java?rev=954036&r1=954035&r2=954036&view=diff
==============================================================================
---
camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanComponent.java
(original)
+++
camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanComponent.java
Sat Jun 12 16:54:41 2010
@@ -24,8 +24,8 @@ import org.apache.camel.impl.DefaultComp
import org.apache.camel.impl.ProcessorEndpoint;
/**
- * The <a href="http://activemq.apache.org/bean.html">Bean Component</a>
- * will look up the URI in the Spring ApplicationContext and use that to
handle message dispatching.
+ * The <a href="http://camel.apache.org/bean.html">Bean Component</a>
+ * will look up the URI in the {...@link org.apache.camel.spi.Registry} and
use that to handle message dispatching.
*
* @version $Revision$
*/
Added:
camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/ClassComponent.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/ClassComponent.java?rev=954036&view=auto
==============================================================================
---
camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/ClassComponent.java
(added)
+++
camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/ClassComponent.java
Sat Jun 12 16:54:41 2010
@@ -0,0 +1,56 @@
+/**
+ * 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.component.bean;
+
+import java.util.Map;
+
+import org.apache.camel.Endpoint;
+import org.apache.camel.Processor;
+
+/**
+ * The <a href="http://camel.apache.org/class.html">Class Component</a>
+ * will create an instance of the class from the {...@link
org.apache.camel.spi.Registry} and use that to handle message dispatching.
+ *
+ * @version $Revision$
+ */
+public class ClassComponent extends BeanComponent {
+
+ @SuppressWarnings("unchecked")
+ protected Endpoint createEndpoint(String uri, String remaining,
Map<String, Object> parameters) throws Exception {
+ BeanEndpoint endpoint = new BeanEndpoint(uri, this);
+ endpoint.setBeanName(remaining);
+
+ // bean name is the FQN
+ String name = endpoint.getBeanName();
+ Class clazz =
getCamelContext().getClassResolver().resolveMandatoryClass(name);
+ // create bean
+ Object bean = getCamelContext().getInjector().newInstance(clazz);
+
+ // now set additional properties on it
+ setProperties(bean, parameters);
+
+ // and register the bean as a holder on the endpoint
+ BeanHolder holder = new ConstantBeanHolder(bean, getCamelContext());
+ endpoint.setBeanHolder(holder);
+
+ // create processor
+ Processor processor = endpoint.getProcessor();
+ setProperties(processor, parameters);
+ return endpoint;
+ }
+
+}
Propchange:
camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/ClassComponent.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/ClassComponent.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/spi/Injector.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/Injector.java?rev=954036&r1=954035&r2=954036&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/spi/Injector.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/spi/Injector.java Sat
Jun 12 16:54:41 2010
@@ -38,6 +38,7 @@ public interface Injector {
* Instantiates a new instance of the given object type possibly injecting
values
* into the object in the process
*
+ * @param type the type of object to create
* @param instance an instance of the type to create
* @return a newly created instance
*/
Added:
camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/component/class
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/component/class?rev=954036&view=auto
==============================================================================
---
camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/component/class
(added)
+++
camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/component/class
Sat Jun 12 16:54:41 2010
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+
+class=org.apache.camel.component.bean.ClassComponent
\ No newline at end of file
Added:
camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/ClassComponentInvalidConfigurationTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/ClassComponentInvalidConfigurationTest.java?rev=954036&view=auto
==============================================================================
---
camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/ClassComponentInvalidConfigurationTest.java
(added)
+++
camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/ClassComponentInvalidConfigurationTest.java
Sat Jun 12 16:54:41 2010
@@ -0,0 +1,72 @@
+/**
+ * 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.component.bean;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.FailedToCreateRouteException;
+import org.apache.camel.ResolveEndpointFailedException;
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ * @version $Revision$
+ */
+public class ClassComponentInvalidConfigurationTest extends ContextTestSupport
{
+
+ @Override
+ public boolean isUseRouteBuilder() {
+ return false;
+ }
+
+ public void testClassNotFound() throws Exception {
+ context.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start")
+ .to("class:org.apache.camel.component.bean.XXX")
+ .to("mock:result");
+ }
+ });
+ try {
+ context.start();
+ fail("Should have thrown exception");
+ } catch (FailedToCreateRouteException e) {
+ ResolveEndpointFailedException cause =
assertIsInstanceOf(ResolveEndpointFailedException.class, e.getCause());
+ ClassNotFoundException not =
assertIsInstanceOf(ClassNotFoundException.class, cause.getCause());
+ assertEquals("org.apache.camel.component.bean.XXX",
not.getMessage());
+ }
+ }
+
+ public void testPropertyNotFoundOnClass() throws Exception {
+ context.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start")
+
.to("class:org.apache.camel.component.bean.MyPrefixBean?foo=bar")
+ .to("mock:result");
+ }
+ });
+ try {
+ context.start();
+ fail("Should have thrown exception");
+ } catch (FailedToCreateRouteException e) {
+ ResolveEndpointFailedException cause =
assertIsInstanceOf(ResolveEndpointFailedException.class, e.getCause());
+ assertTrue(cause.getMessage().contains("Unknown parameters"));
+ assertTrue(cause.getMessage().contains("foo=bar"));
+ }
+ }
+
+}
\ No newline at end of file
Propchange:
camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/ClassComponentInvalidConfigurationTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/ClassComponentInvalidConfigurationTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/ClassComponentTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/ClassComponentTest.java?rev=954036&view=auto
==============================================================================
---
camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/ClassComponentTest.java
(added)
+++
camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/ClassComponentTest.java
Sat Jun 12 16:54:41 2010
@@ -0,0 +1,45 @@
+/**
+ * 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.component.bean;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ * @version $Revision$
+ */
+public class ClassComponentTest extends ContextTestSupport {
+
+ public void testClassComponent() throws Exception {
+ getMockEndpoint("mock:result").expectedBodiesReceived("Hello World",
"Hello Camel");
+
+ template.sendBody("direct:start", "World");
+ template.sendBody("direct:start", "Camel");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+
from("direct:start").to("class:org.apache.camel.component.bean.MyFooBean").to("mock:result");
+ }
+ };
+ }
+}
Propchange:
camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/ClassComponentTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/ClassComponentTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/ClassComponentWithPropertiesLookupSetFromEndpointTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/ClassComponentWithPropertiesLookupSetFromEndpointTest.java?rev=954036&view=auto
==============================================================================
---
camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/ClassComponentWithPropertiesLookupSetFromEndpointTest.java
(added)
+++
camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/ClassComponentWithPropertiesLookupSetFromEndpointTest.java
Sat Jun 12 16:54:41 2010
@@ -0,0 +1,55 @@
+/**
+ * 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.component.bean;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.impl.JndiRegistry;
+
+/**
+ * @version $Revision$
+ */
+public class ClassComponentWithPropertiesLookupSetFromEndpointTest extends
ContextTestSupport {
+
+ @Override
+ protected JndiRegistry createRegistry() throws Exception {
+ JndiRegistry jndi = super.createRegistry();
+ jndi.bind("foo", "Hi");
+ return jndi;
+ }
+
+ public void testClassComponent() throws Exception {
+ getMockEndpoint("mock:result").expectedBodiesReceived("Hi World");
+
+ template.sendBody("direct:start", "World");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start")
+
.to("class:org.apache.camel.component.bean.MyPrefixBean?prefix=#foo")
+ .to("mock:result");
+ }
+ };
+ }
+
+}
\ No newline at end of file
Propchange:
camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/ClassComponentWithPropertiesLookupSetFromEndpointTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/ClassComponentWithPropertiesLookupSetFromEndpointTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/ClassComponentWithPropertiesSetFromEndpointTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/ClassComponentWithPropertiesSetFromEndpointTest.java?rev=954036&view=auto
==============================================================================
---
camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/ClassComponentWithPropertiesSetFromEndpointTest.java
(added)
+++
camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/ClassComponentWithPropertiesSetFromEndpointTest.java
Sat Jun 12 16:54:41 2010
@@ -0,0 +1,47 @@
+/**
+ * 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.component.bean;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ * @version $Revision$
+ */
+public class ClassComponentWithPropertiesSetFromEndpointTest extends
ContextTestSupport {
+
+ public void testClassComponent() throws Exception {
+ getMockEndpoint("mock:result").expectedBodiesReceived("Bye World");
+
+ template.sendBody("direct:start", "World");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start")
+
.to("class:org.apache.camel.component.bean.MyPrefixBean?prefix=Bye")
+ .to("mock:result");
+ }
+ };
+ }
+
+}
\ No newline at end of file
Propchange:
camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/ClassComponentWithPropertiesSetFromEndpointTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/ClassComponentWithPropertiesSetFromEndpointTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/MyPrefixBean.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/MyPrefixBean.java?rev=954036&view=auto
==============================================================================
---
camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/MyPrefixBean.java
(added)
+++
camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/MyPrefixBean.java
Sat Jun 12 16:54:41 2010
@@ -0,0 +1,34 @@
+/**
+ * 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.component.bean;
+
+public class MyPrefixBean {
+ private String prefix;
+
+ public String getPrefix() {
+ return prefix;
+ }
+
+ public void setPrefix(String prefix) {
+ this.prefix = prefix;
+ }
+
+ public String hello(String s) {
+ return prefix + " " + s;
+ }
+
+}
\ No newline at end of file
Propchange:
camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/MyPrefixBean.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/MyPrefixBean.java
------------------------------------------------------------------------------
svn:keywords = Rev Date