Skip to content

Commit

Permalink
Replace async-http-client with armeria
Browse files Browse the repository at this point in the history
  • Loading branch information
danslapman committed Jan 26, 2023
1 parent 1669671 commit d959360
Show file tree
Hide file tree
Showing 11 changed files with 1,158 additions and 237 deletions.
39 changes: 20 additions & 19 deletions backend/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -57,25 +57,26 @@ val mockingbird = (project in file("mockingbird"))
Dependencies.glass
).flatten,
libraryDependencies ++= Seq(
"com.iheart" %% "ficus" % "1.5.0",
"io.circe" %% "circe-config" % "0.8.0",
"com.nrinaudo" %% "kantan.xpath" % "0.5.2",
"com.lihaoyi" %% "scalatags" % "0.9.1",
"tf.tofu" %% "derevo-circe" % Versions.derevo,
"org.webjars.npm" % "swagger-ui-dist" % "3.32.5",
"eu.timepit" %% "fs2-cron-core" % "0.2.2",
"com.softwaremill.sttp.client3" %% "async-http-client-backend-zio" % "3.7.2",
"com.softwaremill.sttp.client3" %% "circe" % "3.7.2",
"org.apache.tika" % "tika-core" % "2.1.0",
"io.scalaland" %% "chimney" % "0.6.1",
"com.ironcorelabs" %% "cats-scalatest" % "3.0.8" % Test,
"com.google.code.findbugs" % "jsr305" % "3.0.2" % Optional,
"com.github.dwickern" %% "scala-nameof" % "3.0.0" % Provided,
"com.github.os72" % "protobuf-dynamic" % "1.0.1",
"com.github.geirolz" %% "advxml-core" % "2.5.1",
"com.github.geirolz" %% "advxml-xpath" % "2.5.1",
"io.estatico" %% "newtype" % "0.4.4",
"org.slf4j" % "slf4j-api" % "1.7.30" % Provided
"com.iheart" %% "ficus" % "1.5.0",
"io.circe" %% "circe-config" % "0.8.0",
"com.nrinaudo" %% "kantan.xpath" % "0.5.2",
"com.lihaoyi" %% "scalatags" % "0.9.1",
"tf.tofu" %% "derevo-circe" % Versions.derevo,
"org.webjars.npm" % "swagger-ui-dist" % "3.32.5",
"eu.timepit" %% "fs2-cron-core" % "0.2.2",
"com.softwaremill.sttp.client3" %% "armeria-backend-zio" % Versions.sttp,
"com.softwaremill.sttp.client3" %% "circe" % Versions.sttp,
"org.javassist" % "javassist" % "3.29.2-GA", // Armeria dependency
"org.apache.tika" % "tika-core" % "2.1.0",
"io.scalaland" %% "chimney" % "0.6.1",
"com.ironcorelabs" %% "cats-scalatest" % "3.0.8" % Test,
"com.google.code.findbugs" % "jsr305" % "3.0.2" % Optional,
"com.github.dwickern" %% "scala-nameof" % "3.0.0" % Provided,
"com.github.os72" % "protobuf-dynamic" % "1.0.1",
"com.github.geirolz" %% "advxml-core" % "2.5.1",
"com.github.geirolz" %% "advxml-xpath" % "2.5.1",
"io.estatico" %% "newtype" % "0.4.4",
"org.slf4j" % "slf4j-api" % "1.7.30" % Provided
),
Compile / unmanagedResourceDirectories += file("../frontend/dist")
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import scalapb.zio_grpc.ServerLayer
import scalapb.zio_grpc.ServiceList
import scalapb.zio_grpc.server.ZServerCallHandler

