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/03 22:22:25 UTC
svn commit: r800527 - in
/servicemix/components/bindings/servicemix-rmi/trunk/src:
main/java/org/apache/servicemix/rmi/
main/java/org/apache/servicemix/rmi/marshaler/
test/java/org/apache/servicemix/rmi/ test/resources/xbean/
Author: jbonofre
Date: Mon Aug 3 20:22:24 2009
New Revision: 800527
URL: http://svn.apache.org/viewvc?rev=800527&view=rev
Log:
Complete RMI endpoints workflow. Change the RMI marshaler signature.
Added:
servicemix/components/bindings/servicemix-rmi/trunk/src/main/java/org/apache/servicemix/rmi/marshaler/RmiCall.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/RmiProviderEndpoint.java
servicemix/components/bindings/servicemix-rmi/trunk/src/main/java/org/apache/servicemix/rmi/marshaler/DefaultRmiMarshaler.java
servicemix/components/bindings/servicemix-rmi/trunk/src/main/java/org/apache/servicemix/rmi/marshaler/RmiMarshalerSupport.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=800527&r1=800526&r2=800527&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 Mon Aug 3 20:22:24 2009
@@ -68,7 +68,7 @@
* @see org.apache.servicemix.common.DefaultComponent#getEndpointClasses()
*/
protected Class[] getEndpointClasses() {
- return new Class[] { RmiConsumerEndpoint.class};
+ return new Class[] { RmiConsumerEndpoint.class, RmiProviderEndpoint.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=800527&r1=800526&r2=800527&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 Mon Aug 3 20:22:24 2009
@@ -26,11 +26,14 @@
import javax.jbi.management.DeploymentException;
import javax.jbi.messaging.ExchangeStatus;
+import javax.jbi.messaging.InOut;
import javax.jbi.messaging.MessageExchange;
import javax.jbi.messaging.MessagingException;
+import javax.jbi.messaging.NormalizedMessage;
import org.apache.servicemix.common.endpoints.ConsumerEndpoint;
import org.apache.servicemix.rmi.marshaler.DefaultRmiMarshaler;
+import org.apache.servicemix.rmi.marshaler.RmiCall;
import org.apache.servicemix.rmi.marshaler.RmiMarshalerSupport;
/**
@@ -47,6 +50,7 @@
private Class remoteInterface; // the remote interface
private RmiMarshalerSupport marshaler = new DefaultRmiMarshaler();
+ private String host = "0.0.0.0"; // the java.rmi.server.hostname property value
private String name; // the endpoint name into the RMI registry
private Object pojo; // delegate method call to a POJO
@@ -68,6 +72,23 @@
this.remoteInterface = remoteInterface;
}
+ public String getHost() {
+ return this.host;
+ }
+
+ /**
+ * <p>
+ * This attribute defines the RMI server host name. This host name is embedded in the RMI
+ * stub to allow remote RMI call.
+ * </p>
+ * <i> The default value is <b>0.0.0.0</b>.</i>
+ *
+ * @param host
+ */
+ public void setHost(String host) {
+ this.host = host;
+ }
+
public String getName() {
return this.name;
}
@@ -126,6 +147,7 @@
logger.debug("The user hasn't define the registry name, use the endpoint one.");
name = this.getEndpoint();
}
+
}
/*
@@ -136,6 +158,9 @@
public synchronized void start() throws Exception {
super.start();
+ // set the java.rmi.server.hostname property to create well formed stub
+ System.setProperty("java.rmi.server.hostname", host);
+
// create the dynamic proxy
Class[] interfaceArray = new Class[]{ remoteInterface };
proxy = (Remote) Proxy.newProxyInstance(this.getClass().getClassLoader(), interfaceArray, this);
@@ -178,10 +203,26 @@
// WARNING: using POJO you bypass NMR and it's a direct POJO call
return method.invoke(pojo, args);
} else {
- // going through the NMR
- // TODO use a marshaler and send to the target endpoint
+ // construct XML structure corresponding to the RMI call and send into the NMR
+ // create in-out exchange
+ InOut exchange = getExchangeFactory().createInOutExchange();
+ // create the in message
+ NormalizedMessage in = exchange.createMessage();
+ // set the exchange in message
+ exchange.setInMessage(in);
+ // create a RMI call container
+ RmiCall rmiCall = new RmiCall();
+ rmiCall.setObject(proxy);
+ rmiCall.setMethod(method);
+ rmiCall.setArgs(args);
+ // populate the message content using the marshaler
+ marshaler.rmiCallToNMR(in, rmiCall);
+ // send the exchange to the delivery channel
+ // TODO use a send and hold on to the marshaler in a map with the exchange id
+ sendSync(exchange);
+ // use the marshaler to get back to the object
+ return marshaler.objectFromNMR(exchange.getOutMessage());
}
- return "test";
}
/*
Modified: servicemix/components/bindings/servicemix-rmi/trunk/src/main/java/org/apache/servicemix/rmi/RmiProviderEndpoint.java
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-rmi/trunk/src/main/java/org/apache/servicemix/rmi/RmiProviderEndpoint.java?rev=800527&r1=800526&r2=800527&view=diff
==============================================================================
--- servicemix/components/bindings/servicemix-rmi/trunk/src/main/java/org/apache/servicemix/rmi/RmiProviderEndpoint.java (original)
+++ servicemix/components/bindings/servicemix-rmi/trunk/src/main/java/org/apache/servicemix/rmi/RmiProviderEndpoint.java Mon Aug 3 20:22:24 2009
@@ -30,7 +30,9 @@
import javax.xml.transform.TransformerException;
import org.apache.servicemix.common.endpoints.ProviderEndpoint;
-import org.apache.servicemix.jbi.helper.MessageUtil;
+import org.apache.servicemix.rmi.marshaler.DefaultRmiMarshaler;
+import org.apache.servicemix.rmi.marshaler.RmiCall;
+import org.apache.servicemix.rmi.marshaler.RmiMarshalerSupport;
/**
* <p>
@@ -46,9 +48,74 @@
private int port = 1099; // target RMI port number
private String name; // target name into the RMI registry
+ private RmiMarshalerSupport marshaler = new DefaultRmiMarshaler(); // the RMI marshaler
+
private Registry registry = null; // the RMI registry
private Remote stub = null; // the remote stub
+ public String getHost() {
+ return this.host;
+ }
+
+ /**
+ * <p>
+ * This attribute defines the remote RMI server host name.
+ * </p>
+ *
+ * @param host the remote RMI server host name.
+ */
+ public void setHost(String host) {
+ this.host = host;
+ }
+
+ public int getPort() {
+ return this.port;
+ }
+
+ /**
+ * <p>
+ * This attribute defines the remote RMI server port number.
+ * </p>
+ * <i> The default value is <b>1099</b>.</i>
+ *
+ * @param port
+ */
+ public void setPort(int port) {
+ this.port = port;
+ }
+
+ public String getName() {
+ return this.name;
+ }
+
+ /**
+ * <p>
+ * This attribute defines the lookup name into the remote RMI registry.
+ * </p>
+ * <i> The default value is the <b>the endpoint name</b>.</i>
+ *
+ * @param name
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public RmiMarshalerSupport getMarshaler() {
+ return this.marshaler;
+ }
+
+ /**
+ * <p>
+ * This attribute defines the RMI marshaler to use.
+ * </p>
+ * <i> The default value is a instance of <b>DefaultRmiMarshaler</b>.
+ *
+ * @param marshaler
+ */
+ public void setMarshaler(RmiMarshalerSupport marshaler) {
+ this.marshaler = marshaler;
+ }
+
/*
* (non-Javadoc)
* @see org.apache.servicemix.common.endpoints.AbstractEndpoint#validate()
@@ -95,8 +162,8 @@
* javax.jbi.messaging.NormalizedMessage)
*/
@Override
- protected void processInOnly(MessageExchange exchange, NormalizedMessage inMsg) throws Exception {
- process(exchange, inMsg);
+ protected void processInOnly(MessageExchange exchange, NormalizedMessage in) throws Exception {
+ process(in);
}
/*
@@ -108,51 +175,34 @@
* javax.jbi.messaging.NormalizedMessage)
*/
@Override
- protected void processInOut(MessageExchange exchange, NormalizedMessage in, NormalizedMessage out)
- throws Exception {
- // we are reading the source of the NormalizedMessage multiple times
- // (else we receive a IOException: Stream closed)
- MessageUtil.enableContentRereadability(in);
-
- process(exchange, in);
+ protected void processInOut(MessageExchange exchange, NormalizedMessage in, NormalizedMessage out) throws Exception {
+ if (exchange.getStatus() == ExchangeStatus.ACTIVE) {
+ logger.debug("Exchange is ACTIVE");
+ return;
+ }
- // message was delivered, simply copy the in message with properties and
- // attachements to out
- MessageUtil.transfer(in, out);
+ // excute the RMI call and get response object
+ Object response = process(in);
+
+ // use the marshaler to marshal the response object into the out message
+ marshaler.objectToNMR(out, response);
}
-
+
/**
* <p>
- * Process the incoming exchange.
+ * Execute the RMI call and return the response object.
* </p>
*
- * @param exchange the message exchange.
- * @param in the in message.
- * @throws TransformerException on transformation errors.
- * @throws MessagingException on messaging errors,
+ * @param in the in <code>NormalizedMessage</code>.
+ * @return the response object.
+ * @throws Exception in case of RMI call or marshaler failure.
*/
- private void process(MessageExchange exchange, NormalizedMessage in) throws TransformerException, MessagingException {
- if (exchange.getStatus() == ExchangeStatus.ACTIVE) {
- return;
- }
+ private Object process(NormalizedMessage in) throws Exception {
+ // get the in message and construct the method with arguments
+ RmiCall rmiCall = marshaler.rmiCallFromNMR(in);
- // get the called method using the exchange operation
- QName operationName = exchange.getOperation();
- if (operationName == null) {
- // TODO try to define a default operation to use
- throw new MessagingException("The exchange operation is not set.");
- }
-
- // get the method call using the operation name
- try {
- // TODO correct the method detection (parameter types)
- Method method = stub.getClass().getMethod(operationName.toString(), null);
- Object result = method.invoke(stub, null);
- // TODO contruct the out normalized message using the object
- } catch (Exception e) {
- throw new MessagingException("RMI call failed.", e);
- }
+ // get the RMI call container to invocate
+ return rmiCall.getMethod().invoke(stub, rmiCall.getArgs());
}
-
}
Modified: servicemix/components/bindings/servicemix-rmi/trunk/src/main/java/org/apache/servicemix/rmi/marshaler/DefaultRmiMarshaler.java
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-rmi/trunk/src/main/java/org/apache/servicemix/rmi/marshaler/DefaultRmiMarshaler.java?rev=800527&r1=800526&r2=800527&view=diff
==============================================================================
--- servicemix/components/bindings/servicemix-rmi/trunk/src/main/java/org/apache/servicemix/rmi/marshaler/DefaultRmiMarshaler.java (original)
+++ servicemix/components/bindings/servicemix-rmi/trunk/src/main/java/org/apache/servicemix/rmi/marshaler/DefaultRmiMarshaler.java Mon Aug 3 20:22:24 2009
@@ -1,9 +1,67 @@
+/*
+ * 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.servicemix.rmi.marshaler;
+import java.lang.reflect.Method;
+
+import javax.jbi.messaging.MessagingException;
+import javax.jbi.messaging.NormalizedMessage;
+
/**
+ * <p>
+ * Default RMI marshaler.
+ * </p>
*
* @author jbonofre
*/
public class DefaultRmiMarshaler implements RmiMarshalerSupport {
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.servicemix.rmi.marshaler.RmiMarshalerSupport#toNMR(javax.jbi.messaging.NormalizedMessage, java.lang.Object, java.lang.reflect.Method, java.lang.Object[])
+ */
+ public void objectToNMR(NormalizedMessage message, Object object) throws MessagingException {
+
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.servicemix.rmi.marshaler.RmiMarshalerSupport#fromNMR(javax.jbi.messaging.NormalizedMessage)
+ */
+ public Object objectFromNMR(NormalizedMessage message) throws MessagingException {
+
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.servicemix.rmi.marshaler.RmiMarshalerSupport#rmiCallFromNMR(javax.jbi.messaging.NormalizedMessage)
+ */
+ public RmiCall rmiCallFromNMR(NormalizedMessage message) throws MessagingException {
+
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.servicemix.rmi.marshaler.RmiMarshalerSupport#rmiCallToNMR(javax.jbi.messaging.NormalizedMessage, org.apache.servicemix.rmi.marshaler.RmiCall)
+ */
+ public void rmiCallToNMR(NormalizedMessage message, RmiCall rmiCall) throws MessagingException {
+
+ }
}
Added: servicemix/components/bindings/servicemix-rmi/trunk/src/main/java/org/apache/servicemix/rmi/marshaler/RmiCall.java
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-rmi/trunk/src/main/java/org/apache/servicemix/rmi/marshaler/RmiCall.java?rev=800527&view=auto
==============================================================================
--- servicemix/components/bindings/servicemix-rmi/trunk/src/main/java/org/apache/servicemix/rmi/marshaler/RmiCall.java (added)
+++ servicemix/components/bindings/servicemix-rmi/trunk/src/main/java/org/apache/servicemix/rmi/marshaler/RmiCall.java Mon Aug 3 20:22:24 2009
@@ -0,0 +1,58 @@
+/*
+ * 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.servicemix.rmi.marshaler;
+
+import java.lang.reflect.Method;
+
+/**
+ * <p>
+ * Container for a RMI call.
+ * </p>
+ *
+ * @author jbonofre
+ */
+public class RmiCall {
+
+ private Object object;
+ private Method method;
+ private Object[] args;
+
+ public Object getObject() {
+ return object;
+ }
+
+ public void setObject(Object object) {
+ this.object = object;
+ }
+
+ public Method getMethod() {
+ return method;
+ }
+
+ public void setMethod(Method method) {
+ this.method = method;
+ }
+
+ public Object[] getArgs() {
+ return args;
+ }
+
+ public void setArgs(Object[] args) {
+ this.args = args;
+ }
+
+}
Propchange: servicemix/components/bindings/servicemix-rmi/trunk/src/main/java/org/apache/servicemix/rmi/marshaler/RmiCall.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: servicemix/components/bindings/servicemix-rmi/trunk/src/main/java/org/apache/servicemix/rmi/marshaler/RmiMarshalerSupport.java
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-rmi/trunk/src/main/java/org/apache/servicemix/rmi/marshaler/RmiMarshalerSupport.java?rev=800527&r1=800526&r2=800527&view=diff
==============================================================================
--- servicemix/components/bindings/servicemix-rmi/trunk/src/main/java/org/apache/servicemix/rmi/marshaler/RmiMarshalerSupport.java (original)
+++ servicemix/components/bindings/servicemix-rmi/trunk/src/main/java/org/apache/servicemix/rmi/marshaler/RmiMarshalerSupport.java Mon Aug 3 20:22:24 2009
@@ -16,6 +16,11 @@
*/
package org.apache.servicemix.rmi.marshaler;
+import java.lang.reflect.Method;
+
+import javax.jbi.messaging.MessagingException;
+import javax.jbi.messaging.NormalizedMessage;
+
/**
* <p>
* Interface describing the behaviors of a RMI marshaler.
@@ -24,5 +29,49 @@
* @author jbonofre
*/
public interface RmiMarshalerSupport {
+
+ /**
+ * <p>
+ * Marshal a RMI call into a XML format and push into the <code>NormalizedMessage</code> content.
+ * </p>
+ *
+ * @param message the normalized message.
+ * @param rmiCall the RMI call container.
+ * @throws MessagingException in case of marshaling failure.
+ */
+ public void rmiCallToNMR(NormalizedMessage message, RmiCall rmiCall) throws MessagingException;
+
+ /**
+ * <p>
+ * Unmarshal a RMI call contained into a <code>NormalizedMessage</code>.
+ * </p>
+ *
+ * @param message the normalized message.
+ * @return the RMI call container.
+ * @throws MessagingException in case of unmarshaling failure.
+ */
+ public RmiCall rmiCallFromNMR(NormalizedMessage message) throws MessagingException;
+
+ /**
+ * <p>
+ * Marshal an object and push into the <code>NormalizedMessage</code> content.
+ * </p>
+ *
+ * @param message the normalized message.
+ * @param object the object to marshal.
+ * @throws MessagingException in case of marshaling failure.
+ */
+ public void objectToNMR(NormalizedMessage message, Object object) throws MessagingException;
+
+ /**
+ * <p>
+ * Unmarshal the <code>NormalizedMessage<code> (mostly the out one) and create the return object.
+ * </p>
+ *
+ * @param message the normalized message.
+ * @return the unmarshaled object
+ * @throws MessagingException in case of unmarshaling failure.
+ */
+ public Object objectFromNMR(NormalizedMessage message) throws MessagingException;
}
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=800527&r1=800526&r2=800527&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 Mon Aug 3 20:22:24 2009
@@ -55,7 +55,7 @@
container.setRmiPort(1099);
container.setUseMBeanServer(true);
container.setCreateMBeanServer(true);
- container.setEmbedded(false);
+ container.setEmbedded(true);
container.init();
// deploy the RMI component
@@ -95,10 +95,17 @@
//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}RmiTestServiceByPassConsumer is not found in the JBI container.", container.getRegistry().getEndpoint(new QName("http://servicemix.apache.org/test", "RmiTestService"), "ByPassConsumer"));
}
+
+ public void testSimpleConsumerExchange() throws Exception {
+ java.rmi.registry.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);
+ }
/**
* <p>
- * Test an in
+ * Test the by pass consumer endpoint.
* </p>
*
* @throws Exception in case of exchange failure.
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=800527&r1=800526&r2=800527&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 Mon Aug 3 20:22:24 2009
@@ -20,12 +20,20 @@
<beans xmlns:rmi="http://servicemix.apache.org/rmi/1.0"
xmlns:test="http://servicemix.apache.org/test">
- <rmi:consumer service="test:RmiTestService" endpoint="SimpleConsumer" remoteInterface="org.apache.servicemix.rmi.Echo"/>
+ <rmi:consumer service="test:RmiTestService" endpoint="SimpleConsumer"
+ targetService="test:RmiTestService"
+ targetEndpoint="SimpleProvider"
+ remoteInterface="org.apache.servicemix.rmi.Echo"/>
<rmi:consumer service="test:RmiTestService" endpoint="ByPassConsumer" remoteInterface="org.apache.servicemix.rmi.Echo">
<rmi:pojo>
<bean class="org.apache.servicemix.rmi.EchoImpl"/>
</rmi:pojo>
</rmi:consumer>
+
+ <rmi:provider service="test:RmiTestServce" endpoint="SimpleProvider"
+ host="localhost"
+ port="1099"
+ name="ByPassConsumer"/>
</beans>
\ No newline at end of file