List of usage examples for org.openqa.selenium.remote.http HttpRequest getQueryParameter
public String getQueryParameter(String name)
From source file:org.openqa.grid.web.servlet.ProxyStatusServlet.java
License:Apache License
private Map<String, Object> getResponse(HttpRequest request) { Map<String, Object> requestJson = null; if (!request.getContentString().isEmpty()) { requestJson = json.toType(request.getContentString(), MAP_TYPE); }//from w w w . j av a2 s .co m Map<String, Object> res = new TreeMap<>(); res.put("success", false); // the id can be specified via a param, or in the json request. String id; if (requestJson == null) { id = request.getQueryParameter("id"); } else { if (!requestJson.containsKey("id")) { res.put("msg", "you need to specify at least an id when call the node status service."); return res; } id = String.valueOf(requestJson.get("id")); } try { URL u = new URL(id); id = "http://" + u.getHost() + ":" + u.getPort(); } catch (MalformedURLException ignore) { // Fall through } // id is defined from here. RemoteProxy proxy = getRegistry().getProxyById(id); if (proxy == null) { res.put("msg", "Cannot find proxy with ID =" + id + " in the registry."); return res; } res.put("msg", "proxy found !"); res.put("success", true); res.put("id", proxy.getId()); res.put("request", proxy.getOriginalRegistrationRequest()); // maybe the request was for more info if (requestJson != null) { // use basic (= no objects ) reflection to get the extra stuff // requested. List<String> methods = getExtraMethodsRequested(requestJson); List<String> errors = new ArrayList<>(); for (String method : methods) { try { Object o = getValueByReflection(proxy, method); res.put(method, o); } catch (Throwable t) { errors.add(t.getMessage()); } } if (!errors.isEmpty()) { res.put("success", false); res.put("errors", errors.toString()); } } return res; }