har-replay

Library that manages a proxy server that replays traffic from a HAR

License

License

GroupId

GroupId

com.github.mike10004
ArtifactId

ArtifactId

har-replay
Last Version

Last Version

0.32
Release Date

Release Date

Type

Type

pom
Description

Description

har-replay
Library that manages a proxy server that replays traffic from a HAR
Project URL

Project URL

https://github.com/mike10004/har-replay
Source Code Management

Source Code Management

https://github.com/mike10004/har-replay

Download har-replay

Filename Size
har-replay-0.32.pom 21 KB
Browse

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.mike10004/har-replay/ -->
<dependency>
    <groupId>com.github.mike10004</groupId>
    <artifactId>har-replay</artifactId>
    <version>0.32</version>
    <type>pom</type>
</dependency>
// https://jarcasting.com/artifacts/com.github.mike10004/har-replay/
implementation 'com.github.mike10004:har-replay:0.32'
// https://jarcasting.com/artifacts/com.github.mike10004/har-replay/
implementation ("com.github.mike10004:har-replay:0.32")
'com.github.mike10004:har-replay:pom:0.32'
<dependency org="com.github.mike10004" name="har-replay" rev="0.32">
  <artifact name="har-replay" type="pom" />
</dependency>
@Grapes(
@Grab(group='com.github.mike10004', module='har-replay', version='0.32')
)
libraryDependencies += "com.github.mike10004" % "har-replay" % "0.32"
[com.github.mike10004/har-replay "0.32"]

Dependencies

compile (1)

Group / Artifact Type Version
com.google.code.findbugs : jsr305 jar 3.0.1

Project Modules

  • virtual-har-server
  • har-replay-core
  • har-replay-exec
  • har-replay-test-support
  • har-replay-vhs
  • har-replay-dist

Travis build status AppVeyor build status Maven Central

har-replay

Java library and executable for serving recorded HTTP responses from a HAR file. To use it, you provide a HAR file, the library instantiates an HTTP proxy server, and you configure your web browser to use the proxy server. The proxy intercepts each request and responds with the corresponding pre-recorded response from the HAR.

Quick Start

Package

Look in https://repo1.maven.org/maven2/com/github/mike10004/har-replay-dist for the latest .deb file or build the parent project to produce one. Execute

$ sudo dpkg --install /path/to/har-replay-deb  

to install the package. (Replace the filename with the downloaded file or the build product.)

Execute

$ har-replay --port 56789 /path/to/my.har

to start an HTTP proxy on port 56789 serving responses from /path/to/my.har.

Library

Maven dependency:

<dependency>
    <groupId>com.github.mike10004</groupId>
    <artifactId>har-replay-vhs</artifactId>
    <version>0.26</version> <!-- use latest version -->
</dependency>

See Maven badge above for the actual latest version. Example code:

File harFile = new File("my-session.har");
ReplaySessionConfig sessionConfig = ReplaySessionConfig.usingTempDir().build(harFile);
VhsReplayManagerConfig config = VhsReplayManagerConfig.getDefault();
ReplayManager replayManager = new VhsReplayManager(config);
try (ReplaySessionControl sessionControl = replayManager.start(sessionConfig)) {
    URL url = new URL("http://www.example.com/");
    Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("localhost", sessionControl.getListeningPort()));
    HttpURLConnection conn = (HttpURLConnection) url.openConnection(proxy);
    try {
        System.out.format("served from HAR: %s %s %s%n", conn.getResponseCode(), conn.getResponseMessage(), url);
        // do something with the connection...
    } finally {
        conn.disconnect();
    }
}

(Imports are from the library and the java.net package.)

The unit tests contain some examples of using the library with an Apache HTTP client and a Selenium Chrome WebDriver client.

FAQ

How do I create a HAR?

See https://toolbox.googleapps.com/apps/har_analyzer/ for instructions on using your web browser to create a HAR file. Another option is to use browsermob-proxy to capture a HAR. The Browsermob method captures some requests the web browser hides from you (because they are trackers or fetch data for browser internals).

Debugging Travis Builds

If the Travis build is failing, you can test locally with Docker by running ./travis-debug.sh. However, the mvn verify command appears to exit early but does not report a nonzero exit code, so it's not clear whether it's actually succeeding or something funky is going on. It should be useful for debugging failures that happen earlier, though. If the failure you see on Travis happens later on in mvn verify, you can follow the Travis Troubleshooting in a local container instructions, which say to execute:

$ docker run --name travis-debug -dit $TRAVIS_IMAGE /sbin/init
$ docker exec -it travis-debug bash -l 

This puts you inside the container, where you can su -l travis, clone the repo, and proceed manually from there.

Versions

Version
0.32
0.31
0.30
0.29
0.28
0.27
0.26
0.25
0.21
0.20
0.12
0.11
0.10
0.9
0.8
0.7
0.6
0.5
0.3
0.2