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/04 22:20:39 UTC

svn commit: r800946 - in /servicemix/components/bindings/servicemix-rmi/trunk/src: main/java/org/apache/servicemix/rmi/ main/java/org/apache/servicemix/rmi/util/ test/java/org/apache/servicemix/rmi/ test/resources/xbean/

Author: jbonofre
Date: Tue Aug  4 20:20:38 2009
New Revision: 800946

URL: http://svn.apache.org/viewvc?rev=800946&view=rev
Log:
Refactoring on the unit tests.
Add helper class to WSDL generation.

Added:
    servicemix/components/bindings/servicemix-rmi/trunk/src/main/java/org/apache/servicemix/rmi/util/
    servicemix/components/bindings/servicemix-rmi/trunk/src/main/java/org/apache/servicemix/rmi/util/WsdlHelper.java   (with props)
    servicemix/components/bindings/servicemix-rmi/trunk/src/test/resources/xbean/xbean-consumer.xml   (contents, props changed)
      - copied, changed from r800874, servicemix/components/bindings/servicemix-rmi/trunk/src/test/resources/xbean/xbean.xml
    servicemix/components/bindings/servicemix-rmi/trunk/src/test/resources/xbean/xbean-provider.xml   (with props)
Removed:
    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/RmiConsumerEndpoint.java
    servicemix/components/bindings/servicemix-rmi/trunk/src/main/java/org/apache/servicemix/rmi/RmiProviderEndpoint.java
    servicemix/components/bindings/servicemix-rmi/trunk/src/test/java/org/apache/servicemix/rmi/RmiXBeanTest.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=800946&r1=800945&r2=800946&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 Tue Aug  4 20:20:38 2009
@@ -32,16 +32,13 @@
 import javax.jbi.messaging.NormalizedMessage;
 import javax.wsdl.factory.WSDLFactory;
 import javax.wsdl.xml.WSDLWriter;
+import javax.xml.namespace.QName;
 
-import org.apache.cxf.BusFactory;
-import org.apache.cxf.aegis.databinding.AegisDatabinding;
-import org.apache.cxf.service.model.ServiceInfo;
-import org.apache.cxf.simple.SimpleServiceBuilder;
-import org.apache.cxf.wsdl11.ServiceWSDLBuilder;
 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;
 
 /**
  * <p>
@@ -155,14 +152,9 @@
             name = this.getEndpoint();
         }
 
-        // use CXF to generate the WSDL definition
-        SimpleServiceBuilder serviceBuilder = new SimpleServiceBuilder();
-        serviceBuilder.setServiceClass(remoteInterface);
-        serviceBuilder.setDataBinding(new AegisDatabinding());
-        ServiceInfo serviceInfo = serviceBuilder.createService();
-        ServiceWSDLBuilder wsdlBuilder = new ServiceWSDLBuilder(BusFactory.getDefaultBus(), serviceInfo);
+        // generate the WSDL definition
         try {
-            definition = wsdlBuilder.build();
+            definition = WsdlHelper.generateWsdlDocument(remoteInterface);
             // 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();
@@ -229,11 +221,18 @@
             // construct XML structure corresponding to the RMI call and send into the NMR
             // create in-out exchange
             InOut exchange = getExchangeFactory().createInOutExchange();
+            // set the exchange operation name to the called method
+            exchange.setOperation(new QName("", ""));
             // create the in message
             NormalizedMessage in = exchange.createMessage();
             // set the exchange in message
             exchange.setInMessage(in);
+            
+            // check if the method match a WSDL an operation
+            
             // create a RMI call container
+            
+            
             RmiCall rmiCall = new RmiCall();
             rmiCall.setObject(proxy);
             rmiCall.setMethod(method);

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=800946&r1=800945&r2=800946&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 Tue Aug  4 20:20:38 2009
@@ -16,23 +16,28 @@
  */
 package org.apache.servicemix.rmi;
 
-import java.lang.reflect.Method;
 import java.rmi.Remote;
 import java.rmi.registry.LocateRegistry;
 import java.rmi.registry.Registry;
 
+import javax.jbi.JBIException;
 import javax.jbi.management.DeploymentException;
 import javax.jbi.messaging.ExchangeStatus;
 import javax.jbi.messaging.MessageExchange;
-import javax.jbi.messaging.MessagingException;
 import javax.jbi.messaging.NormalizedMessage;
+import javax.wsdl.PortType;
+import javax.wsdl.factory.WSDLFactory;
+import javax.wsdl.xml.WSDLWriter;
 import javax.xml.namespace.QName;
