Skip to content

Commit

Permalink
Add a /status handler for pass-through mode.
Browse files Browse the repository at this point in the history
It doesn't include any of the JSON Wire Protocol fields (all of which are optional anyway), but it should get the job done for now.
  • Loading branch information
juangj committed May 27, 2017
1 parent 453585e commit d6d335d
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions java/server/src/org/openqa/selenium/remote/server/AllHandlers.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import static com.google.common.net.MediaType.JAVASCRIPT_UTF_8;
import static java.net.HttpURLConnection.HTTP_NOT_FOUND;
import static java.net.HttpURLConnection.HTTP_OK;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.openqa.selenium.remote.ErrorCodes.UNKNOWN_COMMAND;

Expand Down Expand Up @@ -74,6 +75,10 @@ public CommandHandler match(HttpServletRequest req) {
return new BeginSession(allSessions, legacySessions);
}

if ("GET".equalsIgnoreCase(req.getMethod()) && "/status".equals(path)) {
return new StatusHandler();
}

return new NoHandler();
}

Expand Down Expand Up @@ -108,4 +113,26 @@ public void execute(HttpServletRequest req, HttpServletResponse resp) throws IOE
}
}
}

private static class StatusHandler implements CommandHandler {

@Override
public void execute(HttpServletRequest req, HttpServletResponse resp) throws IOException {
resp.reset();

// Write out a minimal W3C status response.
byte[] payload = new GsonBuilder().create().toJson(ImmutableMap.of(
"ready", true,
"message", "Server is running"
)).getBytes(UTF_8);

resp.setStatus(HTTP_OK);
resp.setContentType(JAVASCRIPT_UTF_8.toString());
resp.setContentLengthLong(payload.length);

try (OutputStream out = resp.getOutputStream()) {
out.write(payload);
}
}
}
}

0 comments on commit d6d335d

Please sign in to comment.