User's Blog!by CA Technologies


How Can We Help?
< Back

[expand title=”Prerequisites” expanded=”true”]


Using HTTPs protocol

CodeSV supports the HTTPs protocol that is easily enabled by using the usingHttps() method. There are three required parameters to be specified:

  • keystorePath points to the location of the keystore on the file system.
  • keystorePassword specifies a password for the provided keystore.
  • keyPassword specifies the password to a key.

Note: In the provided example, we are using our own custom trust manager to trust all communication with common name localhost (CN=localhost). In a real use case scenario you should use another trust manager.

HTTPs example

private static final String KEYSTORE_PATH = HttpsExample.class.getClassLoader()
  private static final String KEYSTORE_PASSWORD = "password";
  private static final String BODY_PLAIN_TEXT = "Success";
  private static final String BASE_URL_SSL = "https://localhost:8090/";
  private static final int HTTP_STATUS_OK_NUMB = 200;

  public VirtualServerRule vs = new VirtualServerRule();

  private TrustManager[] trustAllCerts;
  private SSLContext sslContext;

   * Preparing to trust everything with the common name localhost.
  public void setUp() throws Exception {
    trustAllCerts = new TrustManager[]{
        new X509TrustManager() {
          public[] getAcceptedIssuers() {
            return new X509Certificate[0];

          public void checkClientTrusted(
    [] certs, String authType) {

          public void checkServerTrusted(
    [] certs, String authType) {
            if (certs.length != 1 || !certs[0].getIssuerX500Principal().getName()
                .contains("CN=localhost")) {
              throw new SecurityException("Invalid certificate");

    sslContext = SSLContext.getInstance("TLS");
    sslContext.init(null, trustAllCerts, new SecureRandom());

  @Test(timeout = 10000L)
  public void testHttpsConnection() throws IOException {

    URL u = new URL(BASE_URL_SSL);
    HttpsURLConnection connection = (HttpsURLConnection) u.openConnection();
    assertEquals(HTTP_STATUS_OK_NUMB, connection.getResponseCode());
        IOUtils.toString((InputStream) connection.getContent()));

For a complete example see: HTTPs Example

Required KeyStore file: keystore.jks

Previous Exporting Virtual Services from CodeSV
Next SOAP Virtualization
Table of Contents

Comments are currently closed.