Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-03-2007, 05:38 PM
Senior Member
 
Join Date: Jun 2007
Posts: 114
Albert is on a distinguished road
java.net.ConnectException: Connection refused
Recently I had been struggling with some code to get a https connection to work.

It was coming up with an error that no trusted certificates could be found. I'm working on the program on Windows and putting into a unix server to be run. This worked fine initially with no problems, then the server changed from http to https, so I had to implement some changes to deal with this, now however, even though it works fine on windows when put on unix,
it throws up this error:

java.net.ConnectException: Connection refused

Code:
java.security.Security.insertProviderAt(new sun.security.provider.Sun(),2); java.security.Security.addProvider(new sun.security.provider.Sun()); java.security.Security.insertProviderAt(new com.sun.net.ssl.internal.ssl.Provider(),1); // set protocol to java.protocol.handler.pkgs property to 'HTTP' // -- to do with if report server site is HTTPS System.setProperty("java.protocol.handler.pkgs","HTTP"); // Trustmanager -- set to trust any certificate for a secure server TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() { public java.security.cert.X509Certificate[] getAcceptedIssuers() { return null; } public void checkClientTrusted( java.security.cert.X509Certificate[] certs, String authType) { } public void checkServerTrusted( java.security.cert.X509Certificate[] certs, String authType) { } } }; try { SSLContext sc = SSLContext.getInstance("SSL"); sc.init(null, trustAllCerts, new java.security.SecureRandom()); HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); } catch (Exception e) { e.printStackTrace(); } URL url = null; try { url = new URL( rptUrl ); //rptUrl contains url to use } catch (MalformedURLException mue) { mue.printStackTrace(); } //HttpsURLConnection c; try { URLConnection c = url.openConnection(); //set cache and request method settings c.setUseCaches(false); //set other headers c.setRequestProperty ("Content-Type", "application/pdf"); //connect to the server.. c.connect(); ////some code about what to do with file etc etc....
Any ideas? Thanks.

Albert
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-03-2007, 05:44 PM
Member
 
Join Date: Jun 2007
Posts: 95
Felissa is on a distinguished road
It sounds like there is a DNS problem. A connection refused means that the client machine cannot connect to the port on the server machine.

If I assume that the server machine is the same on both Windows and Unix then the only thing left is that the Unix machine is pointing to a different IP address than the Windows machine.

Greetings.

Felissa
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 07-03-2007, 05:49 PM
Senior Member
 
Join Date: Jun 2007
Posts: 114
Albert is on a distinguished road
The server is usually a certian name example server1. And the https site to connect to is server1.com: The Leading Server Site on the Net

However, now they've done something to the site so the link is now https://site2.com/page.jsp however you still log into onto unix using the original server1... so they may be something in play there?

To clarify local machine is windows, just opens a connection to server. The unix part of it is the java program should be located on the server, which opens a http connection to a site which is on the same server.
Greetings.
Albert
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Java Serevr Connection Problem virendra_agarwal JavaServer Faces 0 12-19-2007 01:43 PM
Socket refused, but applet talking to native server Waccoon Networking 1 12-17-2007 12:13 PM
"connection refused when attempting to contact localhost katie New To Java 1 08-06-2007 11:54 PM
Exception in thread "main" java.net.ConnectException: Connection timed out osval Advanced Java 1 07-27-2007 11:59 PM
ConnectException not found tamayo New To Java 1 07-23-2007 09:23 AM


All times are GMT +3. The time now is 06:38 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org