Devel Configuration Loader will use the classpath to get additional configuration files instead of absolute paths

This commit is contained in:
George Kalampokis 2020-01-15 12:48:41 +02:00
parent df07884cbe
commit 2d56ff0676
2 changed files with 18 additions and 32 deletions

View File

@ -47,42 +47,37 @@ public class DevelConfigLoader implements ConfigLoader {
private void setExternalUrls() {
String fileUrl = this.environment.getProperty("configuration.externalUrls");
System.out.println("Loaded also config file: " + fileUrl);
String current = null;
InputStream is = null;
try {
current = new java.io.File(".").getCanonicalPath();
JAXBContext jaxbContext = JAXBContext.newInstance(ExternalUrls.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
is = new URL("file:///" + current + fileUrl).openStream();
is = getClass().getClassLoader().getResource(fileUrl).openStream();
externalUrls = (ExternalUrls) jaxbUnmarshaller.unmarshal(is);
} catch (Exception ex) {
ex.printStackTrace();
System.out.println("Cannot find in folder" + current);
System.err.println("Cannot find resource in classpath");
} finally {
try {
if (is != null) is.close();
} catch (IOException e) {
System.out.println("Warning: Could not close a stream after reading from file: " + fileUrl);
} catch (IOException | NullPointerException e) {
System.err.println("Warning: Could not close a stream after reading from file: " + fileUrl);
}
}
}
private void setRdaProperties() {
String filePath = environment.getProperty("configuration.rda");
String current;
BufferedReader reader;
List<String> rdaList = new LinkedList<>();
try {
current = new java.io.File(".").getCanonicalPath();
reader = new BufferedReader(new FileReader(current + filePath));
reader = new BufferedReader(new FileReader(getClass().getClassLoader().getResource(filePath).getFile()));
String line = reader.readLine();
while (line != null) {
rdaList.add(line);
line = reader.readLine();
}
reader.close();
} catch (IOException e) {
} catch (IOException | NullPointerException e) {
e.printStackTrace();
}
@ -91,44 +86,35 @@ public class DevelConfigLoader implements ConfigLoader {
private void setDocument() {
String filePath = environment.getProperty("configuration.h2020template");
String current;
InputStream is = null;
try {
current = new java.io.File(".").getCanonicalPath();
is = new URL("file:///" + current + filePath).openStream();
is = getClass().getClassLoader().getResource(filePath).openStream();
this.document = new XWPFDocument(is);
} catch (IOException e) {
} catch (IOException | NullPointerException e) {
e.printStackTrace();
} finally {
try {
if (is != null) is.close();
} catch (IOException e) {
System.out.println("Warning: Could not close a stream after reading from file: " + filePath);
System.err.println("Warning: Could not close a stream after reading from file: " + filePath);
}
}
}
private void setConfigurableProviders() {
String filePath = environment.getProperty("configuration.configurable_login_providers");
String current;
InputStream is = null;
try {
current = new java.io.File(".").getCanonicalPath();
File tempFile = new File(current + filePath);
if (tempFile.exists()) {
is = new URL("file:///" + current + filePath).openStream();
is = getClass().getClassLoader().getResource(filePath).openStream();
ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
this.configurableProviders = mapper.readValue(is, ConfigurableProviders.class);
} else {
this.configurableProviders = new ConfigurableProviders();
}
} catch (IOException e) {
} catch (IOException | NullPointerException e) {
e.printStackTrace();
} finally {
try {
if (is != null) is.close();
} catch (IOException e) {
System.out.println("Warning: Could not close a stream after reading from file: " + filePath);
System.err.println("Warning: Could not close a stream after reading from file: " + filePath);
}
}
}

View File

@ -15,10 +15,10 @@ http-logger.server-address = http://localhost:31311
pdf.converter.url=http://localhost:88/
####################CONFIGURATION FILES OVERRIDES CONFIGURATIONS##########
configuration.externalUrls=/web/src/main/resources/ExternalUrls.xml
configuration.rda=/web/src/main/resources/RDACommonStandards.txt
configuration.h2020template=/web/src/main/resources/documents/h2020.docx
configuration.configurable_login_providers=/web/src/main/resources/configurableLoginProviders.json
configuration.externalUrls=ExternalUrls.xml
configuration.rda=RDACommonStandards.txt
configuration.h2020template=documents/h2020.docx
configuration.configurable_login_providers=configurableLoginProviders.json
#############TWITTER LOGIN CONFIGURATIONS#########