Author: chatellier Date: 2009-01-28 10:35:22 +0000 (Wed, 28 Jan 2009) New Revision: 1760 Modified: isis-fish/trunk/changelog.txt isis-fish/trunk/pom.xml isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/SimulatorServer.java isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/IsisFishServerSimulationLauncher.java isis-fish/trunk/src/main/resources/i18n/isis-fish-en_GB.properties isis-fish/trunk/src/main/resources/i18n/isis-fish-fr_FR.properties Log: Update XML-RPC to 3.1 Modified: isis-fish/trunk/changelog.txt =================================================================== --- isis-fish/trunk/changelog.txt 2009-01-27 15:21:13 UTC (rev 1759) +++ isis-fish/trunk/changelog.txt 2009-01-28 10:35:22 UTC (rev 1760) @@ -1,5 +1,6 @@ isis-fish (3.2.0.x) xxx + * Update XML-RPC launcher to xmlprc 3 * Add ssh simulation launcher * Add Jaxx UI for all interfaces * Remove SwixAT UI Modified: isis-fish/trunk/pom.xml =================================================================== --- isis-fish/trunk/pom.xml 2009-01-27 15:21:13 UTC (rev 1759) +++ isis-fish/trunk/pom.xml 2009-01-28 10:35:22 UTC (rev 1760) @@ -145,20 +145,28 @@ <scope>compile</scope> </dependency> + <!-- XML-RPC Client and server (don't try 3.1.1) --> <dependency> - <groupId>xmlrpc</groupId> - <artifactId>xmlrpc</artifactId> - <version>2.0</version> + <groupId>org.apache.xmlrpc</groupId> + <artifactId>xmlrpc-client</artifactId> + <version>3.1</version> <scope>compile</scope> </dependency> <dependency> - <groupId>commons-codec</groupId> - <artifactId>commons-codec</artifactId> - <version>1.3</version> + <groupId>org.apache.xmlrpc</groupId> + <artifactId>xmlrpc-server</artifactId> + <version>3.1</version> + <scope>compile</scope> + </dependency> + + <dependency> + <groupId>commons-httpclient</groupId> + <artifactId>commons-httpclient</artifactId> + <version>3.1</version> <scope>runtime</scope> </dependency> - + <!-- encore utilise pour les pre-scripts --> <dependency> <groupId>org.beanshell</groupId> Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/SimulatorServer.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/SimulatorServer.java 2009-01-27 15:21:13 UTC (rev 1759) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/SimulatorServer.java 2009-01-28 10:35:22 UTC (rev 1760) @@ -1,48 +1,46 @@ -/* - * *##% Copyright (C) 2002-2005 Code Lutin, Cédric Pineau, Benjamin Poussin - * - * 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. ##% - */ +/* *##% + * Copyright (C) 2007, 2009 + * Ifremer, Code Lutin, Cédric Pineau, Benjamin Poussin + * + * 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. + *##%*/ -/******************************************************************************* - * SimulatorServer.java - * - * Created: Thu Aug 22 2002 - * - * @author <poussin at codelutin.com> Copyright Code Lutin - * - * @version $Revision$ - * - * Mise a jour: $Date$ par : $Author$ - */ - package fr.ifremer.isisfish.simulator; import static org.codelutin.i18n.I18n._; import java.io.File; +import java.io.IOException; import java.util.Hashtable; +import java.util.Map; import java.util.Vector; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.xmlrpc.AuthenticatedXmlRpcHandler; -import org.apache.xmlrpc.WebServer; -import org.apache.xmlrpc.XmlRpc; +import org.apache.xmlrpc.XmlRpcException; +import org.apache.xmlrpc.XmlRpcHandler; +import org.apache.xmlrpc.XmlRpcRequest; +import org.apache.xmlrpc.XmlRpcRequestConfig; +import org.apache.xmlrpc.common.XmlRpcHttpRequestConfig; +import org.apache.xmlrpc.server.XmlRpcHandlerMapping; +import org.apache.xmlrpc.server.XmlRpcNoSuchHandlerException; +import org.apache.xmlrpc.server.XmlRpcServer; +import org.apache.xmlrpc.webserver.WebServer; import org.codelutin.util.FileUtil; +import fr.ifremer.isisfish.IsisFish; import fr.ifremer.isisfish.datastore.SimulationStorage; import fr.ifremer.isisfish.simulator.launcher.InProcessSimulatorLauncher; import fr.ifremer.isisfish.simulator.launcher.SimulatorLauncher; @@ -52,54 +50,99 @@ * de simulation. Il est ensuite possible de lui demander ou en est rendu * une simulation. * - * @author poussin + * Created: Thu Aug 22 2002 + * + * @author <poussin at codelutin.com> Copyright Code Lutin + * + * @version $Revision$ + * + * Mise a jour: $Date$ par : $Author$ */ -public class SimulatorServer implements AuthenticatedXmlRpcHandler { // SimulatorServer +public class SimulatorServer implements XmlRpcHandler, XmlRpcHandlerMapping { // SimulatorServer /** to use log facility, just put in your code: log.info(\"...\"); */ - static private Log log = LogFactory.getLog(SimulatorServer.class); + private static Log log = LogFactory.getLog(SimulatorServer.class); - // TODO dans SimulationControlServer ajouter une date de lancement de - // simulation. Si cette date est par exemple > 7 j on supprime - // automatiquement de simulationControls. Et on fait - // ce petit traitement a chaque connexion au serveur. - Hashtable simulationControls = new Hashtable(); + /** + * TODO dans SimulationControl ajouter une date de lancement de + * simulation. Si cette date est par exemple > 7 j on supprime + * automatiquement de simulationControls. Et on fait + * ce petit traitement a chaque connexion au serveur. + */ + protected Hashtable<String, SimulationControl> simulationControls = new Hashtable<String, SimulationControl>(); - public SimulatorServer() { + /* + * @see org.apache.xmlrpc.server.XmlRpcHandlerMapping#getHandler(java.lang.String) + */ + @Override + public XmlRpcHandler getHandler(String handler) + throws XmlRpcNoSuchHandlerException, XmlRpcException { + if (log.isDebugEnabled()) { + log.debug("Request handler : " + handler); + } + + return this; } - /** - * Method execute - * - * @param method les 2 noms de methodes possibles sont <b>simulate</b> pour - * commencer une nouvelle simulation, et <b>checkPoint</b> pour - * demander ou en est la simulation que l'utilisateur a demande. - * @param params si la methode est <b>simulate</b>, il faut donnee l'id, - * les parameters, le code ecmascript, les regles de gestions, les - * objets de la base a utilse. Si la methode est <b>checkPoint</b> - * il faut redonner le meme id que pour le lancement de la - * simulation. - * @param user le login a utiliser pour pouvoir faire une simulation - * @param password le mot de passe - * @return si la methode est <b>simulate</b> retourne un objet - * {@link SimulationStorage} Simulation sous forme XML. Si la - * methode est <b>checkPoint</b> retourne le nombre de mois simule. + /* + * @see org.apache.xmlrpc.XmlRpcHandler#execute(org.apache.xmlrpc.XmlRpcRequest) */ - public Object execute(String method, Vector params, String user, - String password) throws Exception { - log.info("L'utilisateur " + user + " demande " + method); + @Override + public Object execute(XmlRpcRequest request) throws XmlRpcException { - // TODO: verifier que l'utilisateur a le droit de faire des simulations + /* + * Parametres: + * method les 2 noms de methodes possibles sont <b>simulate</b> pour + * commencer une nouvelle simulation, et <b>checkPoint</b> pour + * demander ou en est la simulation que l'utilisateur a demande. + * param params si la methode est <b>simulate</b>, il faut donnee l'id, + * et le zip de la simulation. Si la methode est <b>checkPoint</b> + * il faut redonner le meme id que pour le lancement de la + * simulation. + * user le login a utiliser pour pouvoir faire une simulation + * password le mot de passe + * si la methode est <b>simulate</b> retourne un objet + * {@link Simulation} Simulation sous forme XML. Si la + * methode est <b>checkPoint</b> retourne le nombre de mois simule. + */ - if ("simulate".equals(method)) { - return new SimulatorServer().simulate(params); - } else if ("checkPoint".equals(method)) { - return checkPoint(params); - } else { - throw new NoSuchMethodException("Erreur: la methode " + method - + " n'existe pas"); + String user = null; + String password = null; + + // get basic connection info + XmlRpcRequestConfig config = request.getConfig(); + if (config instanceof XmlRpcHttpRequestConfig) { + XmlRpcHttpRequestConfig httpConfig = (XmlRpcHttpRequestConfig) config; + user = httpConfig.getBasicUserName(); + password = httpConfig.getBasicPassword(); } + + // TODO check authenticated users + + // get params + Vector params = new Vector(); + for (int index = 0; index < request.getParameterCount(); ++index) { + params.add(request.getParameter(index)); + } + + // launch requested method + String method = request.getMethodName(); + Object result = null; + try { + if ("simulate".equals(method)) { + result = new SimulatorServer().simulate(params); + } else if ("checkPoint".equals(method)) { + result = checkPoint(params); + } else { + throw new NoSuchMethodException("Erreur: la methode " + method + + " n'existe pas"); + } + } catch (Exception e) { + throw new XmlRpcException("Error during xmlrpc call", e); + } + + return result; } /** @@ -117,30 +160,33 @@ */ protected Object simulate(Vector params) throws Exception { // on creer une nouvelle simulation - if (params.size() < 6) + if (params.size() < 2) { throw new IllegalArgumentException("Mauvais nombre d'argument"); + } String id = (String) params.get(0); File zip = FileUtil.byteToFile((byte[]) params.get(1)); - + SimulationControl control = new SimulationControl(id); SimulationStorage simulation = null; - + simulationControls.put(id, control); try { SimulatorLauncher launcher = new InProcessSimulatorLauncher(); simulation = launcher.simulate(null, control, zip); zip = simulation.createZip(); - byte [] result = FileUtil.fileToByte(zip); - + byte[] result = FileUtil.fileToByte(zip); + return result; } catch (Exception eee) { log.warn(_("isisfish.error.during.simulation"), eee); throw eee; } finally { simulationControls.remove(id); - simulation.delete(false); + if (simulation != null) { + simulation.delete(false); + } } } @@ -148,44 +194,47 @@ * synchronized two SimulationControl (local and remote) * * @param params - * @return ? + * @return * @throws Exception */ synchronized protected Object checkPoint(Vector params) throws Exception { // on retourne a l'utilisateur on en est la simulation - if (params.size() < 1) + if (params.size() < 1) { throw new IllegalArgumentException("Mauvais nombre d'argument"); + } - Hashtable<String, Object> args = (Hashtable<String, Object>)params.get(0); - + Hashtable<String, Object> args = new Hashtable<String, Object>(); + args.putAll((Map<String, Object>) params.get(0)); + String id = (String) args.get("id"); SimulationControl callback = (SimulationControl) simulationControls .get(id); - if (callback == null) + if (callback == null) { throw new SimulatorServerBadIdException("Erreur: " + id + " n'est pas un identifiant de simulation"); + } callback.updateFromHashtable(args); - + return callback.getUpdateHashtable(); } -// synchronized protected Object stop(Vector params) throws Exception { -// if (params.size() < 1) -// throw new IllegalArgumentException("Mauvais nombre d'argument"); -// -// String id = (String) params.get(0); -// SimulationControl callback = (SimulationControl) simulationControls -// .get(id); -// if (callback == null) -// throw new SimulationException("Erreur: " + id -// + " n'est pas un identifiant de simulation"); -// -// callback.stopSimulation(); -// -// return ""; -// } + // synchronized protected Object stop(Vector params) throws Exception { + // if (params.size() < 1) + // throw new IllegalArgumentException("Mauvais nombre d'argument"); + // + // String id = (String) params.get(0); + // SimulationControl callback = (SimulationControl) simulationControls + // .get(id); + // if (callback == null) + // throw new SimulationException("Erreur: " + id + // + " n'est pas un identifiant de simulation"); + // + // callback.stopSimulation(); + // + // return ""; + // } /** * Method main permet de lancer un serveur de simulation sur une machine. @@ -193,8 +242,17 @@ * @param args */ public static void main(String[] args) { - System.err.println("Usage: SimulatorServer [port]"); + try { + IsisFish.init(); + } catch (Exception e) { + if (log.isErrorEnabled()) { + log.error("Can't ini IsisFish", e); + } + } + + System.out.println("Usage: SimulatorServer [port]"); + int p = 9090; if (args.length > 0) { @@ -205,18 +263,23 @@ } } - XmlRpc.setKeepAlive(true); + // FIXME KeepAlive in xmlrpc 3.x ? + //XmlRpc.setKeepAlive(true); try { WebServer webserver = new WebServer(p); + XmlRpcServer xmlRpcServer = webserver.getXmlRpcServer(); - webserver.addHandler("$default", new SimulatorServer()); + //xmlRpcServer.addHandler("$default", new SimulatorServer()); // 2.x + xmlRpcServer.setHandlerMapping(new SimulatorServer()); // 3.x - System.err.println("started web server on port " + p); - webserver.start(); - } catch (Exception x) { - System.err.println("Error creating web server: " + x); + System.out.println("Started web server on port " + p); + + } catch (IOException e) { + if (log.isErrorEnabled()) { + log.error("Error creating web server", e); + } } } Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/IsisFishServerSimulationLauncher.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/IsisFishServerSimulationLauncher.java 2009-01-27 15:21:13 UTC (rev 1759) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/IsisFishServerSimulationLauncher.java 2009-01-28 10:35:22 UTC (rev 1760) @@ -1,5 +1,5 @@ /* *##% - * Copyright (C) 2002-2008 Code Lutin, Benjamin Poussin + * Copyright (C) 2002-2009 Code Lutin, Benjamin Poussin * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -21,19 +21,23 @@ import static org.codelutin.i18n.I18n._; -import fr.ifremer.isisfish.IsisConfig; -import fr.ifremer.isisfish.IsisFish; -import fr.ifremer.isisfish.datastore.SimulationStorage; -import fr.ifremer.isisfish.simulator.SimulationControl; import java.io.File; +import java.net.URL; import java.rmi.RemoteException; import java.util.Hashtable; import java.util.Vector; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.xmlrpc.XmlRpcClient; +import org.apache.xmlrpc.client.XmlRpcClient; +import org.apache.xmlrpc.client.XmlRpcClientConfigImpl; +import org.apache.xmlrpc.client.XmlRpcCommonsTransportFactory; import org.codelutin.util.FileUtil; +import fr.ifremer.isisfish.IsisFish; +import fr.ifremer.isisfish.datastore.SimulationStorage; +import fr.ifremer.isisfish.simulator.SimulationControl; + /** * * @author poussin @@ -45,18 +49,24 @@ public class IsisFishServerSimulationLauncher implements SimulatorLauncher { /** to use log facility, just put in your code: log.info(\"...\"); */ - static private Log log = LogFactory.getLog(IsisFishServerSimulationLauncher.class); + private static Log log = LogFactory + .getLog(IsisFishServerSimulationLauncher.class); - public SimulationStorage simulate(SimulationService simulationService, SimulationControl control, File simulationZip) throws RemoteException { + public SimulationStorage simulate(SimulationService simulationService, + SimulationControl control, File simulationZip) + throws RemoteException { String simulationId = control.getId(); SimulationStorage simulation = null; try { - simulation = SimulationStorage.importAndRenameZip( - simulationZip, simulationId); + simulation = SimulationStorage.importAndRenameZip(simulationZip, + simulationId); simulation = remoteSimulate(control, simulation); } catch (Exception eee) { log.error(_("Can't do simulation %s", simulationId), eee); - simulation.getInformation().setException(eee); + // FIXME simulation allways null here + if(simulation != null) { + simulation.getInformation().setException(eee); + } } // on retourne directement le simulation storage passe en argument @@ -70,21 +80,21 @@ return 1; } - /** - * execute la simulation en remote - * - * @param control le controleur de simulation, peut-etre null si on ne - * souhaite pas controler la simulation - * @param simulation la simulation a faire - * - * @return le storage après simulation - * @throws Exception pour toute erreur - */ + /** + * execute la simulation en remote + * + * @param control le controleur de simulation, peut-etre null si on ne + * souhaite pas controler la simulation + * @param simulation la simulation a faire + * + * @return le storage après simulation + * @throws Exception pour toute erreur + */ public SimulationStorage remoteSimulate(SimulationControl control, SimulationStorage simulation) throws Exception { // export en zip du storage File zip = simulation.createZip(); - + if (control != null) { // creation du thread de surveillance de la simulation distante // qui sert a mettre a jour les valeurs de control @@ -97,13 +107,22 @@ Vector<Object> a = new Vector<Object>(); //fixme : on peut avori control à null ? a.add(control.getId()); - a.add(FileUtil.fileToByte(zip)); + a.add(FileUtil.fileToByte(zip)); // lancement de la simulation - XmlRpcClient c = new XmlRpcClient(IsisFish.config.getSimulatorServer()); - c.setBasicAuthentication(IsisFish.config.getSimulatorUsername(), - IsisFish.config.getSimulatorPassword()); - byte[] callResult = (byte[])c.execute("simulate", a); + //XmlRpcClient c = new XmlRpcClient(IsisFish.config.getSimulatorServer()); + //c.setBasicAuthentication(IsisFish.config.getSimulatorUsername(), + // IsisFish.config.getSimulatorPassword()); + + XmlRpcClientConfigImpl xmlrpcconfig = new XmlRpcClientConfigImpl(); + xmlrpcconfig.setServerURL(new URL(IsisFish.config.getSimulatorServer())); + xmlrpcconfig.setBasicUserName(IsisFish.config.getSimulatorUsername()); + xmlrpcconfig.setBasicPassword(IsisFish.config.getSimulatorPassword()); + XmlRpcClient client = new XmlRpcClient(); + client.setTransportFactory(new XmlRpcCommonsTransportFactory(client)); + client.setConfig(xmlrpcconfig); + + byte[] callResult = (byte[]) client.execute("simulate", a); // ecriture du resultat dans un fichier File tmpzip = FileUtil.byteToFile(callResult); @@ -164,16 +183,27 @@ public void updateControl(SimulationControl control) throws Exception { // essai l'ancienne etait en dur: "http://localhost:9090" - IsisConfig config = IsisFish.config; - XmlRpcClient c = new XmlRpcClient(config.getSimulatorServer()); - c.setBasicAuthentication(config.getSimulatorUsername(), config.getSimulatorPassword()); + + XmlRpcClientConfigImpl xmlrpcconfig = new XmlRpcClientConfigImpl(); + xmlrpcconfig.setServerURL(new URL(IsisFish.config.getSimulatorServer())); + xmlrpcconfig.setBasicUserName(IsisFish.config.getSimulatorUsername()); + xmlrpcconfig.setBasicPassword(IsisFish.config.getSimulatorPassword()); + XmlRpcClient client = new XmlRpcClient(); + client.setTransportFactory(new XmlRpcCommonsTransportFactory(client)); + client.setConfig(xmlrpcconfig); Vector a = new Vector(); a.add(control.getUpdateHashtable()); - Hashtable<String, Object> result = (Hashtable<String, Object>) c.execute("checkPoint", a); + Hashtable<String, Object> result = (Hashtable<String, Object>) client + .execute("checkPoint", a); // on remet de le temps normal, vu que la connexion a reussi control.updateFromHashtable(result); } } // SimulationCheckpointRemoteThread + + @Override + public String toString() { + return _("Remote IsisFish server"); + } } Modified: isis-fish/trunk/src/main/resources/i18n/isis-fish-en_GB.properties =================================================================== --- isis-fish/trunk/src/main/resources/i18n/isis-fish-en_GB.properties 2009-01-27 15:21:13 UTC (rev 1759) +++ isis-fish/trunk/src/main/resources/i18n/isis-fish-en_GB.properties 2009-01-28 10:35:22 UTC (rev 1760) @@ -44,7 +44,9 @@ Process\ template\ error= Region\ %s\ allready\ exist\ in\ repository.\ Can't\ import= Region\ %s\ already\ inited= +Remote\ IsisFish\ server= Remote\ control\ file\ doen't\ exists\ %s= +Remote\ control\ file\ doesn't\ exists\ %s= Rename\ data\ directory\ to\ %s= Show\ help= SimulationExecutor\ started\ with\ %s\ thread\ for\ %s= Modified: isis-fish/trunk/src/main/resources/i18n/isis-fish-fr_FR.properties =================================================================== --- isis-fish/trunk/src/main/resources/i18n/isis-fish-fr_FR.properties 2009-01-27 15:21:13 UTC (rev 1759) +++ isis-fish/trunk/src/main/resources/i18n/isis-fish-fr_FR.properties 2009-01-28 10:35:22 UTC (rev 1760) @@ -44,7 +44,9 @@ Process\ template\ error= Region\ %s\ allready\ exist\ in\ repository.\ Can't\ import= Region\ %s\ already\ inited=La r\u00E9gion %s a d\u00E9j\u00E0 \u00E9t\u00E9 initialis\u00E9e +Remote\ IsisFish\ server= Remote\ control\ file\ doen't\ exists\ %s= +Remote\ control\ file\ doesn't\ exists\ %s= Rename\ data\ directory\ to\ %s= Show\ help= SimulationExecutor\ started\ with\ %s\ thread\ for\ %s=