1

I'm trying to build a groovy script that connects to a website. The webaddress ends in a non-standard format .abc.

I had this snippet of code working on a Linux box and now I am moving it over to a Windows box. The Windows box throws an UnknownHostException and fails.The website does render in browsers on both Linux and Windows.

def url = 'http://www.testURL.abc'
def connection = new URL(url).openConnection()
if (connection.responseCode != 200)
   <<Error Handling>>

I believe it may be a proxy issue since both the Windows and Linux boxes are using different proxies to connect. I looked into this and configured Java on each box to use the proxy of the browser which didn't help either. At this point, I'm somewhat stuck. Any help would be greatly appreciated.

EDIT* Both proxies are using automatic configuration scripts (.pac files) ** Updated syntax errors from copying them over

skarp133
  • 13
  • 3
  • Nothing about that sample you posted is correct. `www.textURL.abc` is not a valid complete URL because there's no protocol (e.g: `http`) and no port — you need to specify one or the other to make a connection. Second, there is no `openConnection()` on `String`, so that line fails compilation. Please provide a valid example of your code. – OverZealous Dec 13 '11 at 18:07

1 Answers1

0

I ended up finding a solution through the proxy issue. I had to download the automatic configuration script (.pac file) and find out which proxy host and port were being used for my URL.

I had to set the proxy host and port with the following code:

ProxySelector.setDefault(new ProxySelector() {

    @Override
    public void connectFailed(URI uri, SocketAddress sa, IOException ioe) {
        throw new RuntimeException("Proxy connect failed", ioe);
    }

    @Override
    public List select(URI uri) {
        return Arrays
            .asList(new Proxy(Proxy.Type.HTTP,
                              new InetSocketAddress(proxyHost,
                                                    proxyPort)));
    }
});

This was code from unknown host exception

Community
  • 1
  • 1
skarp133
  • 13
  • 3