List of usage examples for org.openqa.selenium.remote Response getSessionId
public String getSessionId()
From source file:org.aludratest.service.gui.web.selenium.selenium2.AludraSeleniumHttpCommandExecutor.java
License:Apache License
private Response createResponse(HttpResponse httpResponse, HttpContext context) throws IOException { org.openqa.selenium.remote.http.HttpResponse internalResponse = new org.openqa.selenium.remote.http.HttpResponse(); internalResponse.setStatus(httpResponse.getStatusLine().getStatusCode()); for (Header header : httpResponse.getAllHeaders()) { for (HeaderElement headerElement : header.getElements()) { internalResponse.addHeader(header.getName(), headerElement.getValue()); }// w ww . j a v a 2s . c om } HttpEntity entity = httpResponse.getEntity(); if (entity != null) { try { internalResponse.setContent(EntityUtils.toByteArray(entity)); } finally { EntityUtils.consume(entity); } } Response response = responseCodec.decode(internalResponse); if (response.getSessionId() == null) { HttpHost finalHost = (HttpHost) context.getAttribute(HttpCoreContext.HTTP_TARGET_HOST); String uri = finalHost.toURI(); String sessionId = HttpSessionId.getSessionId(uri); response.setSessionId(sessionId); } return response; }
From source file:org.uiautomation.ios.server.servlet.IOSServlet.java
License:Apache License
private void process(HttpServletRequest request, HttpServletResponse response) throws Exception { WebDriverLikeRequest req = new WebDriverLikeRequest(request); response.setContentType("application/json;charset=UTF-8"); response.setCharacterEncoding("UTF-8"); try {/*from w w w. j av a 2 s. co m*/ response.setStatus(200); Response resp = getResponse(req); // TODO implement the json protocol properly. if (req.getGenericCommand() == WebDriverLikeCommand.NEW_SESSION && resp.getStatus() == 0) { response.setStatus(301); String session = resp.getSessionId(); if (session == null || session.isEmpty()) { response.setStatus(500); } String scheme = request.getScheme(); // http String serverName = request.getServerName(); // hostname.com int serverPort = request.getServerPort(); // 80 String contextPath = request.getContextPath(); // /mywebapp // Reconstruct original requesting URL String url = scheme + "://" + serverName + ":" + serverPort + contextPath; response.setHeader("location", url + "/session/" + session); } // String s = toString(resp); BeanToJsonConverter convertor = new BeanToJsonConverter(); String s = convertor.convert(resp); // status is also used for debugging, it's worth formatting it nice. if (req.getGenericCommand() == WebDriverLikeCommand.STATUS) { JSONObject o = new JSONObject(s); response.getWriter().print(o.toString(2)); } else { response.getWriter().print(s); } } catch (WebDriverException e) { response.setStatus(500); response.getWriter().print(serializeException(e)); throw new WebDriverException("Error processing response." + e.getMessage(), e); } finally { response.getWriter().close(); } }
From source file:org.uiautomation.ios.server.servlet.IOSServlet.java
License:Apache License
private String toString(Response r) throws Exception { JSONObject o = new JSONObject(); o.put("sessionId", r.getSessionId()); o.put("status", r.getStatus()); o.put("value", r.getValue().toString()); return o.toString(); }
From source file:org.uiautomation.ios.server.servlet.UIAScriptServlet.java
License:Apache License
private void getResponse(HttpServletRequest request, HttpServletResponse response) throws Exception, JSONException { if (request.getInputStream() != null) { StringWriter writer = new StringWriter(); IOUtils.copy(request.getInputStream(), writer, "UTF-8"); String json = writer.toString(); json = Normalizer.normalize(json, LanguageDictionary.norme); UIAScriptResponse r = new UIAScriptResponse(json); if (r.isFirstResponse()) { log.fine("got first response"); Response resp = r.getResponse(); GetCapabilitiesNHandler.setCachedResponse(resp); getDriver().getSession(resp.getSessionId()).communication().registerUIAScript(); } else {// w ww. ja v a 2 s . c om communication(request).setNextResponse(r); } log.fine("wait for next command"); UIAScriptRequest nextCommand = communication(request).getNextCommand(); String script = nextCommand.getScript(); log.fine("got " + script); response.setContentType("text/html"); response.setCharacterEncoding("UTF-8"); response.setStatus(200); response.getWriter().print(script); response.getWriter().close(); } }
From source file:sf.wicklet.test.support.SeleniumTestUtil.java
License:Apache License
public static void debugprint(final FirefoxDriver driver, final boolean debug, final StepWatch timer, final String url, final Response response) { if (debug) {/*from w w w. j a va 2s . c om*/ System.out.println("###"); System.out.println("### " + url); System.out.println("###"); System.out.println(timer.toString("Page title is: " + driver.getTitle())); System.out.println(response.getValue()); System.out.println("# sessionId: " + response.getSessionId()); System.out.println("# status: " + response.getStatus()); } }