[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[iaik-ssl]cu|| java.io.EOFException Connection closed by remote host



Hi everybody,
 
    I´m having the following problem. I´v downloaded and installed the following files (for evaluation):
 
1. IAIKJCE30ev.exe
2. iaik_rc.jar
3. iaik_jce_full.jar
4. isasilk304ev.zip
 
When I tried to use the HttpsURLConnection, I have the following error:
 
"java.io.EOFException: Connection closed by remote host."
 
This happens when I try to do the following: "InputStream is = con.getInputStream();"
 
 
Anybody knows how to solve this problem?
 
thanks in advanced
 
Hernan Di Chello 
 
The source code is below
 
import java.io.*;
import java.net.*;
import java.util.*;
import iaik.security.ssl.*;
import iaik.protocol.https.*;
 
public class ssltest {
 
  public static void main(String args[]) throws Exception {
   try
   {
   Properties prop = System.getProperties();
 prop.put("https.proxyHost","172.16.0.249");
 prop.put("https.proxyPort","3128");
 prop.put("http.proxyHost","172.16.0.249");
 prop.put("http.proxyPort","3128");
    
 
 
    // register the https URL handler
    System.getProperties().put("java.protocol.handler.pkgs", "iaik.protocol");
 
    String urlString= "https://jcewww.iaik.at/";
  
  
    // the connection is automatically established through proxies
    // if the properties have been set, see iaik.security.ssl.Utils.proxyConnect()
    URL url = new URL(urlString);
 System.out.println("Connecting to " + url + "...");
   HttpsURLConnection con = (HttpsURLConnection)url.openConnection();
   SSLContext context = new SSLClientContext();
   
   // make whatever settings we want in the context
    context.setAllowedProtocolVersions(SSLContext.VERSION_SSL20, SSLContext.VERSION_TLS10);
   con.setSSLContext(context);
 
    con.setRequestMethod("POST");
    con.setDoInput(true);
    con.setDoOutput(true);
 
 OutputStream out = con.getOutputStream();
    out.write("foobar".getBytes());
    out.flush();
 

   // getInputStream()/getOutputStream() establishes the connection and
   // starts the SSL handshake
   InputStream is = con.getInputStream();
   BufferedReader in = Utils.getASCIIReader(is);
 char b[] = new char[2048];
 int nch=0;
 
   System.out.println("Secure connection established.");
   System.out.println();
 
   // read SSL properties from the socket
//   System.out.println("Connected using: " + con.getSSLSocket().getActiveCipherSuite());
   // everything else is standard HTTP URL stuff
   System.out.println("ResponseCode: "+con.getResponseCode());
   System.out.println("ResponseMessage: "+con.getResponseMessage());
   System.out.println("ContentEncoding: "+con.getContentEncoding());
   System.out.println("ContentLength: "+con.getContentLength());
   System.out.println("ContentType: "+con.getContentType());
   System.out.println("Date: "+con.getDate());
   System.out.println("Server: "+con.getHeaderField("Server"));
   System.out.println();
 
   while((nch=in.read(b,0,b.length)) != -1)
   {
    System.out.print(new String(b));
   }
  
  }catch(Exception e)
  {
   FileOutputStream fs = new FileOutputStream(new File("/ERROR_IAIK.TXT"));
  fs.write(e.getMessage().getBytes());
  fs.write(e.getStackTrace().getBytes());
  fs.close();
   throw new Exception(e.getMessage());
  }
  }
 
}