You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by jb...@apache.org on 2009/08/02 15:47:57 UTC
svn commit: r800077 - in
/servicemix/components/bindings/servicemix-rmi/trunk/src:
main/java/org/apache/servicemix/rmi/ test/java/org/apache/servicemix/rmi/
test/resources/xbean/
Author: jbonofre
Date: Sun Aug 2 13:47:57 2009
New Revision: 800077
URL: http://svn.apache.org/viewvc?rev=800077&view=rev
Log:
Add new unit tests.
Added:
servicemix/components/bindings/servicemix-rmi/trunk/src/test/java/org/apache/servicemix/rmi/ClientTest.java (with props)
servicemix/components/bindings/servicemix-rmi/trunk/src/test/java/org/apache/servicemix/rmi/EchoImpl.java (with props)
Modified:
servicemix/components/bindings/servicemix-rmi/trunk/src/main/java/org/apache/servicemix/rmi/RmiComponent.java
servicemix/components/bindings/servicemix-rmi/trunk/src/main/java/org/apache/servicemix/rmi/RmiConsumerEndpoint.java
servicemix/components/bindings/servicemix-rmi/trunk/src/main/java/org/apache/servicemix/rmi/RmiEndpointType.java
servicemix/components/bindings/servicemix-rmi/trunk/src/test/java/org/apache/servicemix/rmi/RmiXBeanTest.java
servicemix/components/bindings/servicemix-rmi/trunk/src/test/resources/xbean/xbean.xml
Modified: servicemix/components/bindings/servicemix-rmi/trunk/src/main/java/org/apache/servicemix/rmi/RmiComponent.java
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-rmi/trunk/src/main/java/org/apache/servicemix/rmi/RmiComponent.java?rev=800077&r1=800076&r2=800077&view=diff
==============================================================================
--- servicemix/components/bindings/servicemix-rmi/trunk/src/main/java/org/apache/servicemix/rmi/RmiComponent.java (original)
+++ servicemix/components/bindings/servicemix-rmi/trunk/src/main/java/org/apache/servicemix/rmi/RmiComponent.java Sun Aug 2 13:47:57 2009
@@ -24,7 +24,10 @@
* Binding component to work directly with RMI.
*
* @author jbonofre
- * @org.apache.xbean.XBean element="component" description="RMI Component"
+ * @org.apache.xbean.XBean element="component" description="RMI Component" RMI component
+ * allowing to use Java Remote Method Invocation (RMI). It provides a marshaler/unmarshaler
+ * to transfort RMI calls into a NMR format. It provide RMI proxy feature by delegating
+ * method execution to a POJO.
*/
public class RmiComponent extends DefaultComponent {
@@ -57,7 +60,7 @@
* @see org.apache.servicemix.common.DefaultComponent#getConfiguredEndpoints()
*/
protected List getConfiguredEndpoints() {
- return asList(this.endpoints);
+ return asList(this.getEndpoints());
}
/*
@@ -65,7 +68,7 @@
* @see org.apache.servicemix.common.DefaultComponent#getEndpointClasses()
*/
protected Class[] getEndpointClasses() {
- return new Class[] { RmiProviderEndpoint.class, RmiConsumerEndpoint.class, RmiBridgeEndpoint.class };
+ return new Class[] { RmiConsumerEndpoint.class};
}
}
Modified: servicemix/components/bindings/servicemix-rmi/trunk/src/main/java/org/apache/servicemix/rmi/RmiConsumerEndpoint.java
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-rmi/trunk/src/main/java/org/apache/servicemix/rmi/RmiConsumerEndpoint.java?rev=800077&r1=800076&r2=800077&view=diff
==============================================================================
--- servicemix/components/bindings/servicemix-rmi/trunk/src/main/java/org/apache/servicemix/rmi/RmiConsumerEndpoint.java (original)
+++ servicemix/components/bindings/servicemix-rmi/trunk/src/main/java/org/apache/servicemix/rmi/RmiConsumerEndpoint.java Sun Aug 2 13:47:57 2009
@@ -44,11 +44,10 @@
public class RmiConsumerEndpoint extends ConsumerEndpoint implements RmiEndpointType, InvocationHandler {
private List<Class> remoteInterfaces; // the remote interfaces
- private int port = 1099; // the RMI registry port number
private String name; // the endpoint name into the RMI registry
+ private int port = 5555; // the Registry port number
private Object pojo; // delegate method call to a POJO
- private Registry registry = null; // the RMI registry
private Remote stub; // the remote stub
private Remote proxy; // the remote proxy
@@ -67,36 +66,35 @@
this.remoteInterfaces = remoteInterfaces;
}
- public int getPort() {
- return this.port;
+ public String getName() {
+ return this.name;
}
/**
* <p>
- * This attribute defines the port number used by the RMI registry.
+ * This attribute defines the endpoint name in the RMI registry.
* </p>
*
- * @param port the RMI registry port number.
- * @org.apache.xbean.Property description="The RMI registry port number."
+ * @param name the endpoint name in the registry.
*/
- public void setPort(int port) {
- this.port = port;
+ public void setName(String name) {
+ this.name = name;
}
- public String getName() {
- return this.name;
+ public int getPort() {
+ return this.port;
}
/**
* <p>
- * This attribute defines the endpoint name in the RMI registry.
+ * This attribute defines the RMI registry port number.
* </p>
+ * <i> The default port number is <b>5555</b>.</i>
*
- * @param name the endpoint name in the registry.
- * @org.apache.xbean.Property description="The endpoint name into the RMI registry."
+ * @param port
*/
- public void setName(String name) {
- this.name = name;
+ public void setPort(int port) {
+ this.port = port;
}
public Object getPojo() {
@@ -109,7 +107,6 @@
* </p>
*
* @param pojo the delegation POJO.
- * @org.apache.xbean.Property description="The POJO on which method calls are delegated."
*/
public void setPojo(Object pojo) {
this.pojo = pojo;
@@ -158,18 +155,15 @@
remoteInterfaces.toArray(interfaces);
proxy = (Remote) Proxy.newProxyInstance(this.getClass().getClassLoader(), interfaces, this);
// create the remote stub
- stub = UnicastRemoteObject.exportObject(proxy, port);
+ stub = UnicastRemoteObject.exportObject(proxy, 0);
try {
- // create a RMI registry if required
- if (registry == null) {
- registry = LocateRegistry.createRegistry(port);
- }
// register the object into the registry
+ Registry registry = LocateRegistry.getRegistry();
registry.bind(name, stub);
} catch (Exception e) {
// an error occurs, unexport the name from the registry
try {
- registry.unbind(name);
+ UnicastRemoteObject.unexportObject(stub, true);
} catch (Throwable ignore) { }
stub = null;
throw e;
@@ -183,13 +177,8 @@
@Override
public synchronized void stop() throws Exception {
// unbind if required
- if (registry != null) {
- try {
- registry.unbind(name);
- } catch (Throwable ignore) { }
- }
- // unexport the proxy
- UnicastRemoteObject.unexportObject(proxy, true);
+ Registry registry = LocateRegistry.getRegistry();
+ registry.unbind(name);
super.stop();
}
@@ -198,9 +187,7 @@
* @see java.lang.reflect.InvocationHandler#invoke(java.lang.Object, java.lang.reflect.Method, java.lang.Object[])
*/
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
- logger.debug("Proxy: " + proxy);
- logger.debug("Method: " + method);
- logger.debug("Args: " + args);
+ logger.error("Remote invocation made");
if (pojo != null) {
// delegrate method call to the POJO
// WARNING: using POJO you bypass NMR and it's a direct POJO call
@@ -209,7 +196,7 @@
// going through the NMR
// TODO use a marshaler and send to the target endpoint
}
- return null;
+ return "test";
}
/*
Modified: servicemix/components/bindings/servicemix-rmi/trunk/src/main/java/org/apache/servicemix/rmi/RmiEndpointType.java
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-rmi/trunk/src/main/java/org/apache/servicemix/rmi/RmiEndpointType.java?rev=800077&r1=800076&r2=800077&view=diff
==============================================================================
--- servicemix/components/bindings/servicemix-rmi/trunk/src/main/java/org/apache/servicemix/rmi/RmiEndpointType.java (original)
+++ servicemix/components/bindings/servicemix-rmi/trunk/src/main/java/org/apache/servicemix/rmi/RmiEndpointType.java Sun Aug 2 13:47:57 2009
@@ -17,7 +17,9 @@
package org.apache.servicemix.rmi;
/**
+ * <p>
* Represents a RMI endpoint.
+ * </p>
*
* @author jbonofre
*/
Added: servicemix/components/bindings/servicemix-rmi/trunk/src/test/java/org/apache/servicemix/rmi/ClientTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-rmi/trunk/src/test/java/org/apache/servicemix/rmi/ClientTest.java?rev=800077&view=auto
==============================================================================
--- servicemix/components/bindings/servicemix-rmi/trunk/src/test/java/org/apache/servicemix/rmi/ClientTest.java (added)
+++ servicemix/components/bindings/servicemix-rmi/trunk/src/test/java/org/apache/servicemix/rmi/ClientTest.java Sun Aug 2 13:47:57 2009
@@ -0,0 +1,14 @@
+package org.apache.servicemix.rmi;
+
+import java.rmi.registry.LocateRegistry;
+import java.rmi.registry.Registry;
+
+public class ClientTest {
+
+ public final static void main(String args[]) throws Exception {
+ Registry registry = LocateRegistry.getRegistry("localhost", 1099);
+ Echo stub = (Echo) registry.lookup("SimpleConsumer");
+ System.out.println(stub.echo("test"));
+ }
+
+}
Propchange: servicemix/components/bindings/servicemix-rmi/trunk/src/test/java/org/apache/servicemix/rmi/ClientTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: servicemix/components/bindings/servicemix-rmi/trunk/src/test/java/org/apache/servicemix/rmi/EchoImpl.java
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-rmi/trunk/src/test/java/org/apache/servicemix/rmi/EchoImpl.java?rev=800077&view=auto
==============================================================================
--- servicemix/components/bindings/servicemix-rmi/trunk/src/test/java/org/apache/servicemix/rmi/EchoImpl.java (added)
+++ servicemix/components/bindings/servicemix-rmi/trunk/src/test/java/org/apache/servicemix/rmi/EchoImpl.java Sun Aug 2 13:47:57 2009
@@ -0,0 +1,9 @@
+package org.apache.servicemix.rmi;
+
+public class EchoImpl implements Echo {
+
+ public String echo(String message) {
+ return message;
+ }
+
+}
Propchange: servicemix/components/bindings/servicemix-rmi/trunk/src/test/java/org/apache/servicemix/rmi/EchoImpl.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: servicemix/components/bindings/servicemix-rmi/trunk/src/test/java/org/apache/servicemix/rmi/RmiXBeanTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-rmi/trunk/src/test/java/org/apache/servicemix/rmi/RmiXBeanTest.java?rev=800077&r1=800076&r2=800077&view=diff
==============================================================================
--- servicemix/components/bindings/servicemix-rmi/trunk/src/test/java/org/apache/servicemix/rmi/RmiXBeanTest.java (original)
+++ servicemix/components/bindings/servicemix-rmi/trunk/src/test/java/org/apache/servicemix/rmi/RmiXBeanTest.java Sun Aug 2 13:47:57 2009
@@ -18,14 +18,23 @@
import java.io.File;
import java.net.URI;
import java.net.URL;
+import java.rmi.registry.LocateRegistry;
+import java.rmi.registry.Registry;
+import javax.jbi.messaging.ExchangeStatus;
+import javax.jbi.messaging.InOnly;
+import javax.jbi.servicedesc.ServiceEndpoint;
import javax.xml.namespace.QName;
import junit.framework.TestCase;
+import org.apache.camel.converter.jaxp.StringSource;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.client.DefaultServiceMixClient;
import org.apache.servicemix.jbi.container.JBIContainer;
+import org.apache.servicemix.jbi.jaxp.SourceTransformer;
+import org.springframework.core.io.ClassPathResource;
/**
* <p>
@@ -48,10 +57,26 @@
protected void setUp() throws Exception {
// create and start the JBI container
container = new JBIContainer();
- container.setUseMBeanServer(false);
- container.setCreateMBeanServer(false);
- container.setEmbedded(true);
+ container.setRmiPort(1099);
+ container.setUseMBeanServer(true);
+ container.setCreateMBeanServer(true);
+ container.setEmbedded(false);
container.init();
+
+ // deploy the RMI component
+ RmiComponent component = new RmiComponent();
+ // activate the RMI component into the JBI container
+ container.activateComponent(component, "RMIComponent");
+
+ // start the JBI container
+ container.start();
+
+ // deploy the SU based on the xbean.xml
+ File path = new ClassPathResource("xbean/xbean.xml").getFile();
+ path = path.getParentFile();
+ component.getServiceUnitManager().deploy("xbean", path.getAbsolutePath());
+ component.getServiceUnitManager().init("xbean", path.getAbsolutePath());
+ component.getServiceUnitManager().start("xbean");
}
/*
@@ -67,32 +92,27 @@
/**
* <p>
- * Main deployment test using a xbean.xml.
+ * Test if endpoints defined in the xbean have been deployed.
* </p>
- *
- * @throws Exception in case of deployment failure.
*/
- public void testDeployment() throws Exception {
- // RMI component
- RmiComponent rmiComponent = new RmiComponent();
- // activate the RMI component into the JBI container
- container.activateComponent(rmiComponent, "RmiComponent");
-
- // start the JBI container
- container.start();
-
- // deploy the RMI SU corresponding to the xbean.xml
- // deploy SU
- URL url = getClass().getClassLoader().getResource("xbean/xbean.xml");
- File path = new File(new URI(url.toString()));
- path = path.getParentFile();
- rmiComponent.getServiceUnitManager().deploy("xbean", path.getAbsolutePath());
- rmiComponent.getServiceUnitManager().init("xbean", path.getAbsolutePath());
- rmiComponent.getServiceUnitManager().start("xbean");
-
+ public void testDeployment() {
// test if the SUs have been deployed
- assertNotNull("RMI endpoint {http://servicemix.apache.org/test}rmiSimpleConsumer is not found in the JBI container.", container.getRegistry().getEndpoint(new QName("http://servicemix.apache.org/test", "rmi"), "SimpleConsumer"));
- assertNotNull("RMI endpoint {http://servicemix.apache.org/test}rmiByPassConsumer is not found in the JBI container.", container.getRegistry().getEndpoint(new QName("http://servicemix.apache.org/test", "rmi"), "ByPassConsumer"));
+ assertNotNull("RMI endpoint {http://servicemix.apache.org/test}RmiTestServiceSimpleConsumer is not found in the JBI container.", container.getRegistry().getEndpoint(new QName("http://servicemix.apache.org/test", "RmiTestService"), "SimpleConsumer"));
+ // assertNotNull("RMI endpoint {http://servicemix.apache.org/test}rmiByPassConsumer is not found in the JBI container.", container.getRegistry().getEndpoint(new QName("http://servicemix.apache.org/test", "rmi"), "ByPassConsumer"));
+ }
+
+ /**
+ * <p>
+ * Test an in
+ * </p>
+ *
+ * @throws Exception in case of exchange failure.
+ */
+ public void testConsumerExchange() throws Exception {
+ Registry registry = LocateRegistry.getRegistry("localhost", 1099);
+ Echo stub = (Echo) registry.lookup("SimpleConsumer");
+ String echo = stub.echo("test");
+ assertEquals("Bad response from the RMI endpoint", "test", echo);
}
}
Modified: servicemix/components/bindings/servicemix-rmi/trunk/src/test/resources/xbean/xbean.xml
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-rmi/trunk/src/test/resources/xbean/xbean.xml?rev=800077&r1=800076&r2=800077&view=diff
==============================================================================
--- servicemix/components/bindings/servicemix-rmi/trunk/src/test/resources/xbean/xbean.xml (original)
+++ servicemix/components/bindings/servicemix-rmi/trunk/src/test/resources/xbean/xbean.xml Sun Aug 2 13:47:57 2009
@@ -20,7 +20,7 @@
<beans xmlns:rmi="http://servicemix.apache.org/rmi/1.0"
xmlns:test="http://servicemix.apache.org/test">
- <rmi:consumer service="test:rmi" endpoint="SimpleConsumer">
+ <rmi:consumer service="test:RmiTestService" endpoint="SimpleConsumer">
<property name="remoteInterfaces">
<list>
<value>org.apache.servicemix.rmi.Echo</value>
@@ -29,7 +29,7 @@
</rmi:consumer>
<!--
- <rmi:consumer service="test:rmi" endpoint="ByPassConsumer" remoteInterfaces="org.apache.servicemix.rmi.Echo">
+ <rmi:consumer service="test:RmiTestService" endpoint="ByPassConsumer" remoteInterfaces="org.apache.servicemix.rmi.Echo">
<rmi:pojo>
<bean class="org.apache.servicenix.rmi.test.EchoImpl"/>
</rmi:pojo>