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/05 22:25:05 UTC

svn commit: r801400 - in /servicemix/components/bindings/servicemix-rmi/trunk/src/main/java/org/apache/servicemix/rmi: ./ marshaler/ util/

Author: jbonofre
Date: Wed Aug  5 20:25:04 2009
New Revision: 801400

URL: http://svn.apache.org/viewvc?rev=801400&view=rev
Log:
Refactore the WsdlHelper and the marshaler. Resume RmiProvider endpoint.

Added:
    servicemix/components/bindings/servicemix-rmi/trunk/src/main/java/org/apache/servicemix/rmi/RmiExchange.java   (contents, props changed)
      - copied, changed from r801357, servicemix/components/bindings/servicemix-rmi/trunk/src/main/java/org/apache/servicemix/rmi/marshaler/RmiCall.java
Removed:
    servicemix/components/bindings/servicemix-rmi/trunk/src/main/java/org/apache/servicemix/rmi/marshaler/RmiCall.java
Modified:
    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/main/java/org/apache/servicemix/rmi/util/WsdlHelper.java

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=801400&r1=801399&r2=801400&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 Wed Aug  5 20:25:04 2009
@@ -36,7 +36,6 @@
 
 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;
 import org.apache.servicemix.rmi.util.WsdlHelper;
 
@@ -154,7 +153,8 @@
 
         // generate the WSDL definition
         try {
-            definition = WsdlHelper.generateWsdlDocument(remoteInterface);
+            WsdlHelper wsdlHelper = new WsdlHelper(remoteInterface);
+            definition = wsdlHelper.createDocument();
             // TODO cleanup the definition (add correct name/target namespace) and make cleanup (binding) to make an abstract WSDL
             // use wsdl4j to create the WSDL description
             WSDLWriter writer = WSDLFactory.newInstance().newWSDLWriter();
@@ -233,17 +233,18 @@
             // create a RMI call container
             
             
-            RmiCall rmiCall = new RmiCall();
+            RmiExchange rmiCall = new RmiExchange();
             rmiCall.setObject(proxy);
             rmiCall.setMethod(method);
             rmiCall.setArgs(args);
             // populate the message content using the marshaler
-            marshaler.rmiCallToNMR(in, rmiCall);
+            //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);
+            //sendSync(exchange);
             // use the marshaler to get back to the object
-            return marshaler.objectFromNMR(exchange.getOutMessage());
+            //return marshaler.objectFromNMR(exchange.getOutMessage());
+            return null;
         }
     }
     

