目前我正在运行 scala play 应用程序,现在它的 HTTP API 在我的本地 Angular UI 应用程序中运行良好。但在我们组织的更高环境中我们需要将其转换为SSL HTTPS API。 我们使用我们自己的组织根 CA,我随身携带了 myCA_trust.jks 证书文件。
我在 application.conf 文件中添加了以下属性,
play.server.https.keyStore.path="./myCA_trust.jks"
play.server.https.keyStore.password="change_me"
为了部署代码,我创建了 dist,并使用以下命令将其部署在 Linux 服务器上
./scala-rest-api -Dplay.http.secret.key="application_secreate_key" -Dhttps.port=8094 -Dplay.server.https.keyStore.path=./myCA_trust.jks -Dplay.server.https.keyStore.password=change_me
执行此操作后,我可以使用服务器地址访问 HTTPS URL,但在服务器控制台中出现错误,例如,
[error] a.a.OneForOneStrategy - ./myCA_trust.jks
akka.actor.ActorInitializationException: akka://application/system/StreamSupervisor-0/flow-2-1: exception during creation
at akka.actor.ActorInitializationException$.apply(Actor.scala:202)
at akka.actor.ActorCell.create(ActorCell.scala:698)
at akka.actor.ActorCell.invokeAll$1(ActorCell.scala:549)
at akka.actor.ActorCell.systemInvoke(ActorCell.scala:571)
at akka.dispatch.Mailbox.processAllSystemMessages(Mailbox.scala:293)
at akka.dispatch.Mailbox.run(Mailbox.scala:228)
at akka.dispatch.Mailbox.exec(Mailbox.scala:241)
at akka.dispatch.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
at akka.dispatch.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
at akka.dispatch.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
Caused by: java.lang.reflect.InvocationTargetException: null
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at play.core.server.ssl.ServerSSLEngine$.createScalaSSLEngineProvider(ServerSSLEngine.scala:116)
at play.core.server.ssl.ServerSSLEngine$.createSSLEngineProvider(ServerSSLEngine.scala:39)
at play.core.server.AkkaHttpServer$$anon$4$$anon$5.sslEngineProvider$lzycompute(AkkaHttpServer.scala:527)
at play.core.server.AkkaHttpServer$$anon$4$$anon$5.sslEngineProvider(AkkaHttpServer.scala:526)
at play.core.server.AkkaHttpServer$$anon$4$$anon$5.engineCreateSSLEngine(AkkaHttpServer.scala:528)
at javax.net.ssl.SSLContext.createSSLEngine(SSLContext.java:329)
Caused by: java.nio.file.NoSuchFileException: ./myCA_trust.jks
请帮助我配置 HTTPS REST API URL,请告诉我是否还需要在代码中添加任何其他内容以及位置。 谢谢,提前。
val sslContext = SSLContext.getInstance("TLS") sslContext.init(null, Array[TrustManager](新 X509TrustManager { 覆盖 def checkClientTrusted(链: Array[X509Certificate], authType: String): Unit = {} 覆盖 def checkServerTrusted(链: Array[X509Certificate], authType: String): Unit = {} 覆盖 def getAcceptedIssuers: Array[X509Certificate] = null}), new java.security.SecureRandom()) val hostnameVerifier = new HostnameVerifier {覆盖 def verify(s: String, sslSession: SSLSession): Boolean = true} val httpClient= HttpClients.custom().setSSLContext (sslContext).setSSLHostnameVerifier (hostnameVerifier).build() val content = EntityUtils.toString(httpClient.execute(new HttpGet("https://randomuser.me/api/0.8/?results-10")).getEntity) val urlstring = content.mkString println(urlstring)