Skip to content

Instantly share code, notes, and snippets.

Created February 17, 2017 21:22
Show Gist options
  • Save anonymous/edcc1d60847d51b159c8fd8a8d0a5f8b to your computer and use it in GitHub Desktop.
Save anonymous/edcc1d60847d51b159c8fd8a8d0a5f8b to your computer and use it in GitHub Desktop.
// Specify scene file path
String filePath = "/hello/world/flashback";
String sceneName = "playbackMe";
SceneMode sceneMode = SceneMode.PLAYBACK;
//Optional
String proxyHost = "localhost";
int port = 1234;
// Create scene config which contains most of scene properties
SceneConfiguration sceneConfiguration = new SceneConfiguration(filePath, sceneMode, sceneName);
// Initialize FlashbackRunner with Scene, MatchRule etc
try (FlashbackRunner flashbackRunner = new FlashbackRunner.Builder().host(proxyHost).port(port).mode(sceneMode).sceneAccessLayer(
new SceneAccessLayer(SceneFactory.create(sceneConfiguration), MatchRuleUtils.matchEntireRequest())).build()) {
flashbackRunner.start();
//Write client code below
//It can be any standard Http call. I use Apache HttpClient as an example.
//Just make sure your request go through proxy that we specified above(host, port)
HttpHost host = new HttpHost(proxyHost, port);
String url = "http://www.example.org/";
HttpClient client = HttpClientBuilder.create().setProxy(host).build();
HttpGet request = new HttpGet(url);
HttpResponse httpResponse = client.execute(request);
//End of client code
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment