net.lightbody.bmp.filters.ResponseFilter Java Examples

The following examples show how to use net.lightbody.bmp.filters.ResponseFilter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultModule.java    From bromium with MIT License 6 votes vote down vote up
@CheckedProvides(IOProvider.class)
public ResponseFilter getResponseFilter(@Named(COMMAND) String command,
                                        ReplayingState replayingState,
                                        @Named(SHOULD_INJECT_JS_PREDICATE) Predicate<HttpRequest> httpRequestPredicate,
                                        @Named(RECORDING_JAVASCRIPT_CODE) IOProvider<String>
                                                    recordingJavascriptCodeProvider,
                                        @Named(REPLAYING_JAVASCRIPT_CODE) IOProvider<String>
                                                    replayingJavascriptCodeProvider) throws IOException {
    switch (command) {
        case RECORD:
            return new RecordResponseFilter(recordingJavascriptCodeProvider.get(), httpRequestPredicate);
        case REPLAY:
            return new ReplayResponseFilter(replayingJavascriptCodeProvider.get(), replayingState, httpRequestPredicate);
        default:
            throw new NoSuchCommandException();
    }
}
 
Example #2
Source File: DefaultModule.java    From bromium with MIT License 6 votes vote down vote up
@CheckedProvides(IOURIProvider.class)
public ProxyDriverIntegrator getProxyDriverIntegrator(IOProvider<RequestFilter> requestFilterIOProvider,
                                                      IOProvider<ResponseFilter> responseFilterIOURIProvider,
                                                      WebDriverSupplier webDriverSupplier,
                                                      DriverServiceSupplier driverServiceSupplier,
                                                      @Named(PATH_TO_DRIVER) String pathToDriverExecutable,
                                                      @Named(SCREEN) String screen,
                                                      @Named(TIMEOUT) int timeout) throws IOException, URISyntaxException {
    return getProxyDriverIntegrator(requestFilterIOProvider.get(),
            webDriverSupplier,
            driverServiceSupplier,
            pathToDriverExecutable,
            screen,
            timeout,
            responseFilterIOURIProvider.get());
}
 
Example #3
Source File: DefaultModule.java    From bromium with MIT License 6 votes vote down vote up
private ProxyDriverIntegrator getProxyDriverIntegrator(RequestFilter recordRequestFilter,
                                                       WebDriverSupplier webDriverSupplier,
                                                       DriverServiceSupplier driverServiceSupplier,
                                                       @Named(PATH_TO_DRIVER) String pathToDriverExecutable,
                                                       @Named(SCREEN) String screen,
                                                       @Named(TIMEOUT) int timeout,
                                                       ResponseFilter responseFilter) throws IOException {
    BrowserMobProxy proxy = createBrowserMobProxy(timeout, recordRequestFilter, responseFilter);
    proxy.start(0);
    logger.info("Proxy running on port " + proxy.getPort());
    Proxy seleniumProxy = createSeleniumProxy(proxy);
    DesiredCapabilities desiredCapabilities = createDesiredCapabilities(seleniumProxy);
    DriverService driverService = driverServiceSupplier.getDriverService(pathToDriverExecutable, screen);
    WebDriver driver = webDriverSupplier.get(driverService, desiredCapabilities);

    return new ProxyDriverIntegrator(driver, proxy, driverService);
}
 
Example #4
Source File: DefaultModuleTest.java    From bromium with MIT License 6 votes vote down vote up
@Test
public void ifCommmandIsInvalidResponseExceptionIsThrown() throws IOException, URISyntaxException {
    String command = "invalid";
    Map<String, Object> opts = new HashMap<>();
    opts.put(BROWSER, CHROME);
    opts.put(DRIVER, chromedriverFile.getAbsolutePath());
    opts.put(APPLICATION, configurationFile.getAbsolutePath());
    opts.put(URL, localhostUrl);
    opts.put(CASE, caseFile.getAbsolutePath());
    opts.put(SCREEN, screenString);
    opts.put(TIMEOUT, timeoutString);
    opts.put(PRECISION, precisionString);
    Module module = new DefaultModule(command, opts);
    Injector injector = Guice.createInjector(module);

    try {
        IOProvider<ResponseFilter> instance = injector.getInstance(new Key<IOProvider<ResponseFilter>>() {});
        instance.get();
    } catch (ProvisionException e) {
        assertTrue(e.getCause() instanceof NoSuchCommandException);
    }
}
 
Example #5
Source File: DeviceUtils.java    From AndroidHttpCapture with MIT License 6 votes vote down vote up
public static void changeResponseFilter(SysApplication sysApplication,final List<ResponseFilterRule> ruleList){
    if(ruleList == null){
        Log.e("~~~~","changeResponseFilter ruleList == null!");
        return;
    }

    sysApplication.proxy.addResponseFilter(new ResponseFilter() {
        @Override
        public void filterResponse(HttpResponse response, HttpMessageContents contents, HttpMessageInfo messageInfo) {
            for (ResponseFilterRule rule: ruleList) {
                if(rule.getEnable()) {
                    if (contents.isText() && messageInfo.getUrl().contains(rule.getUrl())) {
                        String originContent = contents.getTextContents();
                        if (originContent != null) {
                            contents.setTextContents(contents.getTextContents().replaceAll(
                                    rule.getReplaceRegex(), rule.getReplaceContent()));
                        }
                    }
                }
            }
        }
    });
}
 
