From 7a81e49856231685e702e7a673718eaacd34f483 Mon Sep 17 00:00:00 2001 From: Henning Bredel Date: Wed, 23 Sep 2015 09:56:49 +0200 Subject: [PATCH] fixes #197 --- .../java/org/n52/wps/test/PostClient.java | 37 ++++++++++--------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/52n-wps-webapp/src/test/java/org/n52/wps/test/PostClient.java b/52n-wps-webapp/src/test/java/org/n52/wps/test/PostClient.java index aa7e8f860..5df6a2a3a 100644 --- a/52n-wps-webapp/src/test/java/org/n52/wps/test/PostClient.java +++ b/52n-wps-webapp/src/test/java/org/n52/wps/test/PostClient.java @@ -62,7 +62,7 @@ public static String sendRequest(String targetURL, String payload) throws IOExce payloadP = "request=" + payloadP; InputStream in = sendRequestForInputStream(targetURL, payloadP); - + // Get the response BufferedReader rd = new BufferedReader(new InputStreamReader(in)); List lines= new LinkedList(); @@ -78,7 +78,7 @@ public static InputStream sendRequestForInputStream(String targetURL, String pay // Send data URL url = new URL(targetURL); - URLConnection conn = url.openConnection(); + HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setDoOutput(true); @@ -87,10 +87,13 @@ public static InputStream sendRequestForInputStream(String targetURL, String pay wr.write(payload); wr.close(); - return conn.getInputStream(); - + if (conn.getResponseCode() >= 400) { + return conn.getErrorStream(); + } else { + return conn.getInputStream(); + } } - + public static void checkForExceptionReport(String targetURL, String payload, int expectedHTTPStatusCode, String... expectedExceptionParameters) throws IOException{ // Send data URL url = new URL(targetURL); @@ -104,30 +107,30 @@ public static void checkForExceptionReport(String targetURL, String payload, int wr.write(payload); wr.close(); - try { - conn.getInputStream(); + try { + conn.getInputStream(); } catch (IOException e) { /* * expected, ignore - */ + */ } - + InputStream error = ((HttpURLConnection) conn).getErrorStream(); - + String exceptionReport = ""; - + int data = error.read(); while (data != -1) { exceptionReport = exceptionReport + (char)data; data = error.read(); } error.close(); - assertTrue(((HttpURLConnection) conn).getResponseCode() == expectedHTTPStatusCode); - + assertTrue(((HttpURLConnection) conn).getResponseCode() == expectedHTTPStatusCode); + for (String expectedExceptionParameter : expectedExceptionParameters) { - - assertTrue(exceptionReport.contains(expectedExceptionParameter)); - - } + + assertTrue(exceptionReport.contains(expectedExceptionParameter)); + + } } }