Build the app and run tests.
mvn clean packageRun the app itself.
java -cp target/my-app-1.0-SNAPSHOT.jar com.mycompany.app.AppInstall mitmproxy.
sudo apt update
sudo apt install mitmproxyStart the proxy.
mitmproxyWe can test it by making a curl request through the mitmproxy proxy.
curl --proxy http://127.0.0.1:8080 "https://example.org"To intercepts Javas HTTP requests, we need to install the mitmproxy ca cert in javas keystore.
sudo keytool -importcert -file ~/.mitmproxy/mitmproxy-ca-cert.pem -alias mitmproxy -keystore "$JAVA_HOME/lib/security/cacerts" -storepass changeitFinally we invoke maven and make it use the proxy when building and running tests:
mvn clean package -Dhttp.proxyHost=localhost -Dhttp.proxyPort=8080 -Dhttps.proxyHost=localhost -Dhttps.proxyPort=8080Intercepting mTLS requires setting up mitmproxy with an upstream client certificate: https://docs.mitmproxy.org/stable/concepts/certificates/#mtls-between-mitmproxy-and-upstream-server