Win a copy of Java 9 Revealed this week in the Features new in Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Making HttpsURLConnection behind a proxy  RSS feed

 
Sowmya Karmali
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to connect to a secure site from a java application (not browser) on a redhat linux 7.2 machine.
The linux machine is behind a firewall.
when i specify the proxyHost and proxyPort (https.proxyHost,https.proxyPort) in my application i
get an IOException saying -
Exception in thread "main" java.io.IOException: Unable to tunnel through <proxy>.
Proxy returns "HTTP/1.1 200 Connection established"
at com.sun.net.ssl.internal.www.protocol.https.HttpsClient.a([DashoPro-V
1.2-120198])
at com.sun.net.ssl.internal.www.protocol.https.HttpsClient.doConnect([Da
shoPro-V1.2-120198])
at com.sun.net.ssl.internal.www.protocol.https.NetworkClient.openServer(
[DashoPro-V1.2-120198])
at com.sun.net.ssl.internal.www.protocol.https.HttpClient.l([DashoPro-V1
.2-120198])
at com.sun.net.ssl.internal.www.protocol.https.HttpClient.<init>([DashoP
ro-V1.2-120198])
at com.sun.net.ssl.internal.www.protocol.https.HttpsClient.<init>([Dasho
Pro-V1.2-120198])
at com.sun.net.ssl.internal.www.protocol.https.HttpsClient.a([DashoPro-V
1.2-120198])
at com.sun.net.ssl.internal.www.protocol.https.HttpsClient.a([DashoPro-V
1.2-120198])
at com.sun.net.ssl.internal.www.protocol.https.HttpsURLConnection.connec
t([DashoPro-V1.2-120198])
at com.sun.net.ssl.internal.www.protocol.https.HttpsURLConnection.getInp
utStream([DashoPro-V1.2-120198])
at URLTunnelReader.main(URLTunnelReader.java:29)
This is bcos JSSE currently accepts http/1.0 response only from the proxy.
I found an article on javaworld (tip 111) and did what the article said:
Create a class SSLTunnelSocketFactory that extends SSLSocketFactory, and in that have a method which works around this by looking for the string "200 connection established" instead of "HTTP/1.0 200", which the DefaultSSLSocketFactory does.
Now, the SSL handshake is happening, but the createSocket() method from the proxy to the secure site still fails.

Can anyone tell me why is this happening and is there a workaround available?
thanks and Regards
Sowmya.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!