Copied: servicemix/components/bindings/servicemix-rmi/trunk/src/main/java/org/apache/servicemix/rmi/RmiExchange.java (from r801357, 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/RmiExchange.java?p2=servicemix/components/bindings/servicemix-rmi/trunk/src/main/java/org/apache/servicemix/rmi/RmiExchange.java&p1=servicemix/components/bindings/servicemix-rmi/trunk/src/main/java/org/apache/servicemix/rmi/marshaler/RmiCall.java&r1=801357&r2=801400&rev=801400&view=diff
==============================================================================
--- servicemix/components/bindings/servicemix-rmi/trunk/src/main/java/org/apache/servicemix/rmi/marshaler/RmiCall.java (original)
+++ servicemix/components/bindings/servicemix-rmi/trunk/src/main/java/org/apache/servicemix/rmi/RmiExchange.java Wed Aug  5 20:25:04 2009
@@ -14,18 +14,21 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.servicemix.rmi.marshaler;
+package org.apache.servicemix.rmi;
 
 import java.lang.reflect.Method;
+import java.rmi.Remote;
+
+import javax.jbi.messaging.MessageExchange;
 
 /**
  * <p>
- * Container for a RMI call.
+ * SMX representation of a RMI exchange.
  * </p>
  * 
  * @author jbonofre
  */
-public class RmiCall {
+public class RmiExchange {
     
     private Object object;
     private Method method;
@@ -54,5 +57,18 @@
     public void setArgs(Object[] args) {
         this.args = args;
     }
+    
+    /**
+     * <p>
+     * Invoke the RMI exchange on to the give stub.
+     * </p>
+     * 
+     * @param stub the Remote on which invoke the RMI exchange.
+     * @return the response object.
+     * @throws Exception in case of RMI invocation failure.
+     */
+    public Object invoke(Remote stub) throws Exception {
+        return method.invoke(stub, args);
+    }
 
 }

Propchange: servicemix/components/bindings/servicemix-rmi/trunk/src/main/java/org/apache/servicemix/rmi/RmiExchange.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

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=801400&r1=801399&r2=801400&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 Wed Aug  5 20:25:04 2009
@@ -32,7 +32,6 @@
 
 import org.apache.servicemix.common.endpoints.ProviderEndpoint;
 import org.apache.servicemix.rmi.marshaler.DefaultRmiMarshaler;
-import org.apache.servicemix.rmi.marshaler.RmiCall;
 import org.apache.servicemix.rmi.marshaler.RmiMarshalerSupport;
 import org.apache.servicemix.rmi.util.WsdlHelper;
 import org.springframework.core.io.Resource;
@@ -180,7 +179,11 @@
         } else {
             try {
                 // generate the wsdl using the remote interface
-                definition = WsdlHelper.generateWsdlDocument(remoteInterface);
+                WsdlHelper wsdlHelper = new WsdlHelper(remoteInterface);
+                // define the databinding to use in the marshaler
+                marshaler.setDataBinding(wsdlHelper.getDataBinding());
+                // create the WSDL document
+                definition = wsdlHelper.createDocument();
                 // TODO make some cleanups in the WSDL definition
                 // use wsdl4j to populate the endpoint description
                 WSDLWriter writer = WSDLFactory.newInstance().newWSDLWriter();
@@ -210,64 +213,27 @@
     
     /*
      * (non-Javadoc)
-     * @see
-     * org.apache.servicemix.common.endpoints.ProviderEndpoint#processInOnly
-     * (javax.jbi.messaging.MessageExchange,
-     * javax.jbi.messaging.NormalizedMessage)
+     * @see org.apache.servicemix.common.endpoints.ProviderEndpoint#process(javax.jbi.messaging.MessageExchange)
      */
-    @Override
-    protected void processInOnly(MessageExchange exchange, NormalizedMessage in) throws Exception {
-        process(in);
-    }
-
-    /*
-     * (non-Javadoc)
-     * @see
-     * org.apache.servicemix.common.endpoints.ProviderEndpoint#processInOut(
-     * javax.jbi.messaging.MessageExchange,
-     * javax.jbi.messaging.NormalizedMessage,
-     * javax.jbi.messaging.NormalizedMessage)
-     */
-    @Override
-    protected void processInOut(MessageExchange exchange, NormalizedMessage in, NormalizedMessage out) throws Exception {
+    public void process(MessageExchange exchange) throws Exception {
         if (exchange.getStatus() == ExchangeStatus.ACTIVE) {
-            logger.debug("Exchange is ACTIVE");
-            return;
-        }
-        
-        // find the operation
-        QName operation = exchange.getOperation();
-        if (operation == null) {
-            // the operation isn't contained in the message, try to get the first one in the WSDL
-            if (definition.getPortTypes().size() < 1) {
-                throw new JBIException("No port type found in the WSDL.");
+            // the exchange is active
+            NormalizedMessage in = exchange.getMessage("in");
+            if (in == null) {
+                throw new IllegalStateException("Exchange has not in message.");
             }
-            // TODO looking for the first operation in the WSDL port types
-           
+            // create a RMI exchange container
+            RmiExchange rmiExchange = new RmiExchange();
+            // populate the RMI exchange
+            marshaler.createRmiCall(in, rmiExchange);
+            // perform the RMI call
+            Object response = rmiExchange.invoke(stub);
+            // TODO handle RMI invocation exception using exchange.setError();
+            // marshal the response object into a normalized message
+            marshaler.handleRmiResponse(exchange, response);
+            // send the exchange into the NMR
+            send(exchange);
         }
-
-        // 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>
-     * Execute the RMI call and return the response object.
-     * </p>
-     * 
-     * @param in the in <code>NormalizedMessage</code>.
-     * @return the response object.
-     * @throws Exception in case of RMI call or marshaler failure.
-     */
-    private Object process(NormalizedMessage in) throws Exception {
-        // get the in message and construct the method with arguments
-        RmiCall rmiCall = marshaler.rmiCallFromNMR(in);
-        
-        // 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=801400&r1=801399&r2=801400&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 Wed Aug  5 20:25:04 2009
@@ -16,11 +16,16 @@
  */
 package org.apache.servicemix.rmi.marshaler;
 
-import java.lang.reflect.Method;
-
+import javax.jbi.messaging.ExchangeStatus;
+import javax.jbi.messaging.InOptionalOut;
+import javax.jbi.messaging.InOut;
+import javax.jbi.messaging.MessageExchange;
 import javax.jbi.messaging.MessagingException;
 import javax.jbi.messaging.NormalizedMessage;
 
+import org.apache.cxf.databinding.DataBinding;
+import org.apache.servicemix.rmi.RmiExchange;
+
 /**
  * <p>
  * Default RMI marshaler.
@@ -30,38 +35,43 @@
  */
 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 {
-        
-    }
+    private DataBinding dataBinding;
     
-    /*
-     * (non-Javadoc)
-     * @see org.apache.servicemix.rmi.marshaler.RmiMarshalerSupport#fromNMR(javax.jbi.messaging.NormalizedMessage)
-     */
-    public Object objectFromNMR(NormalizedMessage message) throws MessagingException {
-        
-        return null;
+    public void setDataBinding(DataBinding dataBinding) {
+        this.dataBinding = dataBinding;
     }
     
     /*
      * (non-Javadoc)
-     * @see org.apache.servicemix.rmi.marshaler.RmiMarshalerSupport#rmiCallFromNMR(javax.jbi.messaging.NormalizedMessage)
+     * @see org.apache.servicemix.rmi.marshaler.RmiMarshalerSupport#toNMR(javax.jbi.messaging.NormalizedMessage, java.lang.Object, java.lang.reflect.Method, java.lang.Object[])
      */
-    public RmiCall rmiCallFromNMR(NormalizedMessage message) throws MessagingException {
-        
-        return null;
+    public void handleRmiResponse(MessageExchange exchange, Object object) throws MessagingException {
+        if (exchange instanceof InOut) {
+            // it's an InOut exchange
+            // create the out message
+            NormalizedMessage out = exchange.createMessage();
+            // marshal the object using the data binding
+            //dataBinding.createWriter(Remote.class);
+            //out.setContent("");
+        } else if (exchange instanceof InOptionalOut) {
+            // it's an InOptionalOut, send the response only if the object is not null
+            if (object != null) {
+                
+            } else {
+                exchange.setStatus(ExchangeStatus.DONE);
+            }
+        } else {
+            // it's an InOnly exchange
+            exchange.setStatus(ExchangeStatus.DONE);
+        }
     }
     
     /*
      * (non-Javadoc)
-     * @see org.apache.servicemix.rmi.marshaler.RmiMarshalerSupport#rmiCallToNMR(javax.jbi.messaging.NormalizedMessage, org.apache.servicemix.rmi.marshaler.RmiCall)
+     * @see org.apache.servicemix.rmi.marshaler.RmiMarshalerSupport#rmiCallFromNMR(javax.jbi.messaging.NormalizedMessage)
      */
-    public void rmiCallToNMR(NormalizedMessage message, RmiCall rmiCall) throws MessagingException {
-        
+    public void createRmiCall(NormalizedMessage in, RmiExchange rmiCall) throws MessagingException {
+        // TODO get the operation in the exchange and construct the RMI method call using object in the in message
     }
 
 }

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=801400&r1=801399&r2=801400&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 Wed Aug  5 20:25:04 2009
@@ -16,11 +16,13 @@
  */
 package org.apache.servicemix.rmi.marshaler;
 
-import java.lang.reflect.Method;
-
+import javax.jbi.messaging.MessageExchange;
 import javax.jbi.messaging.MessagingException;
 import javax.jbi.messaging.NormalizedMessage;
 
+import org.apache.cxf.databinding.DataBinding;
+import org.apache.servicemix.rmi.RmiExchange;
+
 /**
  * <p>
  * Interface describing the behaviors of a RMI marshaler.
@@ -32,46 +34,33 @@
     
     /**
      * <p>
-     * Marshal a RMI call into a XML format and push into the <code>NormalizedMessage</code> content.
+     * Define the CXF data binding to use.
      * </p>
      * 
-     * @param message the normalized message.
-     * @param rmiCall the RMI call container.
-     * @throws MessagingException in case of marshaling failure.
+     * @param dataBinding
      */
-    public void rmiCallToNMR(NormalizedMessage message, RmiCall rmiCall) throws MessagingException;
+    public void setDataBinding(DataBinding dataBinding);
     
     /**
      * <p>
      * Unmarshal a RMI call contained into a <code>NormalizedMessage</code>.
      * </p>
      * 
-     * @param message the normalized message.
-     * @return the RMI call container.
+     * @param in the in normalized message.
+     * @param rmiCall the RMI call to populate.
      * @throws MessagingException in case of unmarshaling failure.
      */
-    public RmiCall rmiCallFromNMR(NormalizedMessage message) throws MessagingException;
+    public void createRmiCall(NormalizedMessage in, RmiExchange rmiCall) 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.
+     * @param exchange the message exchange.
+     * @param object the response object.
      * @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;
+    public void handleRmiResponse(MessageExchange exchange, Object object) throws MessagingException;
 
 }

Modified: servicemix/components/bindings/servicemix-rmi/trunk/src/main/java/org/apache/servicemix/rmi/util/WsdlHelper.java
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-rmi/trunk/src/main/java/org/apache/servicemix/rmi/util/WsdlHelper.java?rev=801400&r1=801399&r2=801400&view=diff
==============================================================================
--- servicemix/components/bindings/servicemix-rmi/trunk/src/main/java/org/apache/servicemix/rmi/util/WsdlHelper.java (original)
+++ servicemix/components/bindings/servicemix-rmi/trunk/src/main/java/org/apache/servicemix/rmi/util/WsdlHelper.java Wed Aug  5 20:25:04 2009
@@ -21,6 +21,7 @@
 
 import org.apache.cxf.BusFactory;
 import org.apache.cxf.aegis.databinding.AegisDatabinding;
+import org.apache.cxf.databinding.DataBinding;
 import org.apache.cxf.service.model.ServiceInfo;
 import org.apache.cxf.simple.SimpleServiceBuilder;
 import org.apache.cxf.wsdl11.ServiceWSDLBuilder;
@@ -34,6 +35,21 @@
  */
 public class WsdlHelper {
     
+    private Class bean;
+    private SimpleServiceBuilder serviceBuilder;
+    private DataBinding dataBinding = new AegisDatabinding();
+    
+    public WsdlHelper(Class bean) {
+        this.bean = bean;
+        serviceBuilder = new SimpleServiceBuilder();
+        serviceBuilder.setServiceClass(bean);
+        serviceBuilder.setDataBinding(dataBinding);
+    }
+    
+    public DataBinding getDataBinding() {
+        return this.dataBinding;
+    }
+    
     /**
      * <p>
      * Generate a WSDL definition based on the given class using CXF.
@@ -42,10 +58,7 @@
      * @param bean the base class to generate the WSDL.
      * @return the WSDL definition.
      */
-    public final static Definition generateWsdlDocument(Class bean) throws WSDLException {
-        SimpleServiceBuilder serviceBuilder = new SimpleServiceBuilder();
-        serviceBuilder.setServiceClass(bean);
-        serviceBuilder.setDataBinding(new AegisDatabinding());
+    public Definition createDocument() throws WSDLException {
         ServiceInfo serviceInfo = serviceBuilder.createService();
         ServiceWSDLBuilder wsdlBuilder = new ServiceWSDLBuilder(BusFactory.getDefaultBus(), serviceInfo);
         return wsdlBuilder.build();