org.openqa.grid.web.servlet.NodeW3CStatusServlet Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of selenium-server Show documentation
Show all versions of selenium-server Show documentation
Selenium automates browsers. That's it! What you do with that power is entirely up to you.
package org.openqa.grid.web.servlet;
import static com.google.common.net.MediaType.JSON_UTF_8;
import static java.net.HttpURLConnection.HTTP_OK;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.openqa.selenium.remote.ErrorCodes.SUCCESS;
import com.google.common.collect.ImmutableMap;
import org.openqa.selenium.internal.BuildInfo;
import org.openqa.selenium.remote.BeanToJsonConverter;
import java.io.IOException;
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class NodeW3CStatusServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
ImmutableMap.Builder value = ImmutableMap.builder();
// W3C spec
value.put("ready", true);
value.put("message", "Node is running");
BuildInfo buildInfo = new BuildInfo();
value.put("build", ImmutableMap.of(
// We need to fix the BuildInfo to properly fill out these values.
"revision", buildInfo.getBuildRevision(),
"time", buildInfo.getBuildTime(),
"version", buildInfo.getReleaseLabel()));
value.put("os", ImmutableMap.of(
"arch", System.getProperty("os.arch"),
"name", System.getProperty("os.name"),
"version", System.getProperty("os.version")));
value.put("java", ImmutableMap.of("version", System.getProperty("java.version")));
Map payloadObj = ImmutableMap.of(
"status", SUCCESS,
"value", value.build());
// Write out a minimal W3C status response.
byte[] payload = new BeanToJsonConverter().convert(payloadObj).getBytes(UTF_8);
resp.setStatus(HTTP_OK);
resp.setHeader("Content-Type", JSON_UTF_8.toString());
resp.setHeader("Content-Length", String.valueOf(payload.length));
try (ServletOutputStream out = resp.getOutputStream()) {
out.write(payload);
}
}
}