Skip to content

Commit 61efce6

Browse files
committed
Fix deprecated issue
1 parent 867039b commit 61efce6

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed

tests/src/test/scala/system/basic/HttpProxy.scala

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,14 @@
1616
*/
1717
package system.basic
1818
import java.net.ServerSocket
19-
20-
import akka.http.scaladsl.{Http, HttpsConnectionContext}
19+
import akka.http.scaladsl.{ConnectionContext, Http}
2120
import akka.http.scaladsl.model.{HttpRequest, HttpResponse, Uri}
2221
import akka.http.scaladsl.model.Uri.Authority
2322
import akka.http.scaladsl.server.Route
24-
import akka.stream.ActorMaterializer
2523
import akka.stream.scaladsl.{Sink, Source}
26-
import com.typesafe.sslconfig.akka.AkkaSSLConfig
2724
import common.{WskActorSystem, WskProps}
28-
import common.rest.{AcceptAllHostNameVerifier, SSL}
29-
import javax.net.ssl.HostnameVerifier
25+
26+
import javax.net.ssl.SSLContext
3027
import org.scalatest.Suite
3128
import org.scalatest.concurrent.ScalaFutures
3229

@@ -43,7 +40,6 @@ import scala.concurrent.duration._
4340
trait HttpProxy extends WskActorSystem with ScalaFutures {
4441
self: Suite =>
4542

46-
implicit val materializer: ActorMaterializer = ActorMaterializer()
4743
implicit val testConfig: PatienceConfig = PatienceConfig(1.minute)
4844

4945
def withProxy(check: (WskProps, ListBuffer[(HttpRequest, HttpResponse)]) => Unit)(implicit wp: WskProps): Unit = {
@@ -64,7 +60,7 @@ trait HttpProxy extends WskActorSystem with ScalaFutures {
6460
handler
6561
}
6662

67-
val binding = Http(actorSystem).bindAndHandle(handler = proxy, interface = "localhost", port = port)
63+
val binding = Http(actorSystem).newServerAt(interface = "localhost", port = port).bindFlow(proxy)
6864
binding.map { b =>
6965
val proxyProps = wp.copy(apihost = s"http://localhost:$port")
7066
check(proxyProps, requests)
@@ -94,19 +90,20 @@ trait HttpProxy extends WskActorSystem with ScalaFutures {
9490
}
9591

9692
private def httpsConnectionContext() = {
97-
val sslConfig = AkkaSSLConfig().mapSettings { s =>
98-
s.withHostnameVerifierClass(classOf[AcceptAllHostNameVerifier].asInstanceOf[Class[HostnameVerifier]])
99-
}
100-
//SSL.httpsConnectionContext initializes config which is not there in cli test
101-
//So inline the flow as we do not need client auth for this case
102-
new HttpsConnectionContext(SSL.nonValidatingContext(false), Some(sslConfig))
93+
ConnectionContext.httpsServer(() => {
94+
val sslContext = SSLContext.getDefault
95+
val engine = sslContext.createSSLEngine()
96+
engine.setUseClientMode(false)
97+
engine.setNeedClientAuth(false)
98+
engine
99+
})
103100
}
104101

105102
private def proxyRequest(req: HttpRequest, uri: Uri): HttpRequest = {
106103
//https://github.com/akka/akka-http/issues/64
107104
req
108-
.copy(headers = req.headers.filterNot(h => h.is("timeout-access")))
109-
.copy(uri = req.uri.copy(scheme = "", authority = Authority.Empty)) //Strip the authority as it refers to proxy
105+
.withHeaders(headers = req.headers.filterNot(h => h.is("timeout-access")))
106+
.withUri(uri = req.uri.copy(scheme = "", authority = Authority.Empty)) //Strip the authority as it refers to proxy
110107
}
111108

112109
private def freePort(): Int = {

0 commit comments

Comments
 (0)