/* A Thrift SSL Client Author: Ian Kaplan April, 2013 */ package ssl_test; import java.io.File; import java.net.InetAddress; import java.net.UnknownHostException; import org.apache.thrift.transport.TSSLTransportFactory; import org.apache.thrift.transport.TSocket; import org.apache.thrift.transport.TTransport; import org.apache.thrift.transport.TTransportException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class SSLClient extends Thread implements ISSLInterface { private static final Logger LOGGER = LoggerFactory.getLogger(SSLClient.class.getName()); public SSLClient() { File pathToTruststore = new File( truststorePath ); if (pathToTruststore.exists()) { if (! pathToTruststore.canRead()) { System.err.println("Client: cannot read truststore file: " + truststorePath ); } } else { System.err.println("Client: path to keystore does not exist: " + truststorePath ); } } @Override public void run() { System.out.println("SSLClient: entering run()"); TSSLTransportFactory.TSSLTransportParameters params = new TSSLTransportFactory.TSSLTransportParameters(); params.setTrustStore(truststorePath, certPswd); TSocket clientSoc = null; try { clientSoc = TSSLTransportFactory.getClientSocket(host, port, clientTimeout, params); final String msg = "T'was brillag and the slithy toves"; final byte[] buf = msg.getBytes(); System.out.println("Client: Writing to server"); clientSoc.write(buf); clientSoc.flush(); } catch (TTransportException ex) { System.out.println("Client: Error creating client socket: " + ex.getLocalizedMessage()); } finally { if (clientSoc != null) { clientSoc.close(); } } System.out.println("Leaving SSLClient run()"); } }