Re: How do I use Java and SSL for a POST request?
Tuesday, November 25, 2008 06:27 PM
The Java code you write effectively just connects to a URL that starts with "https://" and this will induce the Java framework to handle the connection via SSL w/ no real additional work on the part of the coder. The remote server being connected to (by/from your servlet) WILL need some form of an SSL certificate to identify itself with. Exactly how that is obtained and configured is a function of the web server. The only really tricky part is that the JVM that your servlet runs with will need to "trust" the SSL certificate of the remote server. If you are using a self-signed certificate, or a certificate not signed by an of the root CAs that Java already trusts by default, then you will need to add a few "-D" arguments to specify a custom truststore (a file into which the server's certificate has been imported) to use. If you don't do this, the connection to the remote server will fail, probably silently (depending on what exceptions you catch/print). (And there are some deeper programmatic APIs to setup the truststore and that sort of thing, but the above techniques are generally the easiest to work out when you aren't overly familiar with SSL in general, the jargon, or these deeper APIs.)