How to use Play WS with SSL?

前端 未结 3 1678
无人及你
无人及你 2021-02-10 07:13

My Java client application needs to do REST calls. I was instructed to use Play\'s WS implementation. Currently, I have this:

AsyncHttpClientConfig.Builder build         


        
3条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-10 07:36

    You want to use the parser. See https://www.playframework.com/documentation/2.3.x/KeyStores for details about the configuration.

    val config = play.api.Configuration(ConfigFactory.parseString("""
                                  |trustManager = {
                                  |  stores = [
                                  |    { type: "pkcs12", path: "/path/to/pkcs12/file", password: "foo" }
                                  |  ]
                                  |}
                                """.stripMargin))
    val parser = new DefaultSSLConfigParser(config, app.classloader)
    val sslConfig = parser.parse()
    
    val clientConfig = new DefaultWSClientConfig(sslConfig = sslConfig)
    val secureDefaults = new NingAsyncHttpClientConfigBuilder(clientConfig).build()
    val builder = new AsyncHttpClientConfig.Builder(secureDefaults)
    val wsc = new play.libs.ws.ning.NingWSClient(builder.build());
    val holder = wsc.url("http://www.simpleweb.org/");
    

提交回复
热议问题