From 84509f09748c36d7488ea7770969e84c147d821f Mon Sep 17 00:00:00 2001 From: Darren Gibson Date: Mon, 27 Feb 2023 18:48:32 -0600 Subject: [PATCH 1/3] Fix soap12_tagless template for scala 3 --- cli/src/main/resources/soap12_tagless.scala.template | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/src/main/resources/soap12_tagless.scala.template b/cli/src/main/resources/soap12_tagless.scala.template index 0ebc1aa5..6928907d 100644 --- a/cli/src/main/resources/soap12_tagless.scala.template +++ b/cli/src/main/resources/soap12_tagless.scala.template @@ -84,7 +84,7 @@ trait SoapClientsF[F[_]] { self: HttpClientsF[F] => address, headers ) - ftr.map { s: String => + ftr.map { (s: String) => try { val response = scala.xml.XML.loadString(s) scalaxb.fromXML[Envelope](response) From 5e1cbd1c0e3604ca702aad4bc7737a57b733ebfe Mon Sep 17 00:00:00 2001 From: Kevin Lee Date: Thu, 9 Mar 2023 00:02:55 +1100 Subject: [PATCH 2/3] Add support for http4s 0.22.x client generation - httpclients_http4s_0_22.scala.template --- .../httpclients_http4s_0_22.scala.template | 48 +++++++++++++++++++ .../scalaxb/compiler/wsdl11/Driver.scala | 1 + 2 files changed, 49 insertions(+) create mode 100644 cli/src/main/resources/httpclients_http4s_0_22.scala.template diff --git a/cli/src/main/resources/httpclients_http4s_0_22.scala.template b/cli/src/main/resources/httpclients_http4s_0_22.scala.template new file mode 100644 index 00000000..a4b1b2d6 --- /dev/null +++ b/cli/src/main/resources/httpclients_http4s_0_22.scala.template @@ -0,0 +1,48 @@ +package scalaxb + +import cats.effect._ +import org.http4s._ +import org.http4s.client._ +import org.typelevel.ci._ + +trait Http4sClientsF[F[_]] extends HttpClientsF[F] { self => + implicit protected def F: Concurrent[F] + protected def http4sClient: Client[F] + + protected lazy val httpClient: Http4sClientF[F] = new Http4sClientF[F] { + implicit protected def F: Concurrent[F] = self.F + protected def http4sClient: Client[F] = self.http4sClient + } + + trait Http4sClientF[G[_]] extends HttpClientF[G] { + implicit protected def F: Concurrent[G] + protected def http4sClient: Client[G] + + protected def entityEncoder: EntityEncoder[G, String] = + EntityEncoder[G, String] + protected def entityDecoder: EntityDecoder[G, String] = + EntityDecoder[G, String] + + override def request( + in: String, + address: java.net.URI, + headers: Map[String, String] + ): G[String] = + request( + in = in, + uri = Uri.unsafeFromString(address.toString), + headers = Headers(headers.map { case (name, value) => + Header.Raw(CIString(name), value) + }.toList) + ) + + protected def request(in: String, uri: Uri, headers: Headers): G[String] = { + http4sClient + .expect[String]( + Request[G](method = Method.POST, uri = uri) + .withEntity(in)(entityEncoder) + .putHeaders(headers) + )(entityDecoder) + } + } +} diff --git a/cli/src/main/scala/scalaxb/compiler/wsdl11/Driver.scala b/cli/src/main/scala/scalaxb/compiler/wsdl11/Driver.scala index 2b46338f..75deed43 100644 --- a/cli/src/main/scala/scalaxb/compiler/wsdl11/Driver.scala +++ b/cli/src/main/scala/scalaxb/compiler/wsdl11/Driver.scala @@ -265,6 +265,7 @@ class Driver extends Module { driver => } else Nil) ++ (if (config.generateHttp4sClient && config.httpClientStyle == HttpClientStyle.Tagless) config.http4sVersion match { case VersionPattern(0,21, _) => List(generateFromResource[To](Some("scalaxb"), "httpclients_http4s.scala", "/httpclients_http4s_0_21.scala.template")) + case VersionPattern(0,22, _) => List(generateFromResource[To](Some("scalaxb"), "httpclients_http4s.scala", "/httpclients_http4s_0_22.scala.template")) case VersionPattern(0,23, _) => List(generateFromResource[To](Some("scalaxb"), "httpclients_http4s.scala", "/httpclients_http4s_0_23.scala.template")) case _ => sys.error(s"Unsupported http4s version ${config.http4sVersion}"); Nil } From 3d937785cb01bde21e2e3f0547caf511ccbbb1be Mon Sep 17 00:00:00 2001 From: Emily Barber Date: Mon, 27 Mar 2023 17:07:54 +0200 Subject: [PATCH 3/3] Update soap11_tagless.scala.template --- cli/src/main/resources/soap11_tagless.scala.template | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/src/main/resources/soap11_tagless.scala.template b/cli/src/main/resources/soap11_tagless.scala.template index 2d6d701d..12cfe76f 100644 --- a/cli/src/main/resources/soap11_tagless.scala.template +++ b/cli/src/main/resources/soap11_tagless.scala.template @@ -86,7 +86,7 @@ trait Soap11ClientsF[F[_]] { self: HttpClientsF[F] => address, headers.toMap ) - ftr map { s: String => + ftr map { (s: String) => try { val response = scala.xml.XML.loadString(s) scalaxb.fromXML[Envelope](response)