WebServiceClient { public Client createClient() { return new Client( new URLConnectionClientHandler(getHttpURLConnectionFactory())); }  static void initialize(Configuration conf); static WebServiceClient getWebServiceClient(); Client createClient(); synchronized static void destroy();  }
@Test public void testCreateClient() throws Exception { Configuration conf = new Configuration(); conf.set(YarnConfiguration.YARN_HTTP_POLICY_KEY, "HTTPS_ONLY"); File base = new File(BASEDIR); FileUtil.fullyDelete(base); base.mkdirs(); String keystoresDir = new File(BASEDIR).getAbsolutePath(); String sslConfDir = KeyStoreTestUtil .getClasspathDir(TestWebServiceClient.class); KeyStoreTestUtil.setupSSLConfig(keystoresDir, sslConfDir, conf, false, true); Configuration sslConf = KeyStoreTestUtil.getSslConfig(); sslConf.set(YarnConfiguration.YARN_HTTP_POLICY_KEY, "HTTPS_ONLY"); HttpServer2 server = new HttpServer2.Builder().setName("test") .addEndpoint(new URI("https: .keyPassword( sslConf.get(SSL_SERVER_KEYSTORE_PROP_PREFIX + ".keypassword")) .keyStore(sslConf.get(SSL_SERVER_KEYSTORE_PROP_PREFIX + ".location"), sslConf.get(SSL_SERVER_KEYSTORE_PROP_PREFIX + ".password"), sslConf.get(SSL_SERVER_KEYSTORE_PROP_PREFIX + ".type", "jks")) .trustStore( sslConf.get(SSL_SERVER_TRUSTSTORE_PROP_PREFIX + ".location"), sslConf.get(SSL_SERVER_TRUSTSTORE_PROP_PREFIX + ".password"), sslConf.get(SSL_SERVER_TRUSTSTORE_PROP_PREFIX + ".type", "jks")) .excludeCiphers(sslConf.get("ssl.server.exclude.cipher.list")).build(); server.addServlet(SERVLET_NAME_ECHO, SERVLET_PATH_ECHO, EchoServlet.class); server.start(); final URL baseUrl = new URL( "https: URL u = new URL(baseUrl, SERVLET_PATH_ECHO + "?a=b&c=d"); WebServiceClient.initialize(sslConf); WebServiceClient client = WebServiceClient.getWebServiceClient(); HttpURLConnection conn = client.getHttpURLConnectionFactory() .getHttpURLConnection(u); Assert.assertEquals(HttpURLConnection.HTTP_OK, conn.getResponseCode()); WebServiceClient.destroy(); server.stop(); FileUtil.fullyDelete(new File(BASEDIR)); KeyStoreTestUtil.cleanupSSLConfig(keystoresDir, sslConfDir); }