You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ch...@apache.org on 2007/05/14 18:41:09 UTC
svn commit: r537904 - in /activemq/camel/trunk/camel-spring/src:
main/java/org/apache/camel/spring/remoting/
test/java/org/apache/camel/spring/remoting/
test/resources/org/apache/camel/spring/remoting/
Author: chirino
Date: Mon May 14 09:41:07 2007
New Revision: 537904
URL: http://svn.apache.org/viewvc?view=rev&rev=537904
Log:
Added a testcase that shows spring remoting in action using camel as the transport.
Added:
activemq/camel/trunk/camel-spring/src/test/java/org/apache/camel/spring/remoting/
activemq/camel/trunk/camel-spring/src/test/java/org/apache/camel/spring/remoting/ISay.java
activemq/camel/trunk/camel-spring/src/test/java/org/apache/camel/spring/remoting/SayService.java
activemq/camel/trunk/camel-spring/src/test/java/org/apache/camel/spring/remoting/SpringRemotingRouteTest.java
activemq/camel/trunk/camel-spring/src/test/resources/org/apache/camel/spring/remoting/
activemq/camel/trunk/camel-spring/src/test/resources/org/apache/camel/spring/remoting/spring.xml
Modified:
activemq/camel/trunk/camel-spring/src/main/java/org/apache/camel/spring/remoting/CamelProxyFactoryBean.java
Modified: activemq/camel/trunk/camel-spring/src/main/java/org/apache/camel/spring/remoting/CamelProxyFactoryBean.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-spring/src/main/java/org/apache/camel/spring/remoting/CamelProxyFactoryBean.java?view=diff&rev=537904&r1=537903&r2=537904
==============================================================================
--- activemq/camel/trunk/camel-spring/src/main/java/org/apache/camel/spring/remoting/CamelProxyFactoryBean.java (original)
+++ activemq/camel/trunk/camel-spring/src/main/java/org/apache/camel/spring/remoting/CamelProxyFactoryBean.java Mon May 14 09:41:07 2007
@@ -17,6 +17,7 @@
*/
package org.apache.camel.spring.remoting;
+import org.apache.camel.CamelContext;
import org.apache.camel.Endpoint;
import org.apache.camel.component.pojo.PojoComponent;
import org.springframework.beans.factory.FactoryBean;
@@ -29,6 +30,7 @@
*/
public class CamelProxyFactoryBean extends UrlBasedRemoteAccessor implements FactoryBean {
+ private CamelContext camelContext;
private Endpoint endpoint;
private Object serviceProxy;
@@ -36,6 +38,17 @@
public void afterPropertiesSet() {
super.afterPropertiesSet();
try {
+ if( endpoint == null ) {
+ if( getServiceUrl() == null || camelContext==null ) {
+ throw new IllegalArgumentException("If endpoint is not specified, the serviceUrl and camelContext must be specified.");
+ }
+
+ endpoint = camelContext.getEndpoint(getServiceUrl());
+ if( endpoint == null ) {
+ throw new IllegalArgumentException("Could not resolve endpoint: "+getServiceUrl());
+ }
+ }
+
this.serviceProxy = PojoComponent.createProxy(endpoint, getServiceInterface());
} catch (Exception e) {
throw new IllegalArgumentException(e);
@@ -60,6 +73,14 @@
public void setEndpoint(Endpoint endpoint) {
this.endpoint = endpoint;
+ }
+
+ public CamelContext getCamelContext() {
+ return camelContext;
+ }
+
+ public void setCamelContext(CamelContext camelContext) {
+ this.camelContext = camelContext;
}
}
Added: activemq/camel/trunk/camel-spring/src/test/java/org/apache/camel/spring/remoting/ISay.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-spring/src/test/java/org/apache/camel/spring/remoting/ISay.java?view=auto&rev=537904
==============================================================================
--- activemq/camel/trunk/camel-spring/src/test/java/org/apache/camel/spring/remoting/ISay.java (added)
+++ activemq/camel/trunk/camel-spring/src/test/java/org/apache/camel/spring/remoting/ISay.java Mon May 14 09:41:07 2007
@@ -0,0 +1,24 @@
+/*
+ * 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.remoting;
+
+import java.rmi.Remote;
+import java.rmi.RemoteException;
+
+public interface ISay extends Remote {
+ public String say() throws RemoteException;
+}
Added: activemq/camel/trunk/camel-spring/src/test/java/org/apache/camel/spring/remoting/SayService.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-spring/src/test/java/org/apache/camel/spring/remoting/SayService.java?view=auto&rev=537904
==============================================================================
--- activemq/camel/trunk/camel-spring/src/test/java/org/apache/camel/spring/remoting/SayService.java (added)
+++ activemq/camel/trunk/camel-spring/src/test/java/org/apache/camel/spring/remoting/SayService.java Mon May 14 09:41:07 2007
@@ -0,0 +1,40 @@
+/*
+ * 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.remoting;
+
+public class SayService implements ISay {
+ String message = "Hello";
+
+ public SayService() {
+ }
+ public SayService(String message) {
+ this.message = message;
+ }
+
+ public String say() {
+ return message;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ public void setMessage(String message) {
+ this.message = message;
+ }
+
+}
Added: activemq/camel/trunk/camel-spring/src/test/java/org/apache/camel/spring/remoting/SpringRemotingRouteTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-spring/src/test/java/org/apache/camel/spring/remoting/SpringRemotingRouteTest.java?view=auto&rev=537904
==============================================================================
--- activemq/camel/trunk/camel-spring/src/test/java/org/apache/camel/spring/remoting/SpringRemotingRouteTest.java (added)
+++ activemq/camel/trunk/camel-spring/src/test/java/org/apache/camel/spring/remoting/SpringRemotingRouteTest.java Mon May 14 09:41:07 2007
@@ -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.spring.remoting;
+
+import junit.framework.TestCase;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.spring.SpringCamelContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+/**
+ * @version $Revision: 520220 $
+ */
+public class SpringRemotingRouteTest extends TestCase {
+
+ public void testPojoRoutes() throws Exception {
+
+ ClassPathXmlApplicationContext spring = new ClassPathXmlApplicationContext("org/apache/camel/spring/remoting/spring.xml");
+ CamelContext camelContext = SpringCamelContext.springCamelContext(spring);
+ camelContext.start();
+
+ // START SNIPPET: invoke
+ ISay proxy = (ISay) spring.getBean("sayProxy");
+ String rc = proxy.say();
+ assertEquals("Hello", rc);
+ // END SNIPPET: invoke
+
+ camelContext.stop();
+ spring.destroy();
+ }
+
+}
Added: activemq/camel/trunk/camel-spring/src/test/resources/org/apache/camel/spring/remoting/spring.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-spring/src/test/resources/org/apache/camel/spring/remoting/spring.xml?view=auto&rev=537904
==============================================================================
--- activemq/camel/trunk/camel-spring/src/test/resources/org/apache/camel/spring/remoting/spring.xml (added)
+++ activemq/camel/trunk/camel-spring/src/test/resources/org/apache/camel/spring/remoting/spring.xml Mon May 14 09:41:07 2007
@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
+ http://activemq.apache.org/camel/schema/camel-1.0.xsd http://activemq.apache.org/camel/schema/camel-1.0.xsd
+ ">
+
+ <!-- START SNIPPET: export -->
+ <bean id="sayService" class="org.apache.camel.spring.remoting.SayService"/>
+
+ <!-- Exposes the above bean as via the pojo:say endpoint -->
+ <bean class="org.apache.camel.spring.remoting.CamelServiceExporter">
+ <property name="camelContext" ref="camel"/>
+ <property name="serviceName" value="say"/>
+ <property name="service" ref="sayService"/>
+ <property name="serviceInterface" value="org.apache.camel.spring.remoting.ISay"/>
+ </bean>
+ <!-- END SNIPPET: export -->
+
+ <!-- START SNIPPET: proxy -->
+ <!-- Creates a proxy to the direct:say endpoint. -->
+ <bean id="sayProxy" class="org.apache.camel.spring.remoting.CamelProxyFactoryBean">
+ <property name="camelContext" ref="camel"/>
+ <property name="serviceUrl" value="direct:say"/>
+ <property name="serviceInterface" value="org.apache.camel.spring.remoting.ISay"/>
+ </bean>
+ <!-- END SNIPPET: proxy -->
+
+ <!-- START SNIPPET: example -->
+ <camelContext id="camel" xmlns="http://activemq.apache.org/camel/schema/camel-1.0.xsd">
+ <route>
+ <from uri="direct:say"/>
+ <to uri="pojo:say"/>
+ </route>
+ </camelContext>
+ <!-- END SNIPPET: example -->
+
+
+
+</beans>
+<!-- END SNIPPET: example -->