Expert gentlebeings,
I am using the following method (in a Jetty webserver) to exchange information with another webserver:
String exchMsg(HttpResponse response,StringBuffer sb,boolean sendok)
{ HttpURLConnection conn=null;
try
{ URL address=new URL("
https://"+ipxml+":"+p
ortxml);
conn=(HttpURLConnection)ad
dress.open
Connection
();
if(conn==null)
{ Log.warning("error connecting");
sendResp(response,"send error!");
return(null);
}
} catch(Exception e)
{ Log.warning("error connecting: "+e);
sendResp(response,"send error!");
return(null);
}
try
{ conn.setRequestMethod("POS
T");
conn.setDoOutput(true);
conn.setDoInput(true);
conn.connect();
OutputStream outs=conn.getOutputStream(
);
outs.write(sb.toString().g
etBytes("A
SCII"));
outs.flush();
outs.close();
} catch(Exception e)
{ Log.warning("error sending: "+e);
sendResp(response,"send error!");
return(null);
}
Log.event("SENT to "+ipxml+":"+portxml+" "+sb);
if(sendok)sendResp(respons
e,"OK");
try
{ InputStream ins=conn.getInputStream();
byte bs[]=new byte[1000];
sb=new StringBuffer(1000);
int n;
do
{ if((n=ins.read(bs))!=-1)sb
.append(ne
w String(bs,0,n));
} while(!sb.toString().endsW
ith("</Res
ponse>"));
ins.close();
} catch(Exception e)
{ Log.warning("error receiving: "+e);
return(null);
}
Log.event("RECV "+sb.toString());
return(sb.toString());
}
Now, when I was connecting to an unencrypted port, everything worked fine. However, in attempting to get it encrypted, I changed the URL to be https, connected to a different port on their end (that provides an encrypted connection), and now I get an exception in the second try/catch block, presumably at the conn.connect() statement:
08:12:51.921 WARN!! error sending: java.net.ConnectException:
Connection timed out: connect
The guys at the other end indicate that I am not processing their public key, and that they don't have provision for processing a public key from us (not that I was intending to provide one), and they are getting a handshake exception:
HTTPRequestHandler.getRequ
estLine()j
avax.net.s
sl.SSLHand
shakeExcep
tion:
Received fatal alert: certificate_unknown (HTTP Request handler) 2005-09-30 14:36:57,073 [HTTPRequest.java] DEBUG - Data has not been sent from another process, sending data... (HTTP Request handler) 2005-09-30 14:36:57,074 [HTTPResponse.java] DEBUG - Status code 400 (HTTP Request handler) 2005-09-30 14:36:57,074 [HTTPResponse.java] DEBUG - Sending standard request (HTTP Request handler) 2005-09-30 14:36:57,074 [HTTPResponse.java] DEBUG - Checking security, authorization string null (HTTP Request handler) 2005-09-30 14:36:57,075 [HTTPConst.java] DEBUG - Encoding URL: /~HTTPServerImages/notvali
d.gif (HTTP Request handler) 2005-09-30 14:36:57,075 [HTTPConst.java] DEBUG - URL encoded /~HTTPServerImages/notvali
d.gif (HTTP Request handler) 2005-09-30 14:36:57,076 [HTTPResponse.java] WARN - IOException:
HTTPResponse.send()javax.n
et.ssl.SSL
Exception:
Connection has been
shutdown: javax.net.ssl.SSLHandshake
Exception:
Received fatal alert: certificate_unknown (HTTP Request handler) 2005-09-30 14:36:57,076
What must I do/add to get this to work?