Skip to content

Commit

Permalink
Fixes #1099, wrong response code if compile fails
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartwdouglas committed Mar 1, 2019
1 parent f608c3c commit 48cc5a4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ public void testThatApplicationRecoversCompilationIssue() throws MavenInvocation
await()
.pollDelay(1, TimeUnit.SECONDS)
.atMost(1, TimeUnit.MINUTES).until(() -> {
String content = getHttpResponse("/app/hello");
String content = getHttpResponse("/app/hello", true);
last.set(content);
return content.contains(uuid);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -159,13 +160,27 @@ static String getHttpResponse() {
}

static String getHttpResponse(String path) {
return getHttpResponse(path, false);
}

static String getHttpResponse(String path, boolean allowError) {
AtomicReference<String> resp = new AtomicReference<>();
await()
.pollDelay(1, TimeUnit.SECONDS)
.atMost(1, TimeUnit.MINUTES).until(() -> {
try {
URL url = new URL("http://localhost:8080" + ((path.startsWith("/") ? path : "/" + path)));
String content = IOUtils.toString(url, "UTF-8");
String content;
if (!allowError) {
content = IOUtils.toString(url, "UTF-8");
} else {
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
if (conn.getResponseCode() >= 400) {
content = IOUtils.toString(conn.getErrorStream(), "UTF-8");
} else {
content = IOUtils.toString(conn.getInputStream(), "UTF-8");
}
}
resp.set(content);
return true;
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ public class ReplacementDebugPage {
"</style>";

public static void handleRequest(HttpServerExchange exchange, final Throwable exception) throws IOException {
exchange.setStatusCode(500);
StringBuilder sb = new StringBuilder();
//todo: make this good
sb.append("<html><head><title>ERROR</title>");
Expand Down

0 comments on commit 48cc5a4

Please sign in to comment.