Pass Through a Corporate Proxy in Java

TL;DR: There’s no easy way to create a proxy :)

I’ve tried for a while to build a way to request something through a proxy, for testing an emulated android app. The solution came from Octavian who kindly provided me a snippet to run once per app lifetime. It tackles the problem from two fronts:

  1. Sets proxy system properties (http.proxy* and https.proxy*)
  2. Sets the default Authenticator

The code is:

One thing that can be improved would be a configuration-based (e.g. defined environment variable) bypass code, rather than a hostname approach.

and the full code (with imports and such) is in this Gist:

NOTE: All credit goes to Tavi for finding and building this.


A little experiment: If you find this post and ad below useful, please check the ad out :-)

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to top