Capture proxy problems

Change-Id: I3b2a00513de2b58a7358cb2231e7cdbc7f722cb9
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 12f625e..e2dffaf 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
@@ -9,6 +9,7 @@
 import java.util.Properties;
 
 import javax.ws.rs.BadRequestException;
+import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.FormParam;
 import javax.ws.rs.POST;
 import javax.ws.rs.Path;
@@ -21,6 +22,7 @@
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.Response.ResponseBuilder;
 import javax.ws.rs.core.Response.Status;
+import java.net.ConnectException;
 
 import com.fasterxml.jackson.core.JsonFactory;
 import com.fasterxml.jackson.core.JsonParser;
@@ -108,10 +110,19 @@
             uri = uri.queryParam("count", ExWSConf.MAX_EXP_LIMIT);
         }
 
-        //WebTarget resource = client.target(url);
-        WebTarget resource = client.target(uri.build());
-        String resp = resource.request(MediaType.APPLICATION_JSON)
+        String resp;
+        try {
+            WebTarget resource = client.target(uri.build());
+            resp = resource.request(MediaType.APPLICATION_JSON)
                 .get(String.class);
+        } catch (Exception e) {
+            throw new WebApplicationException(
+                Response
+                .ok(new String("Unable to reach Backend"), MediaType.TEXT_PLAIN)
+                .status(Status.BAD_GATEWAY)
+                .build()
+                );
+        }
 
         if (fname == null) {
             fname = q;
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 22c02d6..27a577a 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
@@ -278,6 +278,29 @@
                 Status.OK.getStatusCode(), responsertf.getStatus());
     }
 
+
+    @Test
+    public void testExportWsProxyProblem () {
+        ExWSConf.properties(null).setProperty("api.port", String.valueOf(mockServer.getPort() + 11));
+
+        String filenamej = "dateiJson";
+        MultivaluedHashMap<String, String> frmap = new MultivaluedHashMap<String, String>();
+        frmap.add("fname", filenamej);
+        frmap.add("format", "json");
+        frmap.add("q", "????");
+        frmap.add("ql", "poliqarp");
+
+        String message;
+
+        Response responsejson = target("/export").request()
+                .post(Entity.form(frmap));
+
+        ExWSConf.properties(null).setProperty("api.port", String.valueOf(mockServer.getPort()));
+
+        assertEquals("Request JSON: Http Response should be 502: ",
+                     Status.BAD_GATEWAY.getStatusCode(), responsejson.getStatus());
+    };
+
     
     // Get fixture from ressources
     private String getFixture (String file) {