What are the valid regex formats for the nonProxyHosts property in Java?

When using the proxyHost , proxyPort and nonProxyHosts in Java to change the URL connection, what are the allowed wildcards in the nonProxyHosts property? Can I do any or all of the following?

  • Explicit server name: nonProxyHosts=server.company.com
  • any server in a subdomain: nonProxyHosts=*.local.company.com
  • specific server by IP address: nonProxyHosts=192.168.101.110
  • any server on the subnet: nonProxyHosts=192.168.101.*
  • any server on the subnet: nonProxyHosts=192.168.101/23

Are there other types of patterns?

Thanks!

+4
source share
3 answers

I think the interpretation of a property value is that it defines a pool of regular expressions. If the host matches any expression in the pool (both hosts and expressions are forcedly underestimated), then the proxy server is not used.

Edit:
Or not really. It looks like sun.misc.RegexpPool processing strings that begin or end with the "*" character. So, I think it really comes down only to prefix and suffix characters ...

Edit2:
A quick way to test is to use:

 ProxySelector.getDefault().select(URI.create("...myURI...")); 

Which will return a List<Proxy> . The default proxy selector is sun.net.spi.DefaultProxySelector , but you can override it.

+4
source

http://download.oracle.com/javase/1.4.2/docs/guide/net/properties.html says:

http.nonProxyHosts indicates hosts that should be connected too directly, and not through a proxy server. The value can be a list of hosts, each of which is separated by the | character, and In addition, you can use the wildcard character (*) to match . For instance:

-Dhttp.nonProxyHosts = "* foo.com |. Local".

+1
source

Check the OpenJDK source for the sun.net.spi.DefaultProxySelector and sun.misc.Regexp . The nonProxyHosts System property is handled there for the Sun JVM. The Regexp class was written by the Java person himself, James Gosling, according to a comment by @author javadoc. All he does is regex * anywhere in the line (start, end and end). Thus, you can execute partial host names as well as partial IP addresses, such as host12* or 10.* , to match all host names starting with host12 or all IP addresses starting with 10. .. In addition, DefaultProxySelector detects localhost and 127.0.0.1 in proxy addresses and automatically excludes them. Thus, you do not need to add them to your nonProxyHosts in relation to the Sun JVM.

Now, at Weblogic, it seems that they have their own weblogic.net classes that work with the same Sun System network properties, but not always the same. I do not have a Weblogic source, but, in my opinion, it is not only the Sun JDK that uses these properties. YMMV with various proxy implementations due to errors or different semantics or interpretations of Sun's behavior and documents.

The original version of OpenJDK that I referred to was from openjdk-6 at http://download.java.net/openjdk/jdk6/ .

+1
source

All Articles