Example usage for org.openqa.selenium.logging.profiler HttpProfilerLogEntry HttpProfilerLogEntry

List of usage examples for org.openqa.selenium.logging.profiler HttpProfilerLogEntry HttpProfilerLogEntry

Introduction

In this page you can find the example usage for org.openqa.selenium.logging.profiler HttpProfilerLogEntry HttpProfilerLogEntry.

Prototype

public HttpProfilerLogEntry(String commandName, boolean isStart) 

Source Link

Usage

From source file:com.jobaline.uiautomation.framework.selenium.phantomJsThreeHourTimeoutFix.HttpCommandExecutor.java

License:Apache License

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 w  w  . jav  a  2s  .  com
        if (!GET_ALL_SESSIONS.equals(command.getName()) && !NEW_SESSION.equals(command.getName())) {
            throw new SessionNotFoundException("Session ID is null. Using WebDriver after calling quit()?");
        }
    }

    CommandInfo info = nameToUrl.get(command.getName());
    try {
        HttpUriRequest httpMethod = info.getMethod(remoteServer, command);

        setAcceptHeader(httpMethod);

        if (httpMethod instanceof HttpPost) {
            String payload = new BeanToJsonConverter().convert(command.getParameters());
            ((HttpPost) httpMethod).setEntity(new StringEntity(payload, "utf-8"));
            httpMethod.addHeader("Content-Type", "application/json; charset=utf-8");
        }

        // Do not allow web proxy caches to cache responses to "get" commands
        if (httpMethod instanceof HttpGet) {
            httpMethod.addHeader("Cache-Control", "no-cache");
        }

        log(LogType.PROFILER, new HttpProfilerLogEntry(command.getName(), true));
        HttpResponse response = fallBackExecute(context, httpMethod);
        log(LogType.PROFILER, new HttpProfilerLogEntry(command.getName(), false));

        response = followRedirects(client, context, response, /* redirect count */0);

        final EntityWithEncoding entityWithEncoding = new EntityWithEncoding(response.getEntity());

        return createResponse(response, context, entityWithEncoding);
    } 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;
    }
}

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 a 2 s.  com
        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;
    }
}