Support path in API and asset URIs

Change-Id: I84970a2603fb7520559ac15dde676475abc32fd1
diff --git a/plugin/src/main/java/de/ids_mannheim/korap/plkexport/IdsExportService.java b/plugin/src/main/java/de/ids_mannheim/korap/plkexport/IdsExportService.java
index 002e279..6eb5663 100644
--- a/plugin/src/main/java/de/ids_mannheim/korap/plkexport/IdsExportService.java
+++ b/plugin/src/main/java/de/ids_mannheim/korap/plkexport/IdsExportService.java
@@ -110,6 +110,7 @@
         String scheme = properties.getProperty("api.scheme", "https");
         String port = properties.getProperty("api.port", "8089");
         String host = properties.getProperty("api.host", "localhost");
+        String path = properties.getProperty("api.path", "");
 
         UriBuilder uri = UriBuilder.fromPath("/api/v1.0/search")
             .host(host)
@@ -120,6 +121,10 @@
             .queryParam("ql", ql)
             .queryParam("cutoff", 1)
             ;
+
+        if (path != "") {
+            uri = uri.path(path);
+        };
         
         if (il != null) {
             uri = uri.queryParam("count", hitc);
@@ -127,7 +132,7 @@
 
         else {
             uri = uri.queryParam("count", ExWSConf.MAX_EXP_LIMIT);
-        }
+        };
 
         String resp;
         try {
@@ -205,15 +210,19 @@
         String scheme = properties.getProperty("asset.scheme", "https");
         String port = properties.getProperty("asset.port", "");
         String host = properties.getProperty("asset.host", "korap.ids-mannheim.de");
+        String path = properties.getProperty("asset.path", "");
 
         UriBuilder uri = UriBuilder.fromPath("")
             .host(host)
-            .scheme(scheme)
-            ;
+            .scheme(scheme);
+
+        if (path != "") {
+            uri = uri.path(path);
+        };
 
         if (port != "") {
             uri = uri.port(Integer.parseInt(port));
-        }
+        };
 
         templateData.put("assetPath", uri.build());
 
diff --git a/plugin/src/main/java/de/ids_mannheim/korap/plkexport/PluginServer.java b/plugin/src/main/java/de/ids_mannheim/korap/plkexport/PluginServer.java
index cb5a71c..8bbd366 100644
--- a/plugin/src/main/java/de/ids_mannheim/korap/plkexport/PluginServer.java
+++ b/plugin/src/main/java/de/ids_mannheim/korap/plkexport/PluginServer.java
@@ -59,7 +59,8 @@
                 "ApiServer expected under: " +
                 properties.getProperty("api.scheme") +
                 "://" +
-                properties.getProperty("api.host")+ ":" +
+                properties.getProperty("api.host") +
+                properties.getProperty("api.path") + ":" +
                 properties.getProperty("api.port")
                 );
             jettyServer.join();
diff --git a/plugin/src/test/java/de/ids_mannheim/korap/plkexport/IdsExportServiceTest.java b/plugin/src/test/java/de/ids_mannheim/korap/plkexport/IdsExportServiceTest.java
index ca63a0a..df2aa5a 100644
--- a/plugin/src/test/java/de/ids_mannheim/korap/plkexport/IdsExportServiceTest.java
+++ b/plugin/src/test/java/de/ids_mannheim/korap/plkexport/IdsExportServiceTest.java
@@ -156,6 +156,29 @@
     }
 
     @Test
+    public void testFormHTML2 () {
+        Properties properties = ExWSConf.properties(null);
+        String hostTemp = properties.getProperty("asset.host");
+        String pathTemp = properties.getProperty("asset.path");
+        properties.setProperty("asset.host", "ids-mannheim.example");
+        properties.setProperty("asset.path", "/instance/test");
+        
+        Response responsehtml = target("/export").request()
+                .get();
+        assertEquals("HTTP Code",
+                Status.OK.getStatusCode(), responsehtml.getStatus());
+        String str = responsehtml.readEntity(String.class);
+        assertTrue("HTTP Body", str.contains("<title>Export</title>"));
+        assertTrue("Assets", str.contains("<script src=\"https://ids-mannheim.example/instance/test/js"));
+        assertTrue("Assets", str.contains("<link href=\"https://ids-mannheim.example/instance/test/css"));
+        assertFalse("Errors", str.contains("dynCall("));
+
+        properties.setProperty("asset.host", hostTemp);
+        properties.setProperty("asset.path", pathTemp != null ? pathTemp : "");
+    }
+
+    
+    @Test
     public void testJS () {
         Response responsejs = target("/export.js").request()
                 .get();
@@ -306,7 +329,9 @@
 
     @Test
     public void testExportWsProxyProblem () {
-        ExWSConf.properties(null).setProperty("api.port", String.valueOf(mockServer.getPort() + 11));
+        Properties properties = ExWSConf.properties(null);
+        String portTemp = properties.getProperty("api.port");
+        properties.setProperty("api.port", String.valueOf(mockServer.getPort() + 11));
 
         String filenamej = "dateiJson";
         MultivaluedHashMap<String, String> frmap = new MultivaluedHashMap<String, String>();
@@ -327,6 +352,7 @@
 
         String str = responsejson.readEntity(String.class);
         assertTrue("HTTP Body", str.contains("P.log(502, 'Unable to reach Backend');"));
+        properties.setProperty("api.port", portTemp);
     };