aspose file tools*
The moose likes Sockets and Internet Protocols and the fly likes Doubt on sun.net.www.http.HttpClient  class whether it supports https protocol Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Doubt on sun.net.www.http.HttpClient  class whether it supports https protocol" Watch "Doubt on sun.net.www.http.HttpClient  class whether it supports https protocol" New topic
Author

Doubt on sun.net.www.http.HttpClient class whether it supports https protocol

rajareddya reddy
Ranch Hand

Joined: Jul 23, 2011
Posts: 54
Dear All,

My requirement is to call HTTPS URL through java code(through HTTP URL call).
for that I am using sun.net.www.http.HttpClient class.

I need to know whether sun.net.www.http.HttpClient class supports only HTTP or it supports HTTPS also
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42599
    
  65
You should not use any of the sun.* classes directly. What's wrong with javax.net.ssl.HttpsURLConnection?


Ping & DNS - my free Android networking tools app
rajareddya reddy
Ranch Hand

Joined: Jul 23, 2011
Posts: 54
I am getting connection refused error when i am accessing HTTPS URL through java code


TWKOnlineSubmit | submitWithResponse | [b]SocketException : java.net.ConnectException: Connection refused
java.net.ConnectException: Connection refused
at sun.reflect.GeneratedConstructorAccessor196.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at sun.net.www.protocol.http.HttpURLConnection$6.run(HttpURLConnection.java:1491)
at java.security.AccessController.doPrivileged(Native Method)
at sun.net.www.protocol.http.HttpURLConnection.getChainedException(HttpURLConnection.java:1485)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1139)
at com.crimsonlogic.thb.twkonline.TWKOnlineSubmit.submitWithResponse(TWKOnlineSubmit.java:350)
at com.crimsonlogic.thb.test.servlet.TWKOnlineSubmitServlet.submit(TWKOnlineSubmitServlet.java:128)
at com.crimsonlogic.thb.test.servlet.TWKOnlineSubmitServlet.doPost(TWKOnlineSubmitServlet.java:86)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:300)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:183)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3717)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3681)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2277)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2183)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1454)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:207)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:176)
[/b]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42599
    
  65
So - is the target host accessible from whichever machine this code runs on through whichever port you're using?
rajareddya reddy
Ranch Hand

Joined: Jul 23, 2011
Posts: 54
Yes, target is accessible from the machine where application is running.
Facing the problem while connecting URL through java code
rajareddya reddy
Ranch Hand

Joined: Jul 23, 2011
Posts: 54

One last question.

I want to know whether sun.net.www.http.HttpClient api supports HTTPS

I am using jdk 1.6 version
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42599
    
  65
The better question is: what do you hope to achieve by using that class that you can't achieve by using a class that is part of the Java API?
rajareddya reddy
Ranch Hand

Joined: Jul 23, 2011
Posts: 54
Thanks for your reply

Ours is maintenance project.Code is already developed.in that somebody already coded that sun.net.www.protocol.http.httpurlconnection used for connecting HTTP URL. But recently our requirement changed.We need to connect to HTTPS URL with sun.net.www.protocol.http.httpurlconnection without changing this API.

Now when we are connecting HTTPS URL, we are getting connection reused error.

Is it a server problem or code problem.

If it is code problem I want to know whether sun.net.www.protocol.http.httpurlconnection api supports HTTPS URL call


Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18886
    
    8

It seems to me that this would be a good time to fix the programming error -- by which I mean the use of a "sun.*" class, which is universally dis-recommended.
Richard Tookey
Ranch Hand

Joined: Aug 27, 2012
Posts: 1083
    
  10

Paul Clapham wrote:It seems to me that this would be a good time to fix the programming error -- by which I mean the use of a "sun.*" class, which is universally dis-recommended.


This view has also been expressed forcefully in the Oracle Java forums but the OP is not listening.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Doubt on sun.net.www.http.HttpClient class whether it supports https protocol