Package jp.vmi.selenium.testutils

Source Code of jp.vmi.selenium.testutils.WebProxy

package jp.vmi.selenium.testutils;

import org.jboss.netty.handler.codec.http.HttpRequest;
import org.littleshoot.proxy.DefaultHttpProxyServer;
import org.littleshoot.proxy.HttpProxyServer;
import org.littleshoot.proxy.HttpRequestFilter;
import org.openqa.selenium.net.PortProber;

/**
* Proxy for unit test.
*/
public class WebProxy {

    private int port;

    private HttpProxyServer server;

    private int count = 0;

    /**
     * Start proxy server.
     */
    public void start() {
        port = PortProber.findFreePort();
        server = new DefaultHttpProxyServer(port, new HttpRequestFilter() {
            @Override
            public void filter(HttpRequest httpRequest) {
                count++;
            }
        });
        server.start();
    }

    /**
     * Stop proxy server.
     */
    public void stop() {
        server.stop();
    }

    /**
     * Reset request count.
     */
    public void resetCount() {
        count = 0;
    }

    /**
     * Get request count.
     *
     * @return request count.
     */
    public int getCount() {
        return count;
    }

    /**
     * Get port number.
     *
     * @return port number.
     */
    public int getPort() {
        return port;
    }

    /**
     * Get server name.
     *
     * @return server name.
     */
    public String getServerNameString() {
        return "localhost:" + port;
    }
}
TOP

Related Classes of jp.vmi.selenium.testutils.WebProxy

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.