diff --git a/pom.xml b/pom.xml index bebcd60..0e4f6ae 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ war UTF-8 - 0.9.30 + 0.9.31 2.24.1 3.8.0 3.1.8 diff --git a/src/main/java/io/rtdi/bigdata/rulesservice/RulesService.java b/src/main/java/io/rtdi/bigdata/rulesservice/RulesService.java index ad2ff0f..1123807 100644 --- a/src/main/java/io/rtdi/bigdata/rulesservice/RulesService.java +++ b/src/main/java/io/rtdi/bigdata/rulesservice/RulesService.java @@ -27,6 +27,7 @@ import javax.naming.Context; import javax.naming.InitialContext; +import javax.naming.NamingException; import org.apache.avro.Schema; import org.apache.avro.Schema.Parser; @@ -69,7 +70,7 @@ public class RulesService implements ServletContextListener { private CachedSchemaRegistryClient schemaclient; private ServletContext context; private Path settingsdir; - private Path rulegroupdir; + private Path rulefiledir; private Exception globalexception; private String properties; private Map propertiesmap; @@ -162,26 +163,42 @@ public void contextInitialized(ServletContextEvent sce) { try { Context initCtx = new InitialContext(); Context envCtx = (Context) initCtx.lookup("java:comp/env"); - Object o = envCtx.lookup("rulesettings"); - if (o != null) { - settingsdir = Path.of(o.toString()); - log.info("Found JNDI resource name , hence the settings directory is <{}>", settingsdir); - } else { + try { + Object o = envCtx.lookup("rulesettings"); + if (o != null) { + settingsdir = Path.of(o.toString()); + log.info("Found JNDI resource name , hence the settings directory is <{}>", settingsdir); + } + } catch (NamingException e) { + log.info("No JNDI resource found in the context.xml for name , hence using the default"); + } + try { + Object o = envCtx.lookup("rulegroups"); + if (o != null) { + rulefiledir = Path.of(o.toString()); + log.info("Found JNDI resource name , hence the rules root directory is <{}>", rulefiledir); + } + } catch (NamingException e) { + log.info("No JNDI resource found in the context.xml for name , hence the default"); + } + } catch (Exception e) { + this.globalexception = e; + log.info("Exception when reading the webserver settings", e); + } + try { + if (settingsdir == null) { settingsdir = Path.of("/apps/rulesservice/settings"); - log.info("No JNDI resource found for name , hence the settings directory is the default <{}>", settingsdir); + log.info("Settings directory is the default <{}>", settingsdir); } - o = envCtx.lookup("rulegroups"); - if (o != null) { - rulegroupdir = Path.of(o.toString()); - log.info("Found JNDI resource name , hence the rules root directory is <{}>", rulegroupdir); - } else { - rulegroupdir = Path.of("/apps/rulesservice/definitions"); - log.info("No JNDI resource found for name , hence the rules root directory is the default <{}>", rulegroupdir); + if (rulefiledir == null) { + rulefiledir = Path.of("/apps/rulesservice/definitions"); + log.info("Rulefile directory is the default <{}>", rulefiledir); } configure(); startService(); } catch (Exception e) { this.globalexception = e; + log.info("Exception when reading the webserver settings", e); } } @@ -321,12 +338,12 @@ private void configure() throws IOException, RestClientException { } public List getRuleFiles(String schemaname) { - List groups = RuleFileDefinition.getAllRuleFiles(rulegroupdir, schemaname); + List groups = RuleFileDefinition.getAllRuleFiles(rulefiledir, schemaname); return groups; } public List getAllRuleFiles() { - List groups = RuleFileDefinition.getAllRuleFiles(rulegroupdir); + List groups = RuleFileDefinition.getAllRuleFiles(rulefiledir); return groups; } @@ -349,7 +366,7 @@ public Exception getGlobalException() { } public Path getRuleFileRootDir() { - return this.rulegroupdir; + return this.rulefiledir; } public ServiceSettings getConfig(boolean isadmin) { @@ -420,7 +437,7 @@ public Collection getTopicsAndRules() throws IOException { */ public Map getTopicRuleFiles() throws IOException { ObjectMapper om = new ObjectMapper(); - Path topicrules = rulegroupdir.resolve("topics"); + Path topicrules = rulefiledir.resolve("topics"); File topicruledir = topicrules.toFile(); Map fileset = new HashMap<>(); if (topicruledir.isDirectory()) { @@ -437,7 +454,7 @@ public Map getTopicRuleFiles() throws IOException { public List saveTopicRules(List input) { - Path topicruledir = rulegroupdir.resolve("topics"); + Path topicruledir = rulefiledir.resolve("topics"); File f = topicruledir.toFile(); if (!f.exists()) { f.mkdirs();