Example #6
Source File: DefaultModule.java    From bromium with MIT License 5 votes vote down vote up
public BrowserMobProxy createBrowserMobProxy(int timeout, RequestFilter requestFilter, ResponseFilter responseFilter) {
    BrowserMobProxyServer proxy = new BrowserMobProxyServer();
    proxy.enableHarCaptureTypes(CaptureType.REQUEST_CONTENT, CaptureType.RESPONSE_CONTENT);
    proxy.newHar("measurements");
    proxy.addRequestFilter(requestFilter);
    proxy.addResponseFilter(responseFilter);
    proxy.setIdleConnectionTimeout(timeout, TimeUnit.SECONDS);
    proxy.setRequestTimeout(timeout, TimeUnit.SECONDS);
    return proxy;
}
 
Example #7
Source File: BrowsermobProxyUtilsImpl.java    From IridiumApplicationTesting with MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked")
private void trackErrorResponses(
	final BrowserMobProxy proxy,
	final ProxyDetails<BrowserMobProxy> proxyDetails) {

	proxy.addResponseFilter(new ResponseFilter() {
		@Override
		public void filterResponse(
			final HttpResponse response,
			final HttpMessageContents contents,
			final HttpMessageInfo messageInfo) {

			/*
				Track anything other than a 200 range response
			 */
			if (response.getStatus().code() >= START_HTTP_ERROR
				&& response.getStatus().code() <= END_HTTP_ERROR) {

				synchronized (proxyDetails) {
					final Map<String, Object> properties = proxyDetails.getProperties();
					if (!properties.containsKey(INVALID_REQUESTS)) {
						properties.put(
							INVALID_REQUESTS,
							new ArrayList<HttpMessageInfo>());
					}
					ArrayList.class.cast(properties.get(INVALID_REQUESTS)).add(messageInfo);
					proxyDetails.setProperties(properties);
				}
			}
		}
	});
}
 
Example #8
Source File: BrowserMobProxyServer.java    From CapturePacket with MIT License 2 votes vote down vote up
/**
 * <b>Note:</b> The current implementation of this method forces a maximum response size of 2 MiB. To adjust the maximum response size, or
 * to disable aggregation (which disallows access to the {@link net.lightbody.bmp.util.HttpMessageContents}), you may add the filter source
 * directly: <code>addFirstHttpFilterFactory(new ResponseFilterAdapter.FilterSource(filter, bufferSizeInBytes));</code>
 */
@Override
public void addResponseFilter(ResponseFilter filter) {
    addLastHttpFilterFactory(new ResponseFilterAdapter.FilterSource(filter));
}
 
Example #9
Source File: BrowserMobProxy.java    From CapturePacket with MIT License 2 votes vote down vote up
/**
 * Adds a new ResponseFilter that can be used to examine and manipulate the response before sending it to the client.
 *
 * @param filter filter instance
 */
void addResponseFilter(ResponseFilter filter);
 
Example #10
Source File: BrowserMobProxyServer.java    From Dream-Catcher with MIT License 2 votes vote down vote up
/**
 * <b>Note:</b> The current implementation of this method forces a maximum response size of 2 MiB. To adjust the maximum response size, or
 * to disable aggregation (which disallows access to the {@link net.lightbody.bmp.util.HttpMessageContents}), you may add the filter source
 * directly: <code>addFirstHttpFilterFactory(new ResponseFilterAdapter.FilterSource(filter, bufferSizeInBytes));</code>
 */
@Override
public void addResponseFilter(ResponseFilter filter) {
    addLastHttpFilterFactory(new ResponseFilterAdapter.FilterSource(filter));
}
 
Example #11
Source File: BrowserMobProxy.java    From Dream-Catcher with MIT License 2 votes vote down vote up
/**
 * Adds a new ResponseFilter that can be used to examine and manipulate the response before sending it to the client.
 *
 * @param filter filter instance
 */
void addResponseFilter(ResponseFilter filter);
 
Example #12
Source File: BrowserMobProxyServer.java    From AndroidHttpCapture with MIT License 2 votes vote down vote up
/**
 * <b>Note:</b> The current implementation of this method forces a maximum response size of 2 MiB. To adjust the maximum response size, or
 * to disable aggregation (which disallows access to the {@link net.lightbody.bmp.util.HttpMessageContents}), you may add the filter source
 * directly: <code>addFirstHttpFilterFactory(new ResponseFilterAdapter.FilterSource(filter, bufferSizeInBytes));</code>
 */
@Override
public void addResponseFilter(ResponseFilter filter) {
    addLastHttpFilterFactory(new ResponseFilterAdapter.FilterSource(filter));
}
 
Example #13
Source File: BrowserMobProxy.java    From AndroidHttpCapture with MIT License 2 votes vote down vote up
/**
 * Adds a new ResponseFilter that can be used to examine and manipulate the response before sending it to the client.
 *
 * @param filter filter instance
 */
void addResponseFilter(ResponseFilter filter);