JoeG
JoeG

Reputation: 7642

NonProxyHosts usage with Groovy HttpBuilder

If I create my httpBuilder as shown below (assume that a proxyUsername IS set, so setCredentials is called), then calls to httpAddress-es that are passed in properly are routed through the proxy. However, the Application has some http calls that are within the local network. Can http.nonProxyHosts be used to work around this and bypass the Proxy? If so, how? Use System.setProperty? Or something on HttpBuilder?

    HTTPBuilder httpBuilder = new HTTPBuilder(httpAddress)
    httpBuilder.setProxy(webProxyHost, webProxyPort, webProxyProtocol)
    if (proxyUsername) {
        httpBuilder.client.getCredentialsProvider().setCredentials(
                    new AuthScope(webProxyHost, webProxyPort),
                    new UsernamePasswordCredentials(proxyUsername, proxyPassword))
        }
    }

In the code above, all of the various named elements (webProxyHost, etc) are declared as String and set accordingly.

Upvotes: 1

Views: 417

Answers (1)

JoeG
JoeG

Reputation: 7642

In answer to the question in the above comment, our primary 'nonProxyHost' need was for 'localhost' which is there by default. Thus this ceased to be an issue. Did not ever really find out how to accomplish this as it is somewhat version-specific on HttpClient.

You can set the System property:

System.setProperty('http.nonProxyHosts', myNonProxyHosts)

However, if you call 'setProxy' on HttpBuilder, even if you call 'useSystemProperties' it will not. This is in their documentation, just not obvious!

Finally, you might be able to call:

httpBuilder.client.params.setParameter('http.nonProxyHosts', myNonProxyHosts)

But I do not know for sure if that is the property name and documentation of those properties is hard to find. Worse - those 'params' are deprecated - you are supposed to use the better 'config' classes, though once again finding comprehensive documentation on all the parameters for that is not the easiest! Wish I could have been of more help!

Upvotes: 0

Related Questions