private val connectionsSource: Source[IncomingConnection, Future[ServerBinding]] =
Tcp(context.system)
.bind(transportConfig.getHost, transportConfig.getPort)
private val connectionsSink: Sink[IncomingConnection, Future[Done]] =
Sink.foreach(handleIncomingConnection)
private val connectionsGraph: RunnableGraph[(Future[ServerBinding], Future[Done])] =
connectionsSource.toMat(connectionsSink)(Keep.both)
private val echo: Flow[ByteString, ByteString, NotUsed] = Flow[ByteString]
.via(Framing.delimiter(ByteString("\n"), maximumFrameLength = 256, allowTruncation = true))
.map(_.utf8String)
.map { text =>
log.info(s"Received message: $text")
ByteString(text + "!!!\n")
}
def handleIncomingConnection(connection: IncomingConnection) {
log.info(s"New client at ${connection.remoteAddress}")
val flowGraph = connection.flow.joinMat(echo)(Keep.both)
flowGraph.run()
}
private val mat = connectionsGraph.run()
def initSslContext(): SSLContext = {
val password = "password"
val keyStore = KeyStore.getInstance(KeyStore.getDefaultType)
keyStore.load(getClass.getResourceAsStream("/keystore"), password.toCharArray)
val trustStore = KeyStore.getInstance(KeyStore.getDefaultType)
trustStore.load(getClass.getResourceAsStream("/truststore"), password.toCharArray)
val keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm)
keyManagerFactory.init(keyStore, password.toCharArray)
val trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm)
trustManagerFactory.init(trustStore)
val context = SSLContext.getInstance("TLS")
context.init(keyManagerFactory.getKeyManagers, trustManagerFactory.getTrustManagers, new SecureRandom)
for (protocol <- context.getSupportedSSLParameters.getProtocols) {
log.info(s"Supported protocol: $protocol")
}
context
}
--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ: http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to akka-user+unsubscribe@googlegroups.com.
To post to this group, send email to akka...@googlegroups.com.
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and stop receiving emails from it, send an email to akka-user+...@googlegroups.com.
On 13 March 2017 at 22:26:51, Pablo Milanese (pablomi...@gmail.com) wrote:
val sslConfig: AkkaSSLConfig = AkkaSSLConfig.get(system)
TlsSupport.atop (tls)Val tlsSupport: BidiFlow [ByteString, TLSProtocol.SslTlsOutbound, TLSProtocol.SslTlsInbound, ByteString, NotUsed] =
BidiFlow.fromFlows (
Flow [ByteString] .map (TLSProtocol.SendBytes (_)),
Flow [TLSProtocol.SslTlsInbound] .collect (pf))
Val tls: BidiFlow [TLSProtocol.SslTlsOutbound, ByteString, ByteString, TLSProtocol.SslTlsInbound, NotUsed] =
TLS (sslContext, firstSession, role)