2

I am trying to connect to an external server from Java (JDK5) server, though proxy.

https://docs.oracle.com/javase/7/docs/technotes/guides/net/proxies.html (3rd section).

java.net.Proxy proxy = new java.net.Proxy(java.net.Proxy.Type.HTTP, new java.net.InetSocketAddress("WHQPROXYPOOL", 80));
java.net.HttpURLConnection con = (java.net.HttpURLConnection) new java.net.URL("https://performancemanager8.successfactors.com/odata/v2/FOPayGroup?$format=json").openConnection(proxy);

But I am getting error, "UnsupportedOperationException, Method not implemented". When I check Java class (JDK5) URLStreamHandler

protected URLConnection openConnection(URL u, Proxy p) throws IOException {
throw new UnsupportedOperationException("Method not implemented.");
}

How can I connect to target server through proxy?

  • What version is your JDK? I am able to connect fine to the above server with the latest version of JDK 5 update 22. – brso05 Aug 04 '15 at 19:52
  • My server, where the program runs, is on JDK 5, update 22. URLStreamHandler is abstract class. Where will be implementation class and how will JDK identify it? – Raghu Vamseedhar Aug 04 '15 at 19:58
  • which line is throwing the exception the second one? – brso05 Aug 04 '15 at 20:03
  • Yes. Second line. .openConnection(proxy) will call openConnection(Proxy proxy) of class URL, it will call openConnection(URL u, Proxy p) of abstract class URLStreamHandler. – Raghu Vamseedhar Aug 04 '15 at 20:06
  • can you post the full stacktrace? – brso05 Aug 04 '15 at 20:09
  • https://docs.google.com/a/presenceofit.com.au/document/d/1U7C_33pHARpPqXZXPeETRUFdKuRIx3EkW9VRgWvTgvc/edit?usp=sharing – Raghu Vamseedhar Aug 04 '15 at 20:15
  • https://docs.google.com/a/presenceofit.com.au/document/d/1U7C_33pHARpPqXZXPeETRUFdKuRIx3EkW9VRgWvTgvc/edit?usp=sharing – Raghu Vamseedhar Aug 04 '15 at 20:21
  • Now, above link is accessible. – Raghu Vamseedhar Aug 04 '15 at 20:34
  • looks like this is specific to XI. They must not be using the default `Protocol Handler` class supplied with the JDK. They must have done their own implementation. When I have time I will try to take a look at the stacktrace and dissect it and see if I can pull any useful information from the stacktrace. – brso05 Aug 04 '15 at 20:55
  • Great analysis. I guessed same thing from the start. URLStreamHandler is abstract class and there must be some implementation. I do know, how JDK will know where implementation class is present. Yes, XI might have there own implementation. Have to find out how XI picks up implantation class Handler. – Raghu Vamseedhar Aug 04 '15 at 21:16
  • I posted what I think might solve your problem...let me know if that works. – brso05 Aug 05 '15 at 12:53

1 Answers1

2

Try this @RaghuVamseedhar:

java.net.Proxy proxy = new java.net.Proxy(java.net.Proxy.Type.HTTP, new java.net.InetSocketAddress("WHQPROXYPOOL", 80));
java.net.HttpURLConnection con = (java.net.HttpURLConnection) new java.net.URL(null, "https://performancemanager8.successfactors.com/odata/v2/FOPayGroup?$format=json", new sun.net.www.protocol.http.Handler()).openConnection(proxy);

I got this code to get the default sun HTTP Handler here

Community
  • 1
  • 1
brso05
  • 13,142
  • 2
  • 21
  • 40