This is an automated email from the git hooks/post-receive script. New commit to branch feature/1176 in repository lima. See http://git.chorem.org/lima.git commit 2d3c9fc1cd44972b0dd379f3fa6e8de4de6bf5bf Author: dcosse <cosse@codelutin.com> Date: Mon Apr 27 16:41:02 2015 +0200 refs #1210 allow to configure defferent address for Ejb than Http --- .../chorem/lima/business/api/OptionsService.java | 3 +- .../chorem/lima/business/LimaBusinessConfig.java | 47 +++++++++++++++------- .../lima/business/ejb/OptionsServiceImpl.java | 4 +- .../resources/i18n/lima-business_en_GB.properties | 1 + .../resources/i18n/lima-business_fr_FR.properties | 1 + lima-server/README.txt | 18 ++++++--- .../org/chorem/lima/server/HttpServerService.java | 11 +++-- .../java/org/chorem/lima/server/LimaServer.java | 43 ++++++++++++++++++-- .../org/chorem/lima/server/LimaServerConfig.java | 9 ----- .../java/org/chorem/lima/ui/MainViewHandler.java | 3 +- 10 files changed, 100 insertions(+), 40 deletions(-) diff --git a/lima-business-api/src/main/java/org/chorem/lima/business/api/OptionsService.java b/lima-business-api/src/main/java/org/chorem/lima/business/api/OptionsService.java index f64a540..6598454 100644 --- a/lima-business-api/src/main/java/org/chorem/lima/business/api/OptionsService.java +++ b/lima-business-api/src/main/java/org/chorem/lima/business/api/OptionsService.java @@ -23,7 +23,6 @@ package org.chorem.lima.business.api; import org.chorem.lima.business.config.LimaConfigOptionDef; import org.chorem.lima.business.utils.BigDecimalToString; -import org.nuiton.config.ConfigOptionDef; /** * Service de report des certaines configurations du swing dans business @@ -54,7 +53,7 @@ public interface OptionsService extends BigDecimalToString.Config { LimaConfigOptionDef getThousandSeparatorOption(); - String getLimaHostAddress(); + String getLimaHttpHostAddress(); int getLimaHttpPort(); diff --git a/lima-business/src/main/java/org/chorem/lima/business/LimaBusinessConfig.java b/lima-business/src/main/java/org/chorem/lima/business/LimaBusinessConfig.java index 9af6496..5b01b0f 100644 --- a/lima-business/src/main/java/org/chorem/lima/business/LimaBusinessConfig.java +++ b/lima-business/src/main/java/org/chorem/lima/business/LimaBusinessConfig.java @@ -26,7 +26,6 @@ import com.google.common.collect.Maps; import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.openejb.client.RemoteInitialContextFactory; import org.chorem.lima.LimaTechnicalException; import org.chorem.lima.business.accountingrules.FranceAccountingRules; import org.chorem.lima.business.config.LimaConfigOptionDef; @@ -37,7 +36,6 @@ import org.nuiton.config.ArgumentsParserException; import org.nuiton.topia.flyway.TopiaFlywayService; import org.nuiton.topia.persistence.TopiaConfigurationConstants; -import javax.naming.Context; import java.io.File; import java.util.Map; import java.util.Properties; @@ -235,7 +233,7 @@ public class LimaBusinessConfig { public void setScale(String locale) { config.setOption(BusinessConfigOption.SCALE.key, locale); - config.saveForUser(); + saveConfig(); } public boolean getCurrency() { @@ -244,7 +242,7 @@ public class LimaBusinessConfig { public void setCurrency(String locale) { config.setOption(BusinessConfigOption.CURRENCY.key, locale); - config.saveForUser(); + saveConfig(); } public char getDecimalSeparator() { @@ -254,7 +252,7 @@ public class LimaBusinessConfig { public void setDecimalSeparator(String locale) { config.setOption(BusinessConfigOption.DECIMAL_SEPARATOR.key, locale); - config.saveForUser(); + saveConfig(); } public char getThousandSeparator() { @@ -263,17 +261,17 @@ public class LimaBusinessConfig { public void setThousandSeparator(String locale) { config.setOption(BusinessConfigOption.THOUSAND_SEPARATOR.key, locale); - config.saveForUser(); + saveConfig(); } - public String getHostAddress() { - String host = config.getOption(BusinessConfigOption.HOST_ADDRESS.getKey()); + public String getHostEJBAddress() { + String host = config.getOption(BusinessConfigOption.HOST_EJB_ADDRESS.getKey()); return host; } - public void setHostAddress(String serverAddress) { - config.setOption(BusinessConfigOption.HOST_ADDRESS.key, serverAddress); - config.saveForUser(); + public void setHostEJBAddress(String serverAddress) { + config.setOption(BusinessConfigOption.HOST_EJB_ADDRESS.key, serverAddress); + saveConfig(); } public int getHostEjbPort() { @@ -281,6 +279,15 @@ public class LimaBusinessConfig { return port; } + public String getHostHttpAddress() { + String port = config.getOption(BusinessConfigOption.HOST_HTTP_ADDRESS.getKey()); + return port; + } + + public void setHostHttpAddress(String address) { + config.setOption(BusinessConfigOption.HOST_HTTP_ADDRESS.key, address); + } + public int getHostHttpPort() { int port = config.getOptionAsInt(BusinessConfigOption.HOST_HTTP_PORT.getKey()); return port; @@ -288,7 +295,16 @@ public class LimaBusinessConfig { public void setHttpPort(int port) { config.setOption(BusinessConfigOption.HOST_HTTP_PORT.key, String.valueOf(port)); - config.saveForUser(); + saveConfig(); + } + + protected void saveConfig() { + config.saveForUser( + BusinessConfigOption.HOST_EJB_ADDRESS.getKey(), + BusinessConfigOption.HOST_EJB_PORT.getKey(), + BusinessConfigOption.HOST_EJB_BIND.getKey(), + BusinessConfigOption.HOST_HTTP_ADDRESS.getKey(), + BusinessConfigOption.HOST_HTTP_PORT.getKey()); } /** @@ -313,8 +329,11 @@ public class LimaBusinessConfig { DATA_DIR("lima.data.dir", n("lima.config.data.dir.description"), "${user.home}/.lima", File.class, false, false), RULES_NATIONALTY("lima.rules", n("lima.config.rulesnationality.description"), FranceAccountingRules.class.getName(), String.class, false, false), - HOST_ADDRESS("lima.host.address", n("lima.host.address.description"), "localhost", String.class, false, false), - HOST_EJB_PORT("ejbd.port", n("lima.host.ejb.port.description"), "4202", Integer.class, false, false), + HOST_EJB_ADDRESS("lima.host.ejb.address", n("lima.host.address.description"), "localhost", String.class, false, false), + HOST_EJB_BIND("lima.host.ejb.bind", "", "0.0.0.0", String.class, false, false), + HOST_EJB_PORT("lima.host.ejb.port", n("lima.host.ejb.port.description"), "4202", Integer.class, false, false), + + HOST_HTTP_ADDRESS("lima.host.http.address", n("lima.host.http.address.description"), "localhost", Integer.class, false, false), HOST_HTTP_PORT("lima.host.http.port", n("lima.host.http.port.description"), "5462", Integer.class, false, false), SCALE("lima.data.bigDecimal.scale", t("lima.config.scale.label"), n("lima.config.scale.description"), "2", String.class, false, false), diff --git a/lima-business/src/main/java/org/chorem/lima/business/ejb/OptionsServiceImpl.java b/lima-business/src/main/java/org/chorem/lima/business/ejb/OptionsServiceImpl.java index a70a5e0..8cbfae8 100644 --- a/lima-business/src/main/java/org/chorem/lima/business/ejb/OptionsServiceImpl.java +++ b/lima-business/src/main/java/org/chorem/lima/business/ejb/OptionsServiceImpl.java @@ -93,8 +93,8 @@ public class OptionsServiceImpl extends AbstractLimaService implements OptionsSe } @Override - public String getLimaHostAddress() { - return LimaBusinessConfig.getInstance().getHostAddress(); + public String getLimaHttpHostAddress() { + return LimaBusinessConfig.getInstance().getHostHttpAddress(); } @Override diff --git a/lima-business/src/main/resources/i18n/lima-business_en_GB.properties b/lima-business/src/main/resources/i18n/lima-business_en_GB.properties index 75bd611..36aa5b4 100644 --- a/lima-business/src/main/resources/i18n/lima-business_en_GB.properties +++ b/lima-business/src/main/resources/i18n/lima-business_en_GB.properties @@ -84,6 +84,7 @@ lima.financialtransaction.account=Account lima.fiscalperiod.fiscalperiod=Fiscal period lima.host.address.description= lima.host.ejb.port.description= +lima.host.http.address.description= lima.host.http.port.description= lima.importexport.import.alreadyExistFinancialStatement=Same financial statement exists lima.lettering.accountRegularization=Regulatory account diff --git a/lima-business/src/main/resources/i18n/lima-business_fr_FR.properties b/lima-business/src/main/resources/i18n/lima-business_fr_FR.properties index 9a1c334..10c9d44 100644 --- a/lima-business/src/main/resources/i18n/lima-business_fr_FR.properties +++ b/lima-business/src/main/resources/i18n/lima-business_fr_FR.properties @@ -86,6 +86,7 @@ lima.financialtransaction.account=compte lima.fiscalperiod.fiscalperiod=Période fiscale lima.host.address.description=Addresse serveur lima.host.ejb.port.description=Port pour connexion du client au serveur +lima.host.http.address.description= lima.host.http.port.description=Port du serveur web de Lima lima.importexport.import.alreadyExistFinancialStatement=Transaction financière exitante lima.lettering.accountRegularization=Compte de régulation diff --git a/lima-server/README.txt b/lima-server/README.txt index a24302b..38cb603 100644 --- a/lima-server/README.txt +++ b/lima-server/README.txt @@ -6,14 +6,22 @@ Windows 7 et + : C:\Users\USER_NAME\AppData\Roaming\lima-server.config Mac OS : $HOME/Library/Application Support/lima-server.config Ajoutez la ligne suivantes sur en remplaçant l'IP en exemple (192.168.1.37) par celle du serveur : -lima.host.address=192.168.1.37 +lima.host.ejb.address=192.168.1.37 + +les lignes suivantes sont optionnelles: +lima.host.ejb.bind=0.0.0.0 # valeur par défaut +lima.host.ejbd.port=4202 # valeur par défaut +lima.host.http.address=192.168.1.137 (si aucune adresse n'est spécifiée celle du serveur ejb est utilisée) +lima.host.http.port=5462 # valeur par défaut + -****************** Configuration du client ****************** +****************** Configuration des clients ****************** -Pour configurer le client pour se connecter au serveur, éditez le fichier de configuration (lima-swing.config) qui se trouve ici : +Pour configurer les clients pour se connecter au serveur, éditez le fichier de configuration de la machine cliente(lima-swing.config) qui se trouve ici : Unix-like : $HOME/.config/lima-swing.config Windows 7 et + : C:\Users\USER_NAME\AppData\Roaming\lima-swing.config Mac OS : $HOME/Library/Application Support/lima-swing.config -Ajoutez la ligne suivantes sur en remplaçant l'IP en exemple (192.168.1.37) par celle du serveur : -lima.host.address=192.168.1.37 \ No newline at end of file +Ajoutez la ligne suivante sur en remplaçant l'IP en exemple (192.168.1.37) par celle du serveur : +lima.host.address=192.168.1.37 + diff --git a/lima-server/src/main/java/org/chorem/lima/server/HttpServerService.java b/lima-server/src/main/java/org/chorem/lima/server/HttpServerService.java index dfea242..1581ffa 100644 --- a/lima-server/src/main/java/org/chorem/lima/server/HttpServerService.java +++ b/lima-server/src/main/java/org/chorem/lima/server/HttpServerService.java @@ -49,6 +49,8 @@ import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.net.InetAddress; +import java.net.InetSocketAddress; import java.net.URL; import java.net.URLDecoder; import java.text.ParseException; @@ -80,7 +82,10 @@ public class HttpServerService { public void start() { if (server == null) { try { - server = new Server(limaHttpPort); + + InetAddress host = InetAddress.getByName(limaHttpHost); + InetSocketAddress inetSocketAddress = InetSocketAddress.createUnresolved(host.getHostAddress(), limaHttpPort); + server = new Server(inetSocketAddress); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); context.setContextPath("/"); @@ -94,7 +99,7 @@ public class HttpServerService { } } catch (Exception eee) { - log.error("error while booting http server", eee); + log.error(String.format("error while booting http server with address %s:%d", limaHttpHost, limaHttpPort), eee); } } } @@ -103,7 +108,7 @@ public class HttpServerService { OptionsService optionsService = LimaServiceFactory.getService(OptionsService.class); - limaHttpHost = optionsService.getLimaHostAddress(); + limaHttpHost = optionsService.getLimaHttpHostAddress(); limaHttpPort = optionsService.getLimaHttpPort(); documentService = new DocumentService(); } diff --git a/lima-server/src/main/java/org/chorem/lima/server/LimaServer.java b/lima-server/src/main/java/org/chorem/lima/server/LimaServer.java index 8f1eb48..3f6afb2 100644 --- a/lima-server/src/main/java/org/chorem/lima/server/LimaServer.java +++ b/lima-server/src/main/java/org/chorem/lima/server/LimaServer.java @@ -26,6 +26,7 @@ package org.chorem.lima.server; import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.apache.openejb.client.RemoteInitialContextFactory; import org.chorem.lima.business.LimaBusinessConfig; import org.chorem.lima.business.LimaServiceFactory; import org.chorem.lima.report.LimaReportConfig; @@ -48,6 +49,8 @@ import javax.naming.NamingException; public class LimaServer { private static final Log log = LogFactory.getLog(LimaServer.class); + public static final String EJB_URL = "ejbd://%s:%d"; + public static final String LIMA_HOST_ADDRESS = "lima.host.address"; /** http serveur */ protected static HttpServerService httpServerService; @@ -92,28 +95,62 @@ public class LimaServer { public static void launch(ApplicationConfig moduleConfig) { - boolean mustStartServer = StringUtils.isBlank(moduleConfig.getOption(Context.PROVIDER_URL)) || - moduleConfig.getOptionAsBoolean("openejb.embedded.remotable"); + boolean isRemoteMode = moduleConfig.getOptionAsBoolean(LimaServerConfig.ServerConfigOption.EJB_REMOTABLE.getKey()); + boolean mustStartServer = StringUtils.isBlank(moduleConfig.getOption(LIMA_HOST_ADDRESS)) || isRemoteMode; ApplicationConfig initConfig = moduleConfig; + LimaBusinessConfig config = LimaBusinessConfig.getInstance(initConfig); + initConfig = config.getConfig(); + if (mustStartServer) { - // push all configs + // server or standalone configs initConfig = LimaServerConfig.getInstance(initConfig).getConfig(); initConfig = LimaBusinessConfig.getInstance(initConfig).getConfig(); initConfig = LimaReportConfig.getInstance(initConfig).getConfig(); + + // this is to map key ex from lima.host.ejb.bind to ejbd.bind + setServeurEjbParams(initConfig); + + } else { + // client config + setClientEjbParams(initConfig); } + String url = String.format(EJB_URL, config.getHostEJBAddress(), config.getHostEjbPort()); + initConfig.setOption(Context.PROVIDER_URL, url); + // start EJB container (either local or remote) LimaServiceFactory.initFactory(initConfig); // start web server only if it's on server mode if (mustStartServer) { + setHttpServerParams(isRemoteMode, initConfig); httpServerService = new HttpServerService(); httpServerService.start(); } } + protected static void setClientEjbParams(ApplicationConfig initConfig) { + initConfig.setOption(LimaBusinessConfig.BusinessConfigOption.HOST_EJB_ADDRESS.getKey(), initConfig.getOption(LIMA_HOST_ADDRESS)); + initConfig.setOption(Context.INITIAL_CONTEXT_FACTORY, RemoteInitialContextFactory.class.getName()); + } + + protected static void setServeurEjbParams(ApplicationConfig initConfig) { + initConfig.setOption(LimaServerConfig.ServerConfigOption.EJB_BIND.getKey(), initConfig.getOption(LimaBusinessConfig.BusinessConfigOption.HOST_EJB_BIND.getKey())); + initConfig.setOption(LimaServerConfig.ServerConfigOption.EJB_PORT.getKey(), initConfig.getOption(LimaBusinessConfig.BusinessConfigOption.HOST_EJB_PORT.getKey())); + } + + + protected static void setHttpServerParams(boolean isRemoteMode, ApplicationConfig initConfig) { + boolean isDefaultHttpAddressUsed = LimaBusinessConfig.getInstance().getHostHttpAddress().contentEquals(LimaBusinessConfig.BusinessConfigOption.HOST_HTTP_ADDRESS.getDefaultValue()); + if (isRemoteMode && isDefaultHttpAddressUsed) { + // in case of client access to server throw remote ejb mode, and no HTTP address is provied, the HTTP server must not use the default localhost address but the ejb one. + String httpAddress = initConfig.getOption(LimaBusinessConfig.BusinessConfigOption.HOST_EJB_ADDRESS.getKey()); + LimaBusinessConfig.getInstance().setHostHttpAddress(httpAddress); + } + } + public static HttpServerService getHttpServerService() { return httpServerService; } diff --git a/lima-server/src/main/java/org/chorem/lima/server/LimaServerConfig.java b/lima-server/src/main/java/org/chorem/lima/server/LimaServerConfig.java index 54680a5..fcc4f28 100644 --- a/lima-server/src/main/java/org/chorem/lima/server/LimaServerConfig.java +++ b/lima-server/src/main/java/org/chorem/lima/server/LimaServerConfig.java @@ -124,15 +124,6 @@ public class LimaServerConfig { } - public Integer getHostEjbPort() { - Integer port = Integer.parseInt(getConfig().getOption(ServerConfigOption.EJB_PORT.key)); - return port; - } - - public void setHostPort(String host) { - getConfig().setOption(ServerConfigOption.EJB_PORT.key, host); - } - public enum ServerConfigOption implements ConfigOptionDef { EJB_INITIAL_CONTEXT_FACTORY(Context.INITIAL_CONTEXT_FACTORY, "", LocalInitialContextFactory.class.getName(), String.class, false, true), diff --git a/lima-swing/src/main/java/org/chorem/lima/ui/MainViewHandler.java b/lima-swing/src/main/java/org/chorem/lima/ui/MainViewHandler.java index 2012972..dbe4867 100644 --- a/lima-swing/src/main/java/org/chorem/lima/ui/MainViewHandler.java +++ b/lima-swing/src/main/java/org/chorem/lima/ui/MainViewHandler.java @@ -71,7 +71,6 @@ import java.net.URI; import java.net.URL; import java.util.Locale; -import static org.nuiton.i18n.I18n.setDefaultLocale; import static org.nuiton.i18n.I18n.t; /** @@ -508,7 +507,7 @@ public class MainViewHandler { OptionsService optionsService = LimaServiceFactory.getService(OptionsService.class); - String host = optionsService.getLimaHttpHost(); + String host = optionsService.getLimaHttpHostAddress(); int port = optionsService.getLimaHttpPort(); String url; -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.