Created
February 27, 2017 18:20
-
-
Save anonymous/091d13179377c765f63d7bf4275acc11 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Specify scene file path | |
String filePath = "/hello/world/flashback"; | |
String sceneName = "playbackMe"; | |
SceneMode sceneMode = SceneMode.RECORD; | |
//Optional | |
String proxyHost = "localhost"; | |
int port = 1234; | |
//This three fields are required to record/playback Https traffic | |
InputStream rootCertificateInputStream = ...; | |
String rootCertificatePassphrase = ""; | |
CertificateAuthority certificateAuthority = ...; | |
// 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) | |
.rootCertificateInputStream(rootCertificateInputStream) | |
.rootCertificatePassphrase(rootCertificatePassphrase) | |
.certificateAuthority(certificateAuthority) | |
.mode(sceneMode) | |
.sceneAccessLayer( | |
new SceneAccessLayer(SceneFactory.create(sceneConfiguration), MatchRuleUtils.matchEntireRequest())) | |
.build()) { | |
flashbackRunner.start(); | |
//Write client code below | |
//Before you start, make sure client code is running in the process that | |
//point to trust store which can trust certificate that signd by CA certificate | |
//you created. | |
System.setProperty("javax.net.ssl.trustStore", "dummy cert store"); | |
System.setProperty("javax.net.ssl.trustStorePassword", "dummy password"); | |
//Client code can be as simple as 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 = "https://www.google.com/"; | |
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