Weird HttpsURLConnection problem
Hi everyone,
I am running a struts application on jboss 3.2.1. Part of my application deals with posting xml over https. Two problems popped up today, and because they appeared at the same time, I have a hunch they're related.
1. Our production server (which we recently purchased a new SSL certificate for) cannot post xml over https.
2. All of our testing servers can post xml over https (these are running the exact same code). However, when we try to post to our production server, the code breaks.
Here is the code that does the posting:
HostnameVerifier hv =new HostnameVerifier(){
publicboolean verify(String urlHostName, SSLSession session){
System.out.println("Warning: URL Host: "+urlHostName+" vs. "+session.getPeerHost());
returntrue;
}
};
HttpURLConnection uc =null;
if ("https".equals(url.getProtocol())){
HttpsURLConnection.setDefaultHostnameVerifier(hv);
uc = (HttpsURLConnection) url.openConnection();
}
else{
uc = (HttpURLConnection) url.openConnection();
}
uc.setDoOutput(true);
if (!headers.isEmpty()){
for (Iterator it = headers.keySet().iterator(); it.hasNext(); ){
String key = (String) it.next();
String val = (String) headers.get(key);
uc.setRequestProperty(key, val);
}
}
logger.info( uc.getURL().toExternalForm() );
logger.info( uc.getURL().toString() );
OutputStreamWriter out =new OutputStreamWriter(new BufferedOutputStream(uc.getOutputStream()),"ASCII");
out.write(query.toString() + data.toString() +"\r\n");
out.flush();
out.close();
for (int j = 0; ; j++){
String header =null;
try{
header = uc.getHeaderField(j);
}
catch (Exception e){
logger.error(e);
}
logger.info("j = " + j +"; header = " + header );
if (header ==null){
break;
}
rHeaders.put(uc.getHeaderFieldKey(j), header);
}
rCode = uc.getResponseCode();
rMsg = uc.getResponseMessage();
rLastMod = uc.getLastModified();
inn = uc.getInputStream();
return inn;
While using Eclipse's debugger to step through this code on my local machine (and posting to our production server) to QA problem #2, everything goes fine until the line "header = uc.getHeaderField(j);" No exception is thrown that I can see, but the system hangs, and the debugger stops working. I thought maybe some kind of exception was being thrown (hence the try/catch) but nothing is caught.
Any ideas what might be the problem? Does this sound like an issue with the cert? It was purchased two weeks ago or so, and is valid from 7/21/2005 to 8/11/2006.
Any help would be greatly appreciated. Thank you,
Ben Rainville