-import javax.xml.transform.TransformerException;
 
 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;
+
+import sun.text.CompactShortArray.Iterator;
 
 /**
  * <p>
@@ -47,6 +52,8 @@
     private String host; // target RMI host name
     private int port = 1099; // target RMI port number
     private String name; // target name into the RMI registry
+    private Class remoteInterface; // the remote interface
+    private Resource wsdl; // the used WSDL
     
     private RmiMarshalerSupport marshaler = new DefaultRmiMarshaler(); // the RMI marshaler
     
@@ -100,6 +107,36 @@
         this.name = name;
     }
     
+    public Class getRemoteInterface() {
+        return this.remoteInterface;
+    }
+    
+    /**
+     * <p>
+     * The attribute defines the remote interface of the RMI stub.
+     * </p>
+     * 
+     * @param remoteInterface the remote interface to use.
+     */
+    public void setRemoteInterface(Class remoteInterface) {
+        this.remoteInterface = remoteInterface;
+    }
+    
+    public Resource getWsdl() {
+        return this.wsdl;
+    }
+    
+    /**
+     * <p>
+     * This attribute defines the WSDL used by the endpoint to generate message content.
+     * </p>
+     * 
+     * @param wsdl the WSDL to use.
+     */
+    public void setWsdl(Resource wsdl) {
+        this.wsdl = wsdl;
+    }
+    
     public RmiMarshalerSupport getMarshaler() {
         return this.marshaler;
     }
@@ -128,20 +165,37 @@
             throw new DeploymentException("The RMI host is mandatory.");
         }
         
+        if (remoteInterface == null) {
+            throw new DeploymentException("The remoteInterface is mandatory.");
+        }
+        
         if (name == null || name.trim().length() < 1) {
             // the user hasn't provide the RMI name, use the endpoint one
             name = this.getEndpoint();
         }
         
-        // get the RMI registry, if required
-        if (registry == null) {
+        if (wsdl != null) {
+            // the user provides the WSDL, load it into endpoint definition/description
+            
+        } else {
             try {
-                registry = LocateRegistry.getRegistry(host, port);
+                // generate the wsdl using the remote interface
+                definition = WsdlHelper.generateWsdlDocument(remoteInterface);
+                // TODO make some cleanups in the WSDL definition
+                // use wsdl4j to populate the endpoint description
+                WSDLWriter writer = WSDLFactory.newInstance().newWSDLWriter();
+                description = writer.getDocument(definition);
             } catch (Exception e) {
-                throw new DeploymentException("Can't connect using RMI on " + host + ":" + port, e);
+                throw new DeploymentException("Can't generate the WSDL.", e);
             }
         }
         
+        try {
+            registry = LocateRegistry.getRegistry(host, port);
+        } catch (Exception e) {
+            throw new DeploymentException("Can't connect using RMI on " + host + ":" + port, e);
+        }
+        
         // lookup the stub
         try {
             stub = registry.lookup(name);
@@ -180,6 +234,17 @@
             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.");
+            }
+            // TODO looking for the first operation in the WSDL port types
+           
+        }
 
         // excute the RMI call and get response object
         Object response = process(in);

