List of usage examples for org.openqa.selenium.remote.http HttpRequest getMethod
public HttpMethod getMethod()
From source file:org.aludratest.service.gui.web.selenium.selenium2.AludraSeleniumHttpCommandExecutor.java
License:Apache License
@Override public Response execute(Command command) throws IOException { HttpContext context = new BasicHttpContext(); if (command.getSessionId() == null) { if (QUIT.equals(command.getName())) { return new Response(); }//from w ww . j a v a2 s .co m if (!GET_ALL_SESSIONS.equals(command.getName()) && !NEW_SESSION.equals(command.getName())) { throw new SessionNotFoundException("Session ID is null. Using WebDriver after calling quit()?"); } } HttpRequest request = commandCodec.encode(command); String requestUrl = remoteServer.toExternalForm().replaceAll("/$", "") + request.getUri(); HttpUriRequest httpMethod = createHttpUriRequest(request.getMethod(), requestUrl); for (String name : request.getHeaderNames()) { // Skip content length as it is implicitly set when the message entity is set below. if (!"Content-Length".equalsIgnoreCase(name)) { for (String value : request.getHeaders(name)) { httpMethod.addHeader(name, value); } } } if (httpMethod instanceof HttpPost) { ((HttpPost) httpMethod).setEntity(new ByteArrayEntity(request.getContent())); } if (requestTimeout > 0 && (httpMethod instanceof HttpRequestBase)) { RequestConfig requestConfig = RequestConfig.custom().setConnectionRequestTimeout(15000) .setConnectTimeout(15000).setSocketTimeout(requestTimeout).build(); ((HttpRequestBase) httpMethod).setConfig(requestConfig); } else if (httpMethod instanceof HttpRequestBase) { // ensure Selenium Standard is set RequestConfig requestConfig = RequestConfig.custom().setConnectionRequestTimeout(60000) .setConnectTimeout(60000).setSocketTimeout(THREE_HOURS).build(); ((HttpRequestBase) httpMethod).setConfig(requestConfig); } try { log(LogType.PROFILER, new HttpProfilerLogEntry(command.getName(), true)); HttpResponse response = fallBackExecute(context, httpMethod); log(LogType.PROFILER, new HttpProfilerLogEntry(command.getName(), false)); lastResponse = response; response = followRedirects(client, context, response, /* redirect count */0); lastResponse = response; return createResponse(response, context); } catch (UnsupportedCommandException e) { if (e.getMessage() == null || "".equals(e.getMessage())) { throw new UnsupportedOperationException( "No information from server. Command name was: " + command.getName(), e.getCause()); } throw e; } catch (SocketTimeoutException e) { LoggerFactory.getLogger(AludraSeleniumHttpCommandExecutor.class) .warn("Timeout in HTTP Command Executor. Timeout was " + ((HttpRequestBase) httpMethod).getConfig().getSocketTimeout()); throw e; } }