本文整理汇总了Scala中javax.net.ssl.HttpsURLConnection类的典型用法代码示例。如果您正苦于以下问题:Scala HttpsURLConnection类的具体用法?Scala HttpsURLConnection怎么用?Scala HttpsURLConnection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了HttpsURLConnection类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: SSLContextTestUtil
//设置package包名称以及导入依赖的类
package mesosphere.marathon.integration.setup
import java.io.File
import java.net.URL
import javax.net.ssl.{ HttpsURLConnection, SSLContext }
import mesosphere.marathon.io.SSLContextUtil
object SSLContextTestUtil {
val keyStorePassword = "password"
lazy val selfSignedKeyStoreURL = Option(getClass.getResource("/test-keystore.jks").getFile).getOrElse(
throw new RuntimeException("Could not find resource /test-keystore.jks")
)
lazy val selfSignedKeyStorePath = new File(selfSignedKeyStoreURL).getAbsolutePath
lazy val selfSignedSSLContext = SSLContextUtil.createSSLContext(
Some(selfSignedKeyStorePath),
Some(keyStorePassword)
)
lazy val caTrustStoreURL = Option(getClass.getResource("/ca-truststore.jks")).getOrElse(
throw new RuntimeException("Could not find resource /ca-truststore.jks")
)
lazy val caTrustStorePath = caTrustStoreURL.getPath
lazy val caKeyStoreURL = Option(getClass.getResource("/ca-keystore.jks")).getOrElse(
throw new RuntimeException("Could not find resource /ca-keystore.jks")
)
lazy val caKeyStorePath = new File(caKeyStoreURL.getPath).getAbsolutePath
lazy val caSignedSSLContext: SSLContext = SSLContextUtil.createSSLContext(
Some(caKeyStorePath),
Some(keyStorePassword)
)
def sslConnection(url: URL, sslContext: SSLContext): HttpsURLConnection = {
val connection = url.openConnection().asInstanceOf[HttpsURLConnection]
connection.setSSLSocketFactory(sslContext.getSocketFactory)
connection
}
}