Search in sources :

Example 1 with HttpMessageContents

use of net.lightbody.bmp.util.HttpMessageContents in project opennms by OpenNMS.

the class DatabaseReportIT method customizeCapabilities.

// setup proxy and response filter
@Override
protected void customizeCapabilities(DesiredCapabilities caps) {
    proxy = new BrowserMobProxyServer();
    proxy.start(0);
    proxy.addResponseFilter(new ResponseFilter() {

        @Override
        public void filterResponse(HttpResponse response, HttpMessageContents contents, HttpMessageInfo messageInfo) {
            if (isReportDownloadResponse(response)) {
                LOG.info("Report download response received with headers: {}", response.headers().entries());
                try (ByteArrayInputStream input = new ByteArrayInputStream(contents.getBinaryContents());
                    FileOutputStream output = new FileOutputStream(getFile())) {
                    ByteStreams.copy(input, output);
                } catch (IOException e) {
                    Throwables.propagate(e);
                }
            }
        }
    });
    // configure the Browser Mob Proxy as a desired capability
    Proxy seleniumProxy = ClientUtil.createSeleniumProxy(proxy);
    caps.setCapability(CapabilityType.PROXY, seleniumProxy);
}
Also used : Proxy(org.openqa.selenium.Proxy) BrowserMobProxy(net.lightbody.bmp.BrowserMobProxy) ByteArrayInputStream(java.io.ByteArrayInputStream) FileOutputStream(java.io.FileOutputStream) ResponseFilter(net.lightbody.bmp.filters.ResponseFilter) HttpResponse(io.netty.handler.codec.http.HttpResponse) HttpMessageInfo(net.lightbody.bmp.util.HttpMessageInfo) IOException(java.io.IOException) BrowserMobProxyServer(net.lightbody.bmp.BrowserMobProxyServer) HttpMessageContents(net.lightbody.bmp.util.HttpMessageContents)

Aggregations

HttpResponse (io.netty.handler.codec.http.HttpResponse)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 BrowserMobProxy (net.lightbody.bmp.BrowserMobProxy)1 BrowserMobProxyServer (net.lightbody.bmp.BrowserMobProxyServer)1 ResponseFilter (net.lightbody.bmp.filters.ResponseFilter)1 HttpMessageContents (net.lightbody.bmp.util.HttpMessageContents)1 HttpMessageInfo (net.lightbody.bmp.util.HttpMessageInfo)1 Proxy (org.openqa.selenium.Proxy)1