{"id":19368635,"url":"https://github.com/ghusta/http-proxy-with-java","last_synced_at":"2026-06-13T02:32:02.292Z","repository":{"id":148620406,"uuid":"136037799","full_name":"ghusta/http-proxy-with-java","owner":"ghusta","description":"Testing HTTP(S) proxy with Java","archived":false,"fork":false,"pushed_at":"2018-06-06T13:47:03.000Z","size":26,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-06T22:36:00.567Z","etag":null,"topics":["http","java","proxy"],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ghusta.png","metadata":{"files":{"readme":"README.adoc","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-06-04T14:31:43.000Z","updated_at":"2021-05-28T15:57:16.000Z","dependencies_parsed_at":"2023-05-20T17:30:15.865Z","dependency_job_id":null,"html_url":"https://github.com/ghusta/http-proxy-with-java","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ghusta%2Fhttp-proxy-with-java","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ghusta%2Fhttp-proxy-with-java/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ghusta%2Fhttp-proxy-with-java/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ghusta%2Fhttp-proxy-with-java/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ghusta","download_url":"https://codeload.github.com/ghusta/http-proxy-with-java/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240491825,"owners_count":19809977,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["http","java","proxy"],"created_at":"2024-11-10T08:07:25.487Z","updated_at":"2026-06-13T02:31:57.252Z","avatar_url":"https://github.com/ghusta.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"= Overview\n:author: Guillaume Husta\n:toc: auto\n:toclevels: 3\n:icons: font\n\nTesting HTTP(S) proxy with Java.\n\n== References\n\n* https://docs.oracle.com/javase/8/docs/technotes/guides/net/proxies.html[Java Networking and Proxies]\n** *2) System Properties* :\n*** HTTP : `http.proxyHost`, `http.proxyPort`, `http.nonProxyHosts`\n*** HTTPS : `https.proxyHost`, `https.proxyPort`\n*** etc.\n** *3) Proxy class* : `DIRECT`, `HTTP`, `SOCKS`\n** *4) ProxySelector* : used in conjunction with system property `java.net.useSystemProxies`\n\nExample :\n\n_So, in order to create an HTTP proxy object you would call:_\n[source,java]\n----\nSocketAddress addr = new InetSocketAddress(\"webcache.example.com\", 8080);\nProxy proxy = new Proxy(Proxy.Type.HTTP, addr);\n----\n\n== Tools\n\n=== mitmproxy\n\n*mitmproxy* is a free and open source interactive HTTPS proxy.\n\nSee : https://mitmproxy.org/[https://mitmproxy.org/]\n\n==== Modes of Operation\n\nThe client side is used in our case. We can use `regular` or `upstream` modes.\n\nSee : https://docs.mitmproxy.org/stable/concepts-modes/\n\nFor example, the upstream mode :\n\nimage::doc/media/proxy-modes-upstream.png[Upstream Proxy]\n\n== FAQ\n\n=== Potential errors\n\n==== PKIX path building failed / unable to find valid certification path to requested target\n\nTrace :\n\n``\nCaused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target\n``\n\nReason :\n\nA certificate is necessary for accessing HTTPS urls with the JVM.\n\nSolution :\n\nSee :\n\n* https://docs.mitmproxy.org/stable/concepts-certificates/\n* https://docs.oracle.com/cd/E19906-01/820-4916/6ngbm6hri/index.html[Installing a Root Certificate (HTTPS Only)]\n* https://docs.microsoft.com/fr-fr/java/azure/java-sdk-add-certificate-ca-store[Adding a root certificate to the Java CA certificates store]\n\nHow to :\n\nCheck the https://docs.oracle.com/javase/8/docs/technotes/tools/unix/keytool.html[keytool] syntax :\n\n```\nkeytool -importcert -help\n```\n\nNOTE: `-import` is an alias for `-importcert`.\n\nImport the certificate for Java :\n```\nkeytool -importcert -trustcacerts -alias mitmproxyca -file ./mitmproxy-ca-cert.cer -keystore ./mitmproxycacert.jks -noprompt\n```\n\nWARNING: If having this problem : _ERROR \"keytool : java.util.IllegalFormatConversionException: d != java.lang.String\"_\nTry adding `-J-Duser.language=en` to the command.\n\nCheck it's OK :\n\n```\nkeytool -list -keystore ./mitmproxycacert.jks [-rfc]\n```\n\nThen to make it work with Java, we can use the following system properties :\n\n* `javax.net.ssl.trustStore` : location of the trust store\n* `javax.net.ssl.trustStorePassword` : password for the trust store\n\n==== Test with proxy returns HTTP 502 instead of 200\n\nMaybe _mitmproxy_ is badly configured.\n\nHTTP code 502 means `Bad Gateway or Proxy Error`.\n\nHere is an example of what is logged on the _mitmproxy_ side :\n```\nGET https://github.com/\n    ← Server connection to ('github.com', 443) failed: Error connecting to \"github.com\": [Errno -3] Try again\n```\n\n_Generated with Asciidoctor {asciidoctor-version}_","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fghusta%2Fhttp-proxy-with-java","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fghusta%2Fhttp-proxy-with-java","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fghusta%2Fhttp-proxy-with-java/lists"}