Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the valid regular expression formats for the nonProxyHosts property in Java?

Tags:

java

regex

proxy

When using the proxyHost, proxyPort and nonProxyHosts properties in Java to modify a URL connection, what are the valid uses of wildcards in the nonProxyHosts property? Could I do any or all of the following?

  1. explicit server name: nonProxyHosts=server.company.com
  2. any server in subdomain: nonProxyHosts=*.local.company.com
  3. specific server by IP address: nonProxyHosts=192.168.101.110
  4. any server in subnet: nonProxyHosts=192.168.101.*
  5. any server in subnet: nonProxyHosts=192.168.101/23

Are there other types of patterns?

Thanks!

like image 806
Joe Casadonte Avatar asked Nov 01 '10 21:11

Joe Casadonte


1 Answers

Check out the OpenJDK source for sun.net.spi.DefaultProxySelector and sun.misc.Regexp classes. The nonProxyHosts System property gets processed there for the Sun JVM. The Regexp class was written by the Java man himself, James Gosling, according to the @author javadoc comment. All it does is match * regular expressions, anywhere in a string (start, middle and end). So, you can do partial hostnames as well as partial IP addresses, such as host12* or 10.* to match all hostnames starting with host12 or all IPs starting with 10.. Also, DefaultProxySelector detects localhost and 127.0.0.1 in proxied URLs and automatically excludes them. So you don't need to add those to your nonProxyHosts as far as the Sun JVM is concerned.

Now, in Weblogic it seems they have their own weblogic.net classes that operate with the same Sun System net properties, but not always the same way. I don't have the Weblogic source handy, but my point is, it's not only the Sun JDK that uses these properties. YMMV with different proxy implementations out there due to bugs or different semantics or interpretations of the Sun behavior and docs.

The OpenJDK source version I referenced was from openjdk-6 at http://download.java.net/openjdk/jdk6/.

like image 69
user2533784 Avatar answered Sep 19 '22 05:09

user2533784