Index: topia2/src/java/org/codelutin/topia/service/TopiaServiceProvider.java diff -u topia2/src/java/org/codelutin/topia/service/TopiaServiceProvider.java:1.2 topia2/src/java/org/codelutin/topia/service/TopiaServiceProvider.java:1.3 --- topia2/src/java/org/codelutin/topia/service/TopiaServiceProvider.java:1.2 Tue Jul 24 14:02:00 2007 +++ topia2/src/java/org/codelutin/topia/service/TopiaServiceProvider.java Tue Jul 24 15:12:35 2007 @@ -36,9 +36,9 @@ * TopiaServiceProvider.java * * @author chatellier - * @version $Revision: 1.2 $ + * @version $Revision: 1.3 $ * - * Last update : $Date: 2007/07/24 14:02:00 $ By : $Author: chatellier $ + * Last update : $Date: 2007/07/24 15:12:35 $ By : $Author: chatellier $ */ public class TopiaServiceProvider { @@ -63,6 +63,11 @@ private Map mapDispatcherForProtocole; /** + * Map between port and protocol + */ + protected Map mapPortForProtocol; + + /** * Constructeur */ public TopiaServiceProvider() { @@ -70,9 +75,20 @@ mapInstanceForClass = new HashMap, TopiaApplicationService>(); mapClassForClass = new HashMap, Class>(); mapDispatcherForProtocole = new HashMap(); + mapPortForProtocol = new HashMap(); } /** + * Add a protocol port + * + * @param pr protocol + * @param port port + */ + public void setProtocolPort(Protocol pr, Integer port) { + mapPortForProtocol.put(pr, port); + } + + /** * * @param interfaze * @param clazz @@ -120,17 +136,32 @@ switch (protocole) { case XML_RPC: - server = new XMLRPCServer(); + if(mapPortForProtocol.get(Protocol.XML_RPC) != null) { + server = new XMLRPCServer(mapPortForProtocol.get(Protocol.XML_RPC)); + } + else { + server = new XMLRPCServer(); + } break; case RMI: try { - server = new RMIServer(); + if(mapPortForProtocol.get(Protocol.RMI) != null) { + server = new RMIServer(mapPortForProtocol.get(Protocol.RMI)); + } + else { + server = new RMIServer(); + } } catch (RemoteException e) { logger.debug("Can't start RMIServer.",e); } break; case SOAP: - server = new SOAPServer(); + if(mapPortForProtocol.get(Protocol.SOAP) != null) { + server = new SOAPServer(mapPortForProtocol.get(Protocol.SOAP)); + } + else { + server = new SOAPServer(); + } break; default: logger.debug("Unsupported protocole"); Index: topia2/src/java/org/codelutin/topia/service/TopiaApplicationServiceFactory.java diff -u topia2/src/java/org/codelutin/topia/service/TopiaApplicationServiceFactory.java:1.2 topia2/src/java/org/codelutin/topia/service/TopiaApplicationServiceFactory.java:1.3 --- topia2/src/java/org/codelutin/topia/service/TopiaApplicationServiceFactory.java:1.2 Tue Jul 24 14:02:00 2007 +++ topia2/src/java/org/codelutin/topia/service/TopiaApplicationServiceFactory.java Tue Jul 24 15:12:35 2007 @@ -52,9 +52,9 @@ * Sert aussi au serveur pour declarer des services * * @author chatellier - * @version $Revision: 1.2 $ + * @version $Revision: 1.3 $ * - * Last update : $Date: 2007/07/24 14:02:00 $ By : $Author: chatellier $ + * Last update : $Date: 2007/07/24 15:12:35 $ By : $Author: chatellier $ */ public class TopiaApplicationServiceFactory { @@ -64,9 +64,12 @@ /** Nom de la propriete de definition des services utilises */ static final String TOPIA_APPLICATION_SERVICE_BEGIN = "topia.application.service."; - /** Nom de la propriete de definition des service fournit */ + /** Nom de la propriete de definition des services fournit */ static final String TOPIA_APPLICATION_PROVIDE_BEGIN = "topia.application.provide."; + /** Nom de la propriete de definition des ports suivant les protocoles */ + static final String TOPIA_APPLICATION_SERVER_PORT_BEGIN = "topia.application.server.port."; + /** * Nom du dossier ou sont generer certains fichiers (doit etre dans le * classpath ) @@ -88,8 +91,8 @@ private static final Log log = LogFactory .getLog(TopiaApplicationServiceFactory.class); - private static TopiaContext defaultServiceContext; - + private static TopiaContext defaultServiceContext; + /** * Retourne la configuration. Charge le fichier s'il n'a pas deja ete * charge. @@ -138,51 +141,59 @@ if (key.toString().startsWith(TOPIA_APPLICATION_PROVIDE_BEGIN)) { // convertir l'URI pour recuperer les parametres - String serviceUrl = config.getProperty(key.toString()); - URI uriService = null; - try { - uriService = new URI(serviceUrl); - } catch (URISyntaxException e) { - log.error("URI Syntax isn't valid"); - } - String proto = uriService.getScheme(); - String host = uriService.getHost(); - String fragment = uriService.getFragment(); + String protos = config.getProperty(key.toString()); String serviceClassName = ((String) key).replace( TOPIA_APPLICATION_PROVIDE_BEGIN, ""); - Protocol protocole = null; - // instancier puis lancer le service - if (!proto.equalsIgnoreCase("local")) { - protocole = Protocol.valueOf(proto.replace('-', '_') - .toUpperCase()); + // lance pour chaque protocole + String[] tabProtos = protos.split(","); + + for (String proto : tabProtos) { + // instancier puis lancer le service + Protocol protocol = Protocol.valueOf(proto.trim().replace( + '-', '_').toUpperCase()); + + // read and set server port + if (config.get(TOPIA_APPLICATION_SERVER_PORT_BEGIN + proto) != null) { + Integer port = null; + try { + port = Integer.valueOf((String)config.get(TOPIA_APPLICATION_SERVER_PORT_BEGIN + proto)); + } + catch(NumberFormatException e) { + log.warn("Can't convert " + proto + " server port to integer",e); + } + mainDispatcher.setProtocolPort(protocol, port); + } + Class serviceInterface = null; Class serviceImplement = null; try { serviceInterface = Class.forName(serviceClassName); serviceImplement = Class.forName(serviceClassName + "Impl"); + + try { + Object newInstance = serviceImplement.newInstance(); + TopiaApplicationService service = (TopiaApplicationService) newInstance; + TopiaContext serviceContext = context + .beginTransaction(); + service.init(serviceContext); + addService(serviceInterface, service, protocol); + } catch (InstantiationException e) { + throw new TopiaException( + "Can't instanciate service class " + + serviceImplement); + } catch (IllegalAccessException e) { + throw new TopiaException( + "Can't access to service class " + + serviceImplement); + } + log.info("service " + serviceClassName + + " added for protocol " + proto); } catch (ClassNotFoundException e) { - log.error("Class not found for " + serviceClassName); - } - try { - Object newInstance = serviceImplement.newInstance(); - TopiaApplicationService service = (TopiaApplicationService) newInstance; - TopiaContext serviceContext = context - .beginTransaction(); - service.init(serviceContext); - addService(serviceInterface, service, protocole); - } catch (InstantiationException e) { - throw new TopiaException( - "Can't instanciate service class " - + serviceImplement); - } catch (IllegalAccessException e) { - throw new TopiaException( - "Can't access to service class " - + serviceImplement); + log.error("Class not found for " + serviceClassName, e); } } - log.info("service " + serviceClassName + " added"); } } } @@ -258,7 +269,8 @@ Class resultClass = (Class) Class .forName(fqClassImpl); serviceimpl = resultClass.newInstance(); - serviceimpl.init(defaultServiceContext.beginTransaction()); + serviceimpl.init(defaultServiceContext + .beginTransaction()); // mise en cache // sauf dans le cas ou il y a un "#new" a la fin de