Index: topia2/src/java/org/codelutin/topia/service/clients/package.html diff -u /dev/null topia2/src/java/org/codelutin/topia/service/clients/package.html:1.1 --- /dev/null Wed Apr 18 12:21:29 2007 +++ topia2/src/java/org/codelutin/topia/service/clients/package.html Wed Apr 18 12:21:24 2007 @@ -0,0 +1,19 @@ + + + +
+ + +Toutes les classes de ce package sont des proxys effectuant la + communication sur un protocole en particulier.
+ + + Index: topia2/src/java/org/codelutin/topia/service/clients/RMIProxy.java diff -u /dev/null topia2/src/java/org/codelutin/topia/service/clients/RMIProxy.java:1.1 --- /dev/null Wed Apr 18 12:21:29 2007 +++ topia2/src/java/org/codelutin/topia/service/clients/RMIProxy.java Wed Apr 18 12:21:24 2007 @@ -0,0 +1,121 @@ +/* *##% + * Copyright (C) 2006 Code Lutin + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + *##%*/ + +package org.codelutin.topia.service.clients; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.net.URI; +import java.rmi.Remote; +import java.rmi.registry.LocateRegistry; +import java.util.Arrays; + +import org.apache.commons.beanutils.MethodUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.codelutin.topia.TopiaException; +import org.codelutin.topia.service.TopiaApplicationService; +import org.codelutin.topia.service.TopiaProxy; + +/** + * RMIProxy.java + * + * @author chatellier + * @version $Revision: 1.1 $ + * + * Last update : $Date: 2007/04/18 12:21:24 $ By : $Author: chatellier $ + */ +public class RMIProxy implements TopiaProxy { + + /** Logger (common logging) */ + private static final Log logger = LogFactory.getLog(RMIProxy.class); + + /** location du service */ + protected String serviceLocation = null; + + /** La classe geree par le proxy */ + protected Class extends TopiaApplicationService> clazz; + + /** + * Constructeur + * + */ + public RMIProxy() { + + } + + /* + * (non-Javadoc) + * + * @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 { + + Object result = null; + + logger.debug("Invoke : " + clazz.getName() + "." + method.getName() + + "(" + Arrays.toString(args) + ")"); + + Remote rObject = LocateRegistry.getRegistry().lookup(clazz.getName()); + + logger.debug("Interfaces : " + + Arrays.toString(rObject.getClass().getInterfaces())); + logger.debug("Lookup for rmi service : rmi://" + this.serviceLocation + + "/" + clazz.getName() + " is " + rObject); + + logger.warn(Arrays.toString(rObject.getClass().getInterfaces())); + + try { + // l'objet Remote est en fait du type de la classe + // Remote generee sur le serveur + // on ne l'a pas ici + // invocation via MethodUtils de commons beanutils + result = MethodUtils.invokeMethod(rObject, method.getName(), args); + } catch (IllegalAccessException e) { + new TopiaException("Illegal Access to method (" + method.getName() + + ") in interface " + clazz.getName()); + } catch (InvocationTargetException e) { + new TopiaException("Can't call method (" + method.getName() + + ") in interface " + clazz.getName()); + } + + return result; + } + + /* + * (non-Javadoc) + * + * @see org.codelutin.topia.service.clients.TopiaProxy#setURI(java.net.URI) + */ + public void setURI(URI uri) { + // serviceLocation = uri.getRawSchemeSpecificPart(); + serviceLocation = uri.getAuthority(); // = host + port si specifie + } + + /* + * (non-Javadoc) + * + * @see org.codelutin.topia.service.clients.TopiaProxy#setClass(java.lang.Class) + */ + public void setClass(Class extends TopiaApplicationService> clazz) { + this.clazz = clazz; + } + +} Index: topia2/src/java/org/codelutin/topia/service/clients/SOAPProxy.java diff -u /dev/null topia2/src/java/org/codelutin/topia/service/clients/SOAPProxy.java:1.1 --- /dev/null Wed Apr 18 12:21:29 2007 +++ topia2/src/java/org/codelutin/topia/service/clients/SOAPProxy.java Wed Apr 18 12:21:24 2007 @@ -0,0 +1,90 @@ +/* *##% + * Copyright (C) 2006 Code Lutin + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + *##%*/ + +package org.codelutin.topia.service.clients; + +import java.lang.reflect.Method; +import java.net.URI; + +import org.apache.commons.beanutils.MethodUtils; +import org.codehaus.xfire.client.XFireProxyFactory; +import org.codehaus.xfire.service.Service; +import org.codehaus.xfire.service.binding.ObjectServiceFactory; +import org.codelutin.topia.service.TopiaApplicationService; +import org.codelutin.topia.service.TopiaProxy; + +/** + * SOAPProxy.java + * + * @author chatellier + * @version $Revision: 1.1 $ + * + * Last update : $Date: 2007/04/18 12:21:24 $ By : $Author: chatellier $ + */ +public class SOAPProxy implements TopiaProxy { + + /** Logger (common logging) */ + //private static final Log logger = LogFactory.getLog(RMIProxy.class); + + /** Classes geree par le proxy */ + protected Class extends TopiaApplicationService> clazz; + + /** URL du service */ + protected String serviceLocation; + + /* + * (non-Javadoc) + * + * @see org.codelutin.topia.service.TopiaProxy#setClass(java.lang.Class) + */ + public void setClass(Class extends TopiaApplicationService> clazz) { + this.clazz = clazz; + } + + /* + * (non-Javadoc) + * + * @see org.codelutin.topia.service.TopiaProxy#setURI(java.net.URI) + */ + public void setURI(URI uri) { + this.serviceLocation = "http:" + uri.getSchemeSpecificPart(); + } + + /* + * (non-Javadoc) + * + * @see java.lang.reflect.InvocationHandler#invoke(java.lang.Object, + * java.lang.reflect.Method, java.lang.Object[]) + */ + public Object invoke(Object obj, Method method, Object[] args) + throws Throwable { + Object result = null; + + // Create a service model for the client + ObjectServiceFactory serviceFactory = new ObjectServiceFactory(); + Service serviceModel = serviceFactory.create(clazz); + + // Create a client proxy + XFireProxyFactory proxyFactory = new XFireProxyFactory(); + Object xfproxy = proxyFactory.create(serviceModel, serviceLocation + "/" + clazz.getSimpleName()); + + result = MethodUtils.invokeMethod(xfproxy,method.getName(),args); + + return result; + } +} Index: topia2/src/java/org/codelutin/topia/service/clients/XMLRPCProxy.java diff -u /dev/null topia2/src/java/org/codelutin/topia/service/clients/XMLRPCProxy.java:1.1 --- /dev/null Wed Apr 18 12:21:29 2007 +++ topia2/src/java/org/codelutin/topia/service/clients/XMLRPCProxy.java Wed Apr 18 12:21:24 2007 @@ -0,0 +1,102 @@ +/* *##% + * Copyright (C) 2006 Code Lutin + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + *##%*/ + +package org.codelutin.topia.service.clients; + +import java.lang.reflect.Method; +import java.net.URI; +import java.net.URL; +import java.util.Arrays; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.xmlrpc.XmlRpcException; +import org.apache.xmlrpc.client.XmlRpcClient; +import org.apache.xmlrpc.client.XmlRpcClientConfigImpl; +import org.apache.xmlrpc.client.XmlRpcCommonsTransportFactory; +import org.codelutin.topia.service.TopiaApplicationService; +import org.codelutin.topia.service.TopiaProxy; + +/** + * XMLRPCProxy.java + * + * @author chatellier + * @version $Revision: 1.1 $ + * + * Last update : $Date: 2007/04/18 12:21:24 $ + * By : $Author: chatellier $ + */ +public class XMLRPCProxy implements TopiaProxy { + + /** Logger (common logging) */ + private static final Log logger = LogFactory.getLog(XMLRPCProxy.class); + + /** location du service */ + protected String serviceLocation = null; + + /** La classe geree par le proxy */ + protected Class extends TopiaApplicationService> clazz; + + /* (non-Javadoc) + * @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 { + + Object result = null; + + logger.debug("Invoke : " +clazz.getName() + "." + + method.getName() + "(" + Arrays.toString(args) + ")"); + + logger.debug("XML-RPC , Using uri = http:" + this.serviceLocation); + + //Le client XMLRPC de crispy est en version < 3 + + XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl(); + try { + config.setServerURL(new URL("http:" + this.serviceLocation)); + XmlRpcClient client = new XmlRpcClient(); + client.setTransportFactory(new XmlRpcCommonsTransportFactory(client)); + client.setConfig(config); + result = client.execute(clazz.getName() + "." + method.getName(), args); + } catch (java.net.MalformedURLException e) { + System.out.println("Caught MalformedURLException\n"); + e.printStackTrace(); + } catch (XmlRpcException e) { + System.out.println("Caught XmlRpcException\n"); + e.printStackTrace(); + } + + return result; + } + + /* (non-Javadoc) + * @see org.codelutin.topia.service.clients.TopiaProxy#setURI(java.net.URI) + */ + public void setURI(URI uri) { + serviceLocation = uri.getRawSchemeSpecificPart(); + } + + /* (non-Javadoc) + * @see org.codelutin.topia.service.clients.TopiaProxy#setClass(java.lang.Class) + */ + public void setClass(Class extends TopiaApplicationService> clazz) { + this.clazz = clazz; + } + +}