Added setting KorAP base service URI from web.xml
Change-Id: I81f4accafa1f6fd471fce6f990373f5d49ab5c85
diff --git a/src/main/java/de/mannheim/ids/korap/sru/KorapClient.java b/src/main/java/de/mannheim/ids/korap/sru/KorapClient.java
index 71e67c3..a131e9d 100644
--- a/src/main/java/de/mannheim/ids/korap/sru/KorapClient.java
+++ b/src/main/java/de/mannheim/ids/korap/sru/KorapClient.java
@@ -37,9 +37,11 @@
*/
public class KorapClient {
- private static String SERVICE_URI;
- private static final String CONFIGURATION_FILE = "kustvakt.conf";
- private static final String SERVICE_URI_PROPERTY = "korapsru.client.service.uri";
+ private static String serviceUri;
+ private static final String CONFIGURATION_FILE =
+ "kustvakt.conf";
+ private static final String SERVICE_URI_PROPERTY =
+ "korapsru.client.service.uri";
private static final String DEFAULT_CONTEXT_TYPE = "sentence";
private static final String DEFAULT_FOUNDRY = "*";
@@ -47,8 +49,8 @@
private int defaultMaxRecords = 10;
private static ObjectMapper objectMapper = new ObjectMapper();
- private static Logger logger = (Logger) LoggerFactory
- .getLogger(KorapClient.class);
+ private static Logger logger =
+ (Logger) LoggerFactory.getLogger(KorapClient.class);
/**
@@ -65,26 +67,33 @@
throws FileNotFoundException {
this.defaultNumOfRecords = numOfRecords;
this.defaultMaxRecords = maxRecords;
-
+
Properties properties = new Properties();
+ String path = System.getenv("$HOME")+"/"+CONFIGURATION_FILE;
InputStream is = getClass().getClassLoader()
- .getResourceAsStream(CONFIGURATION_FILE);
+ .getResourceAsStream(path);
try {
properties.load(is);
}
catch (IOException e) {
throw new FileNotFoundException("Configuration file "
- + CONFIGURATION_FILE + " is not found in the classpath.");
+ + CONFIGURATION_FILE + " is not found.");
}
if (properties.containsKey(SERVICE_URI_PROPERTY)) {
- SERVICE_URI = properties.getProperty("korapsru.client.service.uri");
- logger.info(SERVICE_URI);
+ serviceUri = properties.getProperty("korapsru.client.service.uri");
+ logger.info(serviceUri);
}
else {
throw new NullPointerException("Please specify korapsru.client."
+ "service.uri in the configuration file.");
}
}
+
+ public KorapClient (String serviceUri, int numOfRecords, int maxRecords){
+ this.defaultNumOfRecords = numOfRecords;
+ this.defaultMaxRecords = maxRecords;
+ this.serviceUri = serviceUri;
+ }
/**
@@ -99,7 +108,7 @@
public JsonNode retrieveResources ()
throws URISyntaxException, IOException {
- URIBuilder builder = new URIBuilder(SERVICE_URI + "Corpus");
+ URIBuilder builder = new URIBuilder(serviceUri + "Corpus");
URI uri = builder.build();
logger.info("Resource URI: " + uri.toString());
HttpGet httpRequest = new HttpGet(uri);
@@ -120,8 +129,8 @@
response.getStatusLine().getReasonPhrase());
}
- BufferedInputStream jsonStream = new BufferedInputStream(
- response.getEntity().getContent());
+ BufferedInputStream jsonStream =
+ new BufferedInputStream(response.getEntity().getContent());
try {
resources = objectMapper.readValue(jsonStream, JsonNode.class);
}
@@ -199,8 +208,8 @@
parseError(response);
}
- BufferedInputStream jsonStream = new BufferedInputStream(
- response.getEntity().getContent());
+ BufferedInputStream jsonStream =
+ new BufferedInputStream(response.getEntity().getContent());
try {
result = objectMapper.readValue(jsonStream, KorapResult.class);
}
@@ -212,7 +221,7 @@
}
}
catch (IOException e) {
- throw new IOException("Failed executing HTTP request.",e);
+ throw new IOException("Failed executing HTTP request.", e);
}
finally {
response.close();
@@ -297,7 +306,7 @@
params.add(
new BasicNameValuePair("offset", String.valueOf(startRecord)));
- URIBuilder builder = new URIBuilder(SERVICE_URI + "search");
+ URIBuilder builder = new URIBuilder(serviceUri + "search");
builder.addParameters(params);
URI uri = builder.build();
@@ -359,8 +368,8 @@
}
HttpUriRequest httpRequest;
- httpRequest = createMatchInfoRequest(resourceId, documentId, textId, matchId,
- foundry);
+ httpRequest = createMatchInfoRequest(resourceId, documentId, textId,
+ matchId, foundry);
String annotationSnippet = null;
@@ -375,8 +384,8 @@
parseError(response);
}
- BufferedInputStream jsonStream = new BufferedInputStream(
- response.getEntity().getContent());
+ BufferedInputStream jsonStream =
+ new BufferedInputStream(response.getEntity().getContent());
try {
JsonNode root = objectMapper.readTree(jsonStream);
annotationSnippet = "<snippet>" + root.at("/snippet").asText()
@@ -416,7 +425,7 @@
throws URISyntaxException {
StringBuilder sb = new StringBuilder();
- sb.append(SERVICE_URI);
+ sb.append(serviceUri);
sb.append("corpus/");
sb.append(resourceId);
sb.append("/");
diff --git a/src/main/java/de/mannheim/ids/korap/sru/KorapSRU.java b/src/main/java/de/mannheim/ids/korap/sru/KorapSRU.java
index 534ca1d..14bd9e1 100644
--- a/src/main/java/de/mannheim/ids/korap/sru/KorapSRU.java
+++ b/src/main/java/de/mannheim/ids/korap/sru/KorapSRU.java
@@ -55,14 +55,12 @@
protected void doInit(ServletContext context, SRUServerConfig config,
SRUQueryParserRegistry.Builder parserRegistryBuilder,
Map<String, String> params) throws SRUConfigException {
- // serverConfig = config;
- try {
- korapClient = new KorapClient(config.getNumberOfRecords(),
- config.getMaximumRecords());
- }
- catch (FileNotFoundException e) {
- throw new SRUConfigException(e.getMessage());
- }
+
+ String korapURI = context.getInitParameter("korap.service.uri");
+
+ korapClient = new KorapClient(korapURI,
+ config.getNumberOfRecords(),
+ config.getMaximumRecords());
StringBuilder sb = new StringBuilder();
sb.append(config.getTransports());
diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml
index 45ff7f1..8574a4b 100644
--- a/src/main/webapp/WEB-INF/web.xml
+++ b/src/main/webapp/WEB-INF/web.xml
@@ -1,77 +1,81 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns="http://java.sun.com/xml/ns/javaee"
- xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
- xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
- id="KorapSRU" version="2.5">
- <display-name>KorapSRU</display-name>
+ xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
+ id="KorapSRU" version="2.5">
+ <display-name>KorapSRU</display-name>
- <servlet>
- <display-name>KorAP SRU/CQL Service (HTTP Interface)</display-name>
- <servlet-name>KorapSRU</servlet-name>
- <servlet-class>eu.clarin.sru.server.utils.SRUServerServlet</servlet-class>
- <init-param>
- <param-name>eu.clarin.sru.server.numberOfRecords</param-name>
- <param-value>25</param-value>
- </init-param>
- <init-param>
- <param-name>eu.clarin.sru.server.maximumRecords</param-name>
- <param-value>50</param-value>
- </init-param>
- <init-param>
- <param-name>eu.clarin.sru.server.transport</param-name>
- <param-value>http</param-value>
- </init-param>
- <init-param>
- <param-name>eu.clarin.sru.server.host</param-name>
- <param-value>clarin.ids-mannheim.de</param-value>
- </init-param>
- <init-param>
- <param-name>eu.clarin.sru.server.port</param-name>
- <param-value>80</param-value>
- </init-param>
- <init-param>
- <param-name>eu.clarin.sru.server.database</param-name>
- <param-value>korapsru</param-value>
- </init-param>
- <init-param>
- <param-name>eu.clarin.sru.server.allowOverrideMaximumRecords</param-name>
- <param-value>false</param-value>
- </init-param>
- <init-param>
- <param-name>eu.clarin.sru.server.allowOverrideIndentResponse</param-name>
- <param-value>true</param-value>
- </init-param>
- <init-param>
- <param-name>eu.clarin.sru.server.utils.sruServerSearchEngineClass</param-name>
- <param-value>de.mannheim.ids.korap.sru.KorapSRU</param-value>
- </init-param>
- <init-param>
- <param-name>eu.clarin.sru.server.legacyNamespaceMode</param-name>
- <param-value>loc</param-value>
- </init-param>
- <init-param>
- <param-name>eu.clarin.sru.server.sruSupportedVersionMax</param-name>
- <param-value>2.0</param-value>
- </init-param>
- <load-on-startup>1</load-on-startup>
- </servlet>
- <servlet-mapping>
- <servlet-name>KorapSRU</servlet-name>
- <url-pattern>/*</url-pattern>
- </servlet-mapping>
+ <context-param>
+ <param-name>korap.service.uri</param-name>
+ <param-value>http://10.0.10.52:9000/api/</param-value>
+ </context-param>
- <servlet>
- <servlet-name>ResourceService</servlet-name>
- <jsp-file>/_redirect.jsp</jsp-file>
- <init-param>
- <param-name>korapWebUrl</param-name>
- <param-value>http://korap.ids-mannheim.de/kalamar</param-value>
- </init-param>
- </servlet>
- <servlet-mapping>
- <servlet-name>ResourceService</servlet-name>
- <url-pattern>/redirect/*</url-pattern>
- </servlet-mapping>
+ <servlet>
+ <display-name>KorAP SRU/CQL Service (HTTP Interface)</display-name>
+ <servlet-name>KorapSRU</servlet-name>
+ <servlet-class>eu.clarin.sru.server.utils.SRUServerServlet</servlet-class>
+ <init-param>
+ <param-name>eu.clarin.sru.server.numberOfRecords</param-name>
+ <param-value>25</param-value>
+ </init-param>
+ <init-param>
+ <param-name>eu.clarin.sru.server.maximumRecords</param-name>
+ <param-value>50</param-value>
+ </init-param>
+ <init-param>
+ <param-name>eu.clarin.sru.server.transport</param-name>
+ <param-value>http</param-value>
+ </init-param>
+ <init-param>
+ <param-name>eu.clarin.sru.server.host</param-name>
+ <param-value>clarin.ids-mannheim.de</param-value>
+ </init-param>
+ <init-param>
+ <param-name>eu.clarin.sru.server.port</param-name>
+ <param-value>80</param-value>
+ </init-param>
+ <init-param>
+ <param-name>eu.clarin.sru.server.database</param-name>
+ <param-value>korapsru</param-value>
+ </init-param>
+ <init-param>
+ <param-name>eu.clarin.sru.server.allowOverrideMaximumRecords</param-name>
+ <param-value>false</param-value>
+ </init-param>
+ <init-param>
+ <param-name>eu.clarin.sru.server.allowOverrideIndentResponse</param-name>
+ <param-value>true</param-value>
+ </init-param>
+ <init-param>
+ <param-name>eu.clarin.sru.server.utils.sruServerSearchEngineClass</param-name>
+ <param-value>de.mannheim.ids.korap.sru.KorapSRU</param-value>
+ </init-param>
+ <init-param>
+ <param-name>eu.clarin.sru.server.legacyNamespaceMode</param-name>
+ <param-value>loc</param-value>
+ </init-param>
+ <init-param>
+ <param-name>eu.clarin.sru.server.sruSupportedVersionMax</param-name>
+ <param-value>2.0</param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>KorapSRU</servlet-name>
+ <url-pattern>/*</url-pattern>
+ </servlet-mapping>
+
+ <servlet>
+ <servlet-name>ResourceService</servlet-name>
+ <jsp-file>/_redirect.jsp</jsp-file>
+ <init-param>
+ <param-name>korapWebUrl</param-name>
+ <param-value>http://korap.ids-mannheim.de/kalamar</param-value>
+ </init-param>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>ResourceService</servlet-name>
+ <url-pattern>/redirect/*</url-pattern>
+ </servlet-mapping>
</web-app>