Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » scout » Using IOUtility from behind an authenticating proxy
Using IOUtility from behind an authenticating proxy [message #1067544] Tue, 09 July 2013 09:33 Go to next message
Urs Beeli is currently offline Urs Beeli
Messages: 335
Registered: October 2012
Location: Bern, Switzerland
Senior Member
The Scout Book uses the following call in various places:
IOUtility.getContent(url.openStream())


However, as I am sitting behind an authenticating proxy, this fails with the following exception:
java.net.ConnectException: Connection timed out: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)


After some googling I added the following code to Desktop.initConfig():
      System.setProperty("http.proxyHost", "proxy.<our org>.ch");
      System.setProperty("http.proxyPort", "8080");

      Authenticator.setDefault(new Authenticator() {
        @Override
        protected PasswordAuthentication getPasswordAuthentication() {
          // Decision logic here (sets username and password values)
          return new PasswordAuthentication("<my username>", "<my password>".toCharArray());
        }
      });

(obviously I have replaced sensitive information with <...> tags for this post.

However, this causes the following console output:
!ENTRY org.eclipse.core.net 1 0 2013-07-09 11:26:18.750
!MESSAGE System property http.proxyHost has been set to proxy.<our org>.ch by an external source. This value will be overwritten using the values from the preferences

!ENTRY org.eclipse.core.net 1 0 2013-07-09 11:26:18.751
!MESSAGE System property http.proxyPort has been set to 8080 by an external source. This value will be overwritten using the values from the preferences

And I still run into the timeout.

I have two questions:

  • how do I set the proxy port and address for the scout client and server
  • how do I pass authentication information for the proxy along (this may differ from the credentials used for logging into the scout app)?


The scout book also uses the org.scribe library, which fails for the same reason. Is there a way to set up the proxy in scout so the library can also use this, or do I have to find a library specific solution for this?
Re: Using IOUtility from behind an authenticating proxy [message #1067703 is a reply to message #1067544] Wed, 10 July 2013 08:10 Go to previous messageGo to next message
Urs Beeli is currently offline Urs Beeli
Messages: 335
Registered: October 2012
Location: Bern, Switzerland
Senior Member
Ok, I've come a few steps closer. In a standalone J2SE project, using System.setProperty() seems to work nicely. Not so in an eclipse RCP project. After looking at this page I tried the following code to see what the current proxy config is:

      ServiceTracker proxyTracker = new ServiceTracker(FrameworkUtil.getBundle(this.getClass()).getBundleContext(), IProxyService.class.getName(), null);
      proxyTracker.open();
      IProxyService proxyService = (IProxyService) proxyTracker.getService();
      System.out.println("Proxies");
      for (IProxyData p : proxyService.getProxyData()) {
        System.out.println("  -" + p);
      }
      System.out.println("Proxies for www.linkedin.com");
      for (IProxyData p : proxyService.select(new URI("https://www.linkedin.com"))) {
        System.out.println("  -" + p);
      }


At first run, this yielded three entries for getProxyData():
- null:-1, <my userid>, <my password>, HTTP
- null:-1, <my userid>, <my password>, HTTPS
- null:-1, null, null, SOCKS
The result for the select() call was empty.

Checking in Eclipse's preferences there was indeed neither hostname nor port defined for HTTP and HTTPS (but the username and passwords were set).
I added the proxy information for the two protocols, but the output stayed the same.

I then added the following code:
      ProxyData np = new ProxyData(IProxyData.HTTP_PROXY_TYPE, "proxy.<our domain>", 8080, true, "");
      ProxyData nps = new ProxyData(IProxyData.HTTPS_PROXY_TYPE, "proxy.<our domain>", 8080, true, "");
      np.setUserid("<my userid>");
      np.setPassword("<my password>");
      nps.setUserid("<my userid>");
      nps.setPassword("<my password>");
      proxyService.setProxyData(new IProxyData[] { np, nps });
      for (IProxyData p : proxyService.getProxyData()) {
        System.out.println("  -" + p);
      }
      System.out.println("Proxies for www.linkedin.com");
      for (IProxyData p : proxyService.select(new URI("https://www.linkedin.com"))) {
        System.out.println("  -" + p);
      }


This now yields the following output for getProxyData():
- proxy.<our domain>:8080 <my userid>, <my password>, HTTP
- proxy.<our domain>:8080 <my userid>, <my password>, HTTPS
- null:-1, null, null, SOCKS
And the select call now returns:
- proxy.<our domain>:8080 <my userid>, <my password>, HTTPS

Interestingly enough, this seems to be persisted somewhere in the eclipse SDK settings, because if I edit those, the SDK warns me that I'm about to overwrite them.

Doing this in Desktop.initConfig makes the client side network access work (I now see the image of Alice in Wonderland and I can show Google maps for her address instead of running into a timeout).

However, doing the same in LinkedInService.initializeService makes no difference to the following calle:
Token requestToken = m_service.getRequestToken();

that still results in a timeout. Also, if I use the same code used in my standalone J2EE program to just read any web page using new BufferedInputStream(new URL("www.linkedin.com").openStream()) runs into a timeout, too.

It seems that in the client, network access uses the eclipse plattform's proxy configuration (though it does not use System.getProperty(proxy.*)) but in the server, neither of the two methods are used...

Does anyone have an idea what could be the reason for this?
Re: Using IOUtility from behind an authenticating proxy [message #1067706 is a reply to message #1067703] Wed, 10 July 2013 08:32 Go to previous messageGo to next message
Urs Beeli is currently offline Urs Beeli
Messages: 335
Registered: October 2012
Location: Bern, Switzerland
Senior Member
Just an idea: Considering that the server is running in a Jetty container, do we need to configure the proxy in jetty? And if so, how is that done?
Re: Using IOUtility from behind an authenticating proxy [message #1075335 is a reply to message #1067706] Mon, 29 July 2013 09:01 Go to previous message
Urs Beeli is currently offline Urs Beeli
Messages: 335
Registered: October 2012
Location: Bern, Switzerland
Senior Member
A brief update:

  • adding a proxy to the client using a ProxyService lets us use IOUtility.getContent()
  • adding a proxy to the server using a ProxyService in order to use the Scribe library does not work
  • my colleague imported the Scribe library as source and created its own plugin, so he could debug it. It seems that OAuth uses https, which explains why setting a proxy using
    System.setProperty("http.proxyHost", "proxy.<our org>.ch");
    System.setProperty("http.proxyPort", "8080");

    didn't work. However, when adding
    System.setProperty("https.proxyHost", "proxy.<our org>.ch");
    System.setProperty("https.proxyPort", "8080");
    as well, some progress is made. However, there is a line in Scribe which sets "http.keepAlive" which seems to cause our proxy to choke (or maybe it is jetty?), when that line was commented out, it all worked
  • out of curiosity I moved the whole LinkedInService from the server to the client (where the proxy is defined using a ProxyService)
    This works flawlessly and the "http.keepAlive" property seems to not cause any trouble, either

Previous Topic:Supporting disabled buttons and toggle buttons on the toolbar
Next Topic:Where are the transaction boundaries?
Goto Forum:
  


Current Time: Tue Oct 21 21:51:20 GMT 2014

Powered by FUDForum. Page generated in 0.11330 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software