我正在尝试将akka http服务绑定到具有https配置的服务器。但我得到了未解决的地址问题。
[ERROR] [03/01/2017 13:43:28.983] [readings-data-receiver-akka.actor.default-dispatcher-3] [akka://readings-data-receiver/system/IO-TCP/selectors/$a/0] Bind failed for TCP channel on endpoint [https://enetdefender.com/graphql:443]
java.net.SocketException: Unresolved address
at sun.nio.ch.Net.translateToSocketException(Net.java:131)
at sun.nio.ch.Net.translateException(Net.java:157)
at sun.nio.ch.Net.translateException(Net.java:163)
at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:76)
at akka.io.TcpListener.liftedTree1$1(TcpListener.scala:56)
at akka.io.TcpListener.<init>(TcpListener.scala:53)
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 akka.util.Reflect$.instantiate(Reflect.scala:65)
at akka.actor.ArgsReflectConstructor.produce(IndirectActorProducer.scala:96)
at akka.actor.Props.newActor(Props.scala:213)
at akka.actor.ActorCell.newActor(ActorCell.scala:562)
at akka.actor.ActorCell.create(ActorCell.scala:588)
at akka.actor.ActorCell.invokeAll$1(ActorCell.scala:461)
at akka.actor.ActorCell.systemInvoke(ActorCell.scala:483)
at akka.dispatch.Mailbox.processAllSystemMessages(Mailbox.scala:282)
at akka.dispatch.Mailbox.run(Mailbox.scala:223)
at akka.dispatch.Mailbox.exec(Mailbox.scala:234)
at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)
Caused by: java.nio.channels.UnresolvedAddressException
at sun.nio.ch.Net.checkAddress(Net.java:101)
at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:218)
at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
... 20 more
` 我正在添加代码,请查看它。 pppppPPPPPPPPPPPPPPPPPPppppppPPPPPpPPpppppppppppppppppppppppppppp 对象AkkaHttp扩展了App {
type PR = ProducerRecord[String, String]
val props = new Properties();
props.put("bootstrap.servers", "localhost:9092");
props.put("key.serializer", classOf[StringSerializer].getCanonicalName);
props.put("value.serializer", classOf[StringSerializer].getCanonicalName);
implicit val system = ActorSystem("readings-data-receiver")
implicit val materializer = ActorMaterializer()
implicit val executionContext = system.dispatcher
val producer = new KafkaProducer[String, String](props);
val settings = CorsSettings.defaultSettings
val password: Array[Char] = new Array[Char]('a');// do not store passwords in code, read them from somewhere safe!
val ks: KeyStore = KeyStore.getInstance("PKCS12")
val keystore: InputStream = getClass.getClassLoader.getResourceAsStream("server.p12")
//require(keystore != null, "Keystore required!")
ks.load(keystore, password)
val keyManagerFactory: KeyManagerFactory = KeyManagerFactory.getInstance("SunX509")
keyManagerFactory.init(ks, password)
val tmf: TrustManagerFactory = TrustManagerFactory.getInstance("SunX509")
tmf.init(ks)
val sslContext: SSLContext = SSLContext.getInstance("TLS")
sslContext.init(keyManagerFactory.getKeyManagers, tmf.getTrustManagers, SecureRandom.getInstanceStrong)
val https: HttpsConnectionContext = ConnectionContext.https(sslContext)
// sets default context to HTTPS – all Http() bound servers for this ActorSystem will use HTTPS from now on
Http().setDefaultServerHttpContext(https)
val route: Route= cors(settings) {
post {
path("") {
entity(as[String]) {payload=>
val rec = new PR("Events", 0, UUID.randomUUID().toString, payload)
producer.send(rec)
println(rec)
complete(HttpEntity(ContentTypes.`text/html(UTF-8)`, ""))
}
}
}
}
//val bindingFuture = Http().bindAndHandle(route, "54.85.112.231",9000,connectionContext = https)
val bindingFuture = Http().bindAndHandle(route, "54.85.112.231:9000",connectionContext = https)
答案 0 :(得分:0)
服务器绑定的地址错误。 graphql安装在那个阻止akka http服务的客户上。通过更改服务器,它工作正常。