Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
A Grid console servlet, that will provide you with all free and busy proxies along with their registration info as a JSON object
package com.test.MyServlets;
import java.util.Iterator;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.openqa.grid.common.exception.GridException;
import org.openqa.grid.internal.ProxySet;
import org.openqa.grid.internal.Registry;
import org.openqa.grid.internal.RemoteProxy;
import org.openqa.grid.web.servlet.RegistryBasedServlet;
public class MyConsoleServlet extends RegistryBasedServlet {
private static final long serialVersionUID = -1975392591408983229L;
public MyConsoleServlet() {
public MyConsoleServlet(Registry registry) {
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
doPost(req, resp);
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
process(req, resp);
protected void process(HttpServletRequest request, HttpServletResponse response) throws IOException {
JSONObject res;
try {
res = getResponse();
} catch (JSONException e) {
throw new GridException(e.getMessage());
private JSONObject getResponse() throws IOException, JSONException {
JSONObject requestJSON = new JSONObject();
ProxySet proxies = this.getRegistry().getAllProxies();
Iterator<RemoteProxy> iterator = proxies.iterator();
JSONArray busyProxies = new JSONArray();
JSONArray freeProxies = new JSONArray();
while (iterator.hasNext()) {
RemoteProxy eachProxy =;
if (eachProxy.isBusy()) {
} else {
requestJSON.put("BusyProxies", busyProxies);
requestJSON.put("FreeProxies", freeProxies);
return requestJSON;

This comment has been minimized.

Copy link

commented Nov 2, 2017

Just in case if any one is wondering about getAssociatedJSON() method... it's removed. You need to use eachProxy.getOriginalRegistrationRequest().toJson()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.