Added: 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=800946&view=auto
==============================================================================
--- servicemix/components/bindings/servicemix-rmi/trunk/src/main/java/org/apache/servicemix/rmi/util/WsdlHelper.java (added)
+++ servicemix/components/bindings/servicemix-rmi/trunk/src/main/java/org/apache/servicemix/rmi/util/WsdlHelper.java Tue Aug  4 20:20:38 2009
@@ -0,0 +1,54 @@
+/*
+ * 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.util;
+
+import javax.wsdl.Definition;
+import javax.wsdl.WSDLException;
+
+import org.apache.cxf.BusFactory;
+import org.apache.cxf.aegis.databinding.AegisDatabinding;
+import org.apache.cxf.service.model.ServiceInfo;
+import org.apache.cxf.simple.SimpleServiceBuilder;
+import org.apache.cxf.wsdl11.ServiceWSDLBuilder;
+
+/**
+ * <p>
+ * A helper around WSDL generation.
+ * </p>
+ * 
+ * @author jbonofre
+ */
+public class WsdlHelper {
+    
+    /**
+     * <p>
+     * Generate a WSDL definition based on the given class using CXF.
+     * </p>
+     * 
+     * @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());
+        ServiceInfo serviceInfo = serviceBuilder.createService();
+        ServiceWSDLBuilder wsdlBuilder = new ServiceWSDLBuilder(BusFactory.getDefaultBus(), serviceInfo);
+        return wsdlBuilder.build();
+    }
+
+}

Propchange: servicemix/components/bindings/servicemix-rmi/trunk/src/main/java/org/apache/servicemix/rmi/util/WsdlHelper.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=800946&r1=800945&r2=800946&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 Tue Aug  4 20:20:38 2009
@@ -39,6 +39,7 @@
     private final static transient Log LOG = LogFactory.getLog(RmiXBeanTest.class);
     
     protected JBIContainer container;
+    protected RmiComponent component;
     
     /*
      * (non-Javadoc)
@@ -54,15 +55,25 @@
         container.init();
         
         // deploy the RMI component
-        RmiComponent component = new RmiComponent();
+        component = new RmiComponent();
         // activate the RMI component into the JBI container
         container.activateComponent(component, "RMIComponent");
         
         // start the JBI container
         container.start();
-        
+    }
+    
+    /**
+     * <p>
+     * Deploy a target xbean into the JBI container.
+     * </p>
+     * 
+     * @param xbean the xbean.xml file path.
+     * @throws Exception in case of xbean deployment error.
+     */
+    private void deployXBean(String xbean) throws Exception {    
         // deploy the SU based on the xbean.xml
-        File path = new ClassPathResource("xbean/xbean.xml").getFile();
+        File path = new ClassPathResource(xbean).getFile();
         path = path.getParentFile();
         component.getServiceUnitManager().deploy("xbean", path.getAbsolutePath());
         component.getServiceUnitManager().init("xbean", path.getAbsolutePath());
@@ -92,6 +103,7 @@
     }
     
     public void testSimpleConsumerExchange() throws Exception {
+        this.deployXBean("xbean/xbean-consumer.xml");
         java.rmi.registry.Registry registry = LocateRegistry.getRegistry("localhost", 1099);
         Echo stub = (Echo) registry.lookup("SimpleConsumer");
         String echo = stub.echo("test");
@@ -106,10 +118,22 @@
      * @throws Exception in case of exchange failure.
      */
     public void testByPassConsumerExchange() throws Exception {
+        this.deployXBean("xbean/xbean-consumer.xml");
         java.rmi.registry.Registry registry = LocateRegistry.getRegistry("localhost", 1099);
         Echo stub = (Echo) registry.lookup("ByPassConsumer");
         String echo = stub.echo("test");
         assertEquals("Bad response from the RMI endpoint", "test", echo);
     }
+    
+    /**
+     * <p>
+     * Test the simple provider endpoint.
+     * </p>
+     * 
+     * @throws Exception in case of exchange failure.
+     */
+    public void testSimpleProviderExchange() throws Exception {
+        this.deployXBean("xbean/xbean-provider.xml");
+    }
 
 }

Copied: servicemix/components/bindings/servicemix-rmi/trunk/src/test/resources/xbean/xbean-consumer.xml (from r800874, 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-consumer.xml?p2=servicemix/components/bindings/servicemix-rmi/trunk/src/test/resources/xbean/xbean-consumer.xml&p1=servicemix/components/bindings/servicemix-rmi/trunk/src/test/resources/xbean/xbean.xml&r1=800874&r2=800946&rev=800946&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-consumer.xml Tue Aug  4 20:20:38 2009
@@ -30,10 +30,5 @@
             <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

Propchange: servicemix/components/bindings/servicemix-rmi/trunk/src/test/resources/xbean/xbean-consumer.xml
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: servicemix/components/bindings/servicemix-rmi/trunk/src/test/resources/xbean/xbean-provider.xml
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-rmi/trunk/src/test/resources/xbean/xbean-provider.xml?rev=800946&view=auto
==============================================================================
--- servicemix/components/bindings/servicemix-rmi/trunk/src/test/resources/xbean/xbean-provider.xml (added)
+++ servicemix/components/bindings/servicemix-rmi/trunk/src/test/resources/xbean/xbean-provider.xml Tue Aug  4 20:20:38 2009
@@ -0,0 +1,29 @@
+<?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:rmi="http://servicemix.apache.org/rmi/1.0"
+       xmlns:test="http://servicemix.apache.org/test">
+    
+    <rmi:provider service="test:RmiTestServce" endpoint="SimpleProvider"
+        host="localhost"
+        port="1099"
+        name="ByPassConsumer"
+        remoteInterface="org.apache.servicemix.rmi.Echo"/>
+       
+</beans>
\ No newline at end of file

Propchange: servicemix/components/bindings/servicemix-rmi/trunk/src/test/resources/xbean/xbean-provider.xml
------------------------------------------------------------------------------
    svn:mime-type = text/plain