GroovyWS HTTP Proxy Configuration
May 28, 2009 at 3:03 pm 3 comments
Here’s the story of how I got Groovy 1.6.3 and GroovyWS 0.5.0 to call a SOAP service through an HTTP proxy.
As of 28-May-2009, the GroovyWS website said…
Using proxies
If you are using a proxy for accessing internet, you can use the following environment variables to get rid of it:
- proxyHost
- proxyPort
- proxy.user
- proxy.password
or directly use the following in your proxy.setproxypropertie([:])
I tried to make HTTP proxy configuration work by following their instructions. Unfortunately, the following three ways didn’t work
I used various property naming conventions I saw in the GroovyWS javadocs and other online examples.
//A
proxy.setProxyProperties( [ "proxyHost":"proxy.foo.org", proxyPort:"8080", "proxy.user":"myUsername", "proxy.password":"myPassword" ] )
//B
proxy.setProxyProperties( [ "http.proxyHost":"proxy.foo.org", "http.proxyPort":"8080", "http.proxy.user":"myUsername", "http.proxy.password":"myPassword" ] )
//C
proxy.setProxyProperties( [ proxyHost:"proxy.foo.org", proxyPort:"8080", "http.proxy.user":"myUsername", "proxy.password":"myPassword" ] )
However, these two ways did work
//D
System.setProperty(“http.proxyHost”, “proxy.foo.org”)
System.setProperty(“http.proxyPort”, “8080″)
System.setProperty(“http.proxy.user”, “myUsername”)
System.setProperty(“http.proxy.password”, “myPassword”)
//E
System.setProperty(“proxyHost”, “proxy.foo.org”)
System.setProperty(“proxyPort”, “8080″)
System.setProperty(“proxy.user”, “myUsername”)
System.setProperty(“proxy.password”, “myPassword”)
My conclusion is that either I called setProxyProperties() incorrectly or that it doesn’t work. Setting the system properties directly was the only way I got GroovyWS to work through an HTTP proxy.
Here is the final working script:
import groovyx.net.ws.WSClient System.setProperty("proxyHost", "proxy.foo.org") System.setProperty("proxyPort", "8080") System.setProperty("proxy.user", "myUsername") System.setProperty("proxy.password", "myPassword") WSClient proxy = new WSClient("http://www.w3schools.com/webservices/tempconvert.asmx?WSDL", this.class.classLoader) proxy.initialize() def result = proxy.CelsiusToFahrenheit(0) println "You are probably freezing at ${result} degrees Farhenheit"NOTE: I used the GroovyWS uber jar: groovyws-standalone-0.5.0.jar. Because it was taking too long, I gave up on trying use the GroovyWS minimal jar and then figuring out which CXF dependencies were needed for a simple SOAP client.
1.
Olivier | August 18, 2010 at 11:54 pm
Thanks a lot for the information.
It’s a pity when official documentation does not give correct information!
For me version D and the following one works.
proxy.setProxyProperties(["http.proxyHost":"xxx.xxx.xxx.xxx", "http.proxyPort":"8012", "http.proxy.user":"xxxxx", "http.proxy.password":"xxxxx"])
2. GroovyWS: through proxy and add WS-Security « SourceForge.net: User zmhu | January 13, 2011 at 6:59 pm
[...] Although the official document described how easy it is to configure proxy settings of GroovyWS, it just does not work in real world as you would have expected. There is a post describing this issue and providing a work around. [...]
3.
James Hu | February 10, 2011 at 10:28 pm
Enlightened by this post and after tracing into the source code, I described details behind this problem and suggested another work-around: http://sourceforge.net/userapps/wordpress/zmhu/2011/01/14/groovyws-through-proxy-and-add-ws-security/