Results 1 to 3 of 3
  1. #1
    Albert is offline Senior Member
    Join Date
    Jun 2007
    Posts
    114
    Rep Power
    0

    Default 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

    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....
    Any ideas? Thanks.

    Albert:rolleyes:

  2. #2
    Felissa is offline Member
    Join Date
    Jun 2007
    Posts
    95
    Rep Power
    0

    Default

    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

  3. #3
    Albert is offline Senior Member
    Join Date
    Jun 2007
    Posts
    114
    Rep Power
    0

    Default

    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

  1. Replies: 2
    Last Post: 11-21-2008, 09:36 PM
  2. Java Serevr Connection Problem
    By virendra_agarwal in forum JavaServer Faces (JSF)
    Replies: 0
    Last Post: 12-19-2007, 01:43 PM
  3. Replies: 1
    Last Post: 12-17-2007, 12:13 PM
  4. Replies: 1
    Last Post: 07-27-2007, 11:59 PM
  5. ConnectException not found
    By tamayo in forum New To Java
    Replies: 1
    Last Post: 07-23-2007, 09:23 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •