Self-Signed Certificate Problem
Hi all,
I believe this is the correct forum for this question, and I apologize if this has been asked and answered already (I looked but didn't find anything).
I have a servlet application on a webserver.I built a test client in Java to connect to it, and all worked perfectly. Then I learned that the people I'm building this for require this to be on an SSL port. So I moved the application and now am getting the following exception:
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:150)
Now I've noticed that the webserver (used exclusively for testing) has a self-signed certificate, which might be causing the problem. However I'm not in a position to change that. Typically we test websites on this server, so the browser can handle the self-signed certificate, however in this case we don't have that luxury. Given that, is there a way to get around this?
I'll include the code from my test client in the hopes that someone has some helpful tips.
Thanks in advance,
- Jack
import java.io.*;
import javax.net.ssl.HttpsURLConnection;
import java.net.URL;
public class fileloadTester
{
public fileloadTester()
{
}
public static void main(String[] args) throws Exception
{
(new fileloadTester()).run();
}
public void run()
{
HttpsURLConnection conn;
try
{
URL serverURL =
new URL("https://mytestserver.com:8443/xxx/contact");
conn = (HttpsURLConnection) serverURL.openConnection();
conn.setDoOutput(true);
conn.setUseCaches(false);
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-type", "text/xml");
File file = new File ("test.xml");
if (!file.exists() || !file.canRead())
{
return;
}
FileInputStream fis = new FileInputStream(file);
String xmlRequestString = readInputStream(fis);
fis.close();
System.out.println(xmlRequestString);
conn.setRequestProperty("Content-Length",
Integer.toString(xmlRequestString.length()));
OutputStream os = conn.getOutputStream();
os.write(xmlRequestString.getBytes());
os.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}

