HTTPSURLConnection Problem
Java Swing client through HTTPSURLConnection talks to a load-balancer server (Apache 2.2.3 with
mod_ssl /openSSL 0.9.8) running 443 port which inturn forwards request to 2 JBoss servers
(Webserver Tomcat) running in 8080 port.
Above is the setup
When I send a Object through HTTPSURLCOnnection's ObjectOutputStream to servlet through
load-balancer, it throws EOFException while doing the following operation
request.getInputStream().
Below is the code of Java Swing Client :
//
publicvoid swingToSvltSSL(){
try{
HttpsURLConnection conn = getSSLOutputConnection();
OutputStream os = conn.getOutputStream();
//java.io.ByteArrayOutputStream bos = new java.io.ByteArrayOutputStream();
ObjectOutputStream obj =new ObjectOutputStream(os);
System.out.println(" Object table is "+objectTable);
obj.writeObject(objectTable);
os.flush();
os.close();
InputStream is = conn.getInputStream();
//
java.io.ObjectInputStream objIn =new java.io.ObjectInputStream(is);
objectTable = (java.util.Hashtable) objIn.readObject();
//
}
catch(java.io.EOFException ex){
objectTable =null;
}
catch(Exception e){
System.out.println("Exception at the swingToSvlt "+e);
}
}
private HttpsURLConnection getSSLOutputConnection()throws Exception{
try{
buildDocument();
URL url =new URL(protocol, ipAddress, portNumber, document);
System.out.println(" URL is "+url);
hts = (HttpsURLConnection) url.openConnection();
hts.setHostnameVerifier(new javax.net.ssl.HostnameVerifier(){
publicboolean verify(String hostname, javax.net.ssl.SSLSession certHostName)
{
returntrue;
}
});
hts.setUseCaches(false);
hts.setDefaultUseCaches(false);
hts.setDoInput(true);
hts.setDoOutput(true);
hts.setSSLSocketFactory(getSSLFactory());
}
catch(Exception e){
throw e;
}
return hts;
}
private SSLSocketFactory getSSLFactory()
{
System.out.println(" At the ssl factory new");
SSLSocketFactory factory =null;
try{
SSLContext ctx;
factory = createSSLContext().getSocketFactory();
System.out.println(" Factory is "+factory);
return factory;
}catch (Exception e){
e.printStackTrace();
returnnull;
//throw new IOException(e.getMessage());
}
}
}
//
Below is the code in servlet :
publicvoid getFromSwing(HttpServletRequest request)
{
try{
InputStream is = request.getInputStream();
java.io.ObjectInputStream objIn =new java.io.ObjectInputStream(is);
objectTable = (java.util.Hashtable) objIn.readObject();
}
catch(java.io.EOFException ex)
{
ex.printStackTrace();
objectTable =null;
}
catch(Exception e){
System.out.println("Exception is l"+e);
}
// end of servlet part
Getting java.io.EOFException while trying to read the object >>objectTable =
(java.util.Hashtable) objIn.readObject();
Same code works very fine with HTTPUrlConnection (i.e., without SSL)
Whether SSL transportation corrupts the request stream?
Please help me out.[/code]
Rgds
Venquet

