mitmproxy-java

A bridge between Python's mitmproxy and Java programs. Built on top of mitmproxy-node

License

License

Categories

Categories

Java Languages
GroupId

GroupId

io.appium
ArtifactId

ArtifactId

mitmproxy-java
Last Version

Last Version

2.0.1
Release Date

Release Date

Type

Type

jar
Description

Description

mitmproxy-java
A bridge between Python's mitmproxy and Java programs. Built on top of mitmproxy-node
Project URL

Project URL

https://github.com/appium/mitmproxy-java
Source Code Management

Source Code Management

http://github.com/appium/mitmproxy-java/tree/master

Download mitmproxy-java

How to add to project

<!-- https://jarcasting.com/artifacts/io.appium/mitmproxy-java/ -->
<dependency>
    <groupId>io.appium</groupId>
    <artifactId>mitmproxy-java</artifactId>
    <version>2.0.1</version>
</dependency>
// https://jarcasting.com/artifacts/io.appium/mitmproxy-java/
implementation 'io.appium:mitmproxy-java:2.0.1'
// https://jarcasting.com/artifacts/io.appium/mitmproxy-java/
implementation ("io.appium:mitmproxy-java:2.0.1")
'io.appium:mitmproxy-java:jar:2.0.1'
<dependency org="io.appium" name="mitmproxy-java" rev="2.0.1">
  <artifact name="mitmproxy-java" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.appium', module='mitmproxy-java', version='2.0.1')
)
libraryDependencies += "io.appium" % "mitmproxy-java" % "2.0.1"
[io.appium/mitmproxy-java "2.0.1"]

Dependencies

compile (1)

Group / Artifact Type Version
org.apache.commons : commons-collections4 jar 4.0

runtime (7)

Group / Artifact Type Version
org.java-websocket : Java-WebSocket jar 1.4.0
javax.ws.rs : javax.ws.rs-api jar 2.0-m02
com.fasterxml.jackson.core : jackson-core jar 2.9.8
com.fasterxml.jackson.core : jackson-databind jar 2.9.8
org.zeroturnaround : zt-exec jar 1.10
org.zeroturnaround : zt-process-killer jar 1.9
org.slf4j : slf4j-simple jar 1.7.26

test (4)

Group / Artifact Type Version
junit : junit jar 4.12
org.mockito : mockito-all jar 1.10.19
com.mashape.unirest : unirest-java jar 1.4.9
org.assertj : assertj-core jar 3.12.2

Project Modules

There are no modules declared in this project.

Java rendition of node-mitmproxy

Make sure to read the prerequisites section below.

Detailed information included in the AppiumPro article which introduces this library.

Why?

mitmproxy is great for capturing network traffic, but has no easy interface for Java users. The software testing community, specifically Appium mobile testers, want to be able to capture network requests made by devices during their Java tests.

This library will run mitmproxy in the background as a separate process, and allow you to pass in a lambda function which gets called on every network request captured by mitmproxy. This allows you to check the captured requests within you Java code without having to stop the proxy or end capture.

See @jonahss's Appium Pro posts on this topic:

What can I use this for?

For transparently rewriting HTTP/HTTPS responses. The mitmproxy plugin lets every HTTP request go through to the server uninhibited, and then passes it to Java via a WebSocket for rewriting.

How does it work?

mitmproxy-java starts a Websocket server and a Python plugin for mitmproxy connects to it and sends requests over. The two communicate via binary messages to reduce marshaling-related overhead.

Pre-requisites

  • mitmproxy V4 must be installed and runnable from the terminal. The install method cannot be a prebuilt binary or homebrew, since those packages are missing the Python websockets module. Install via pip or from source.
  • Python 3.6, since we use the new async/await syntax in the mitmproxy plugin
  • pip3 install websockets

Maven:

<dependency>
  <groupId>io.appium</groupId>
  <artifactId>mitmproxy-java</artifactId>
  <version>1.6.2</version>
</dependency>

Gradle:

testCompile group: 'io.appium', name: 'mitmproxy-java', version: '1.6.1'

Usage

List<InterceptedMessage> messages = new ArrayList<InterceptedMessage>();

//optional, default port is 8080
int mitmproxyPort = 8090;

//optional, you can pass null if no extra params
List<String> extraMitmproxyParams = Arrays.asList("param1", "value1", "param2", "value2");

// remember to set local OS proxy settings in the Network Preferences
proxy = new MitmproxyJava("/usr/local/bin/mitmdump", (InterceptedMessage m) -> {
    System.out.println("intercepted request for " + m.getRequest().getUrl());
    messages.add(m);
    return m;
}, mitmproxyPort, extraMitmproxyParams);

proxy.start();

// do stuff

proxy.stop();

See AppriumPro article for more guidelines: https://appiumpro.com/editions/65 Example can be found here: https://github.com/cloudgrey-io/appiumpro/blob/master/java/src/test/java/Edition065_Capture_Network_Requests.java

Your Java code is bad and you should feel bad

I'm no Java expert! You may see some bad patterns, like my terrible disregard for exception handling. Let's make it better. File your issues and land some PRs! I wrote this in just a couple days for our weekly newsletter.

Your Python plugin is bad and you should feel bad

See node-mitmproxy. Pull requests welcome!

Develop

Upload to Central Repository with command ./gradlew uploadArchives

io.appium

Appium

Mobile App Automation Made Awesome

Versions

Version
2.0.1
2.0.0
1.6.2
1.6.1
1.6.0
1.5
1.4