import com.linecorp.armeria.client.ClientFactory
import com.linecorp.armeria.client.WebClient
import com.linecorp.armeria.client.encoding.DecodingClient
import com.mongodb.ConnectionString
import io.grpc.ServerBuilder
import io.grpc.Status
Expand All @@ -14,7 +17,7 @@ import org.mongodb.scala.MongoCollection
import org.mongodb.scala.MongoDatabase
import org.mongodb.scala.bson.BsonDocument
import sttp.client3.SttpBackendOptions
import sttp.client3.asynchttpclient.zio.AsyncHttpClientZioBackend
import sttp.client3.armeria.zio.ArmeriaZioBackend
import tofu.logging.Logging
import tofu.logging.impl.ZUniversalLogging
import zio.managed.*
Expand Down Expand Up @@ -101,26 +104,42 @@ object Mockingbird extends scala.App {
ZLayer.scoped {
for {
pc <- ZIO.service[ProxyConfig]
scopedBackend <- AsyncHttpClientZioBackend.scoped(
pc.proxyServer.fold(SttpBackendOptions.Default) { psc =>
SttpBackendOptions.Default
.copy(proxy =
SttpBackendOptions
.Proxy(
psc.host,
psc.port,
(psc.`type`: @unchecked) match {
case ProxyServerType.Http => SttpBackendOptions.ProxyType.Http
case ProxyServerType.Socks => SttpBackendOptions.ProxyType.Socks
},
psc.nonProxy.to(List),
psc.auth.map(psa => SttpBackendOptions.ProxyAuth(psa.user, psa.password)),
psc.onlyProxy.to(List)
)
.some
)
}
)
sttpSettings = pc.proxyServer.fold(SttpBackendOptions.Default) { psc =>
SttpBackendOptions.Default
.copy(proxy =
SttpBackendOptions
.Proxy(
psc.host,
psc.port,
(psc.`type`: @unchecked) match {
case ProxyServerType.Http => SttpBackendOptions.ProxyType.Http
case ProxyServerType.Socks => SttpBackendOptions.ProxyType.Socks
},
psc.nonProxy.to(List),
psc.auth.map(psa => SttpBackendOptions.ProxyAuth(psa.user, psa.password)),
psc.onlyProxy.to(List)
)
.some
)
}
factory = ClientFactory
.builder()
.connectTimeoutMillis(sttpSettings.connectionTimeout.toMillis)
.pipe(b => sttpSettings.proxy.fold(b)(conf => b.proxyConfig(conf.asJavaProxySelector)))
.tlsNoVerifyHosts(pc.insecureHosts*)
.build()
webClient = WebClient
.builder()
.decorator(
DecodingClient
.builder()
.autoFillAcceptEncoding(false)
.strictContentEncoding(true)
.newDecorator()
)
.factory(factory)
.build()
scopedBackend <- ArmeriaZioBackend.scopedUsingClient(webClient)
} yield scopedBackend
},
mongoLayer,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
[
{
"name":"[B"
},
{
"name":"[Ljava.lang.String;"
},
{
"name":"[[B"
},
{
"name":"io.netty.channel.ChannelException"
},
Expand Down Expand Up @@ -48,6 +57,68 @@
{
"name":"io.netty.channel.unix.Socket"
},
{
"name":"io.netty.handler.ssl.OpenSslClientSessionCache"
},
{
"name":"io.netty.handler.ssl.OpenSslSessionCache",
"methods":[
{"name":"getSession","parameterTypes":["long","byte[]"] },
{"name":"sessionCreated","parameterTypes":["long","long"] }
]
},
{
"name":"io.netty.handler.ssl.ReferenceCountedOpenSslClientContext$ExtendedTrustManagerVerifyCallback"
},
{
"name":"io.netty.handler.ssl.ReferenceCountedOpenSslContext$AbstractCertificateVerifier",
"methods":[{"name":"verify","parameterTypes":["long","byte[][]","java.lang.String"] }]
},
{
"name":"io.netty.internal.tcnative.Buffer"
},
{
"name":"io.netty.internal.tcnative.CertificateCallbackTask",
"methods":[{"name":"<init>","parameterTypes":["long","byte[]","byte[][]","io.netty.internal.tcnative.CertificateCallback"] }]
},
{
"name":"io.netty.internal.tcnative.CertificateVerifierTask",
"methods":[{"name":"<init>","parameterTypes":["long","byte[][]","java.lang.String","io.netty.internal.tcnative.CertificateVerifier"] }]
},
{
"name":"io.netty.internal.tcnative.Library"
},
{
"name":"io.netty.internal.tcnative.NativeStaticallyReferencedJniMethods"
},
{
"name":"io.netty.internal.tcnative.SSL"
},
{
"name":"io.netty.internal.tcnative.SSLContext"
},
{
"name":"io.netty.internal.tcnative.SSLPrivateKeyMethodDecryptTask",
"methods":[{"name":"<init>","parameterTypes":["long","byte[]","io.netty.internal.tcnative.AsyncSSLPrivateKeyMethod"] }]
},
{
"name":"io.netty.internal.tcnative.SSLPrivateKeyMethodSignTask",
"methods":[{"name":"<init>","parameterTypes":["long","int","byte[]","io.netty.internal.tcnative.AsyncSSLPrivateKeyMethod"] }]
},
{
"name":"io.netty.internal.tcnative.SSLPrivateKeyMethodTask",
"fields":[{"name":"resultBytes"}]
},
{
"name":"io.netty.internal.tcnative.SSLSession"
},
{
"name":"io.netty.internal.tcnative.SSLTask",
"fields":[
{"name":"complete"},
{"name":"returnValue"}
]
},
{
"name":"java.io.FileDescriptor",
"fields":[{"name":"fd"}]
Expand All @@ -66,6 +137,15 @@
{"name":"loadClass","parameterTypes":["java.lang.String"] }
]
},
{
"name":"java.lang.Exception"
},
{
"name":"java.lang.IllegalArgumentException"
},
{
"name":"java.lang.NullPointerException"
},
{
"name":"java.lang.OutOfMemoryError"
},
Expand All @@ -75,6 +155,8 @@
{
"name":"java.lang.String",
"methods":[
{"name":"<init>","parameterTypes":["byte[]"] },
{"name":"getBytes","parameterTypes":[] },
{"name":"lastIndexOf","parameterTypes":["int"] },
{"name":"substring","parameterTypes":["int"] }
]
Expand Down
Loading

0 comments on commit d959360

Please sign in to comment.