当前位置: 首页>>代码示例>>Scala>>正文


Scala HttpsURLConnection类代码示例

本文整理汇总了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
  }
} 
开发者ID:xiaozai512,项目名称:marathon,代码行数:41,代码来源:SSLContextTestUtil.scala


注:本文中的javax.net.ssl.HttpsURLConnection类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。