Skip to content

Commit

Permalink
Changed loading external kustvakt.conf and jdbc.properties
Browse files Browse the repository at this point in the history
to use /data folder (#598)

Change-Id: I0431d6fa76e68a90821234f90a626d999b150aac
  • Loading branch information
margaretha committed Mar 22, 2024
1 parent 387e468 commit d77ee71
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 50 deletions.
3 changes: 3 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
- Moved service.properties to src/main/resources/properties
- Moved free-resources.json to src/main/resources/json
- Enables inputting free-resources.json from data folder
- Changed loading external kustvakt.conf and jdbc.properties
to use /data folder (#598)



# version 0.73
Expand Down
34 changes: 32 additions & 2 deletions src/main/java/de/ids_mannheim/korap/server/KustvaktBaseServer.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package de.ids_mannheim.korap.server;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.nio.charset.StandardCharsets;
import java.security.NoSuchAlgorithmException;
import java.util.Properties;
import java.util.Scanner;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.HttpConnectionFactory;
import org.eclipse.jetty.server.Server;
Expand All @@ -22,17 +27,20 @@
import org.springframework.web.context.support.XmlWebApplicationContext;

import de.ids_mannheim.korap.config.KustvaktConfiguration;
import de.ids_mannheim.korap.dao.AnnotationDao;
import de.ids_mannheim.korap.encryption.RandomCodeGenerator;
import de.ids_mannheim.korap.exceptions.KustvaktException;
import lombok.Getter;
import lombok.Setter;

/**
* @author hanl
* @date 01/06/2015
* @author hanl, margaretha
*
*/
public abstract class KustvaktBaseServer {

private Logger log = LogManager.getLogger(KustvaktBaseServer.class);

protected static KustvaktConfiguration config;
protected static String springConfig = "default-config.xml";

Expand Down Expand Up @@ -76,6 +84,28 @@ protected KustvaktArgs readAttributes (String[] args) {
return kargs;
}

protected void loadProperties (String path, String defaultPath) throws IOException {
File f = new File(path);
Properties properties = new Properties();

InputStream in = null;
if (!f.exists()) {
log.info("Loading kustvakt configuration from "+defaultPath);
in = KustvaktServer.class.getClassLoader()
.getResourceAsStream(defaultPath);
}
else {
log.info("Loading kustvakt configuration from "+path);
in = new FileInputStream(f);
}

properties.load(in);
in.close();

config = new KustvaktConfiguration();
config.loadBasicProperties(properties);
}

protected void start ()
throws KustvaktException, IOException, NoSuchAlgorithmException {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
package de.ids_mannheim.korap.server;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Properties;

import de.ids_mannheim.korap.config.KustvaktConfiguration;

public class KustvaktLiteServer extends KustvaktBaseServer {

public static void main (String[] args) throws Exception {
Expand All @@ -16,22 +9,7 @@ public static void main (String[] args) throws Exception {
if (kargs == null)
System.exit(0);

File f = new File("kustvakt-lite.conf");
Properties properties = new Properties();
InputStream in = null;

if (!f.exists()) {
in = KustvaktLiteServer.class.getClassLoader()
.getResourceAsStream("kustvakt-lite.conf");
}
else {
in = new FileInputStream(f);
}

properties.load(in);
in.close();
config = new KustvaktConfiguration();
config.loadBasicProperties(properties);
server.loadProperties("data/kustvakt-lite.conf", "kustvakt-lite.conf");

springConfig = "default-lite-config.xml";

Expand Down
27 changes: 2 additions & 25 deletions src/main/java/de/ids_mannheim/korap/server/KustvaktServer.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
package de.ids_mannheim.korap.server;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Properties;

import de.ids_mannheim.korap.config.FullConfiguration;

/**
* pu
*
Expand All @@ -19,27 +12,11 @@ public static void main (String[] args) throws Exception {
KustvaktServer server = new KustvaktServer();
kargs = server.readAttributes(args);

File f = new File("kustvakt.conf");
Properties properties = new Properties();

InputStream in = null;
if (!f.exists()) {
in = KustvaktServer.class.getClassLoader()
.getResourceAsStream("kustvakt.conf");
}
else {
in = new FileInputStream(f);
}

properties.load(in);
in.close();

config = new FullConfiguration();
config.loadBasicProperties(properties);

// EM: why is this necessary?
if (kargs == null)
System.exit(0);

server.loadProperties("data/kustvakt.conf", "kustvakt.conf");
server.start();
}
}
3 changes: 3 additions & 0 deletions src/main/resources/default-config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<array>
<value>classpath:kustvakt.conf</value>
<value>file:./kustvakt.conf</value>
<value>file:./data/kustvakt.conf</value>
</array>
</property>
</bean>
Expand All @@ -40,12 +41,14 @@
<array>
<value>classpath:properties/jdbc.properties</value>
<value>file:./jdbc.properties</value>
<value>file:./data/jdbc.properties</value>
<value>classpath:properties/mail.properties</value>
<value>file:./mail.properties</value>
<value>classpath:properties/hibernate.properties</value>

<value>classpath:kustvakt.conf</value>
<value>file:./kustvakt.conf</value>
<value>file:./data/kustvakt.conf</value>
</array>
</property>
</bean>
Expand Down

0 comments on commit d77ee71

Please sign in to comment.