Results 1 to 3 of 3
- 07-03-2007, 04:38 PM #1
Senior Member
- Join Date
- Jun 2007
- Posts
- 114
- Rep Power
- 0
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
Any ideas? Thanks.Java 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....
Albert:rolleyes:
- 07-03-2007, 04:44 PM #2
Member
- Join Date
- Jun 2007
- Posts
- 95
- Rep Power
- 0
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:p
- 07-03-2007, 04:49 PM #3
Senior Member
- Join Date
- Jun 2007
- Posts
- 114
- Rep Power
- 0
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:rolleyes:
Similar Threads
-
"connection refused when attempting to contact localhost
By katie in forum New To JavaReplies: 2Last Post: 11-21-2008, 08:36 PM -
Java Serevr Connection Problem
By virendra_agarwal in forum JavaServer Faces (JSF)Replies: 0Last Post: 12-19-2007, 12:43 PM -
Socket refused, but applet talking to native server
By Waccoon in forum NetworkingReplies: 1Last Post: 12-17-2007, 11:13 AM -
Exception in thread "main" java.net.ConnectException: Connection timed out
By osval in forum Advanced JavaReplies: 1Last Post: 07-27-2007, 10:59 PM -
ConnectException not found
By tamayo in forum New To JavaReplies: 1Last Post: 07-23-2007, 08:23 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks