Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 01:54

    mergify[bot] on master

    Update zio, zio-streams to 1.0.… Merge pull request #1111 from s… (compare)

  • 01:54
    mergify[bot] closed #1111
  • 01:22
    mergify[bot] labeled #1111
  • 01:21
    scala-steward opened #1111
  • Sep 20 07:20
    bartekzylinski assigned #1065
  • Sep 18 06:58

    mergify[bot] on master

    Update cats-effect, cats-effect… Merge pull request #1110 from s… (compare)

  • Sep 18 06:58
    mergify[bot] closed #1110
  • Sep 18 06:24
    mergify[bot] labeled #1110
  • Sep 18 06:24
    scala-steward opened #1110
  • Sep 18 01:20
    mergify[bot] labeled #1109
  • Sep 18 01:19
    scala-steward opened #1109
  • Sep 17 17:57
    mergify[bot] labeled #1108
  • Sep 17 17:56
    scala-steward commented #1093
  • Sep 17 17:56
    scala-steward opened #1108
  • Sep 16 14:38

    mergify[bot] on master

    Update zio-interop-reactivestre… Merge pull request #1107 from s… (compare)

  • Sep 16 14:38
    mergify[bot] closed #1107
  • Sep 16 14:06
    mergify[bot] labeled #1107
  • Sep 16 14:05
    scala-steward opened #1107
  • Sep 15 13:58

    mergify[bot] on master

    Update zio-opentelemetry, zio-o… Merge pull request #1106 from s… (compare)

  • Sep 15 13:58
    mergify[bot] closed #1106
Glen Marchesani
@fizzy33
I am not in front of a computer something like this though
    request
      .response(asByteArray)
Brent
@brentsony
For example, where url returns an image (such as a .png).
Glen Marchesani
@fizzy33
so
val req = quickRequest.readTimeout(timeoutMs.millis).get(uri"""$url""").response(asByteArray)
making sure you have
import sttp.client3._
I think should do it for you
Brent
@brentsony
Yep - that did it! Thank you.
Andrii Ilin
@AndreyIlin
Hi, guys.
Where can I find some kind of compatibility matrix for sttp-model, getting NoClassDefFound when try to use tapir 0.15.x and sttp client3 in the same project?
1 reply
eugeniyk
@eugeniyk

Hi, guys.
Where can I find some kind of compatibility matrix for sttp-model, getting NoClassDefFound when try to use tapir 0.15.x and sttp client3 in the same project?

Faced same in our projects
Concrete classes:

  1. MediaType.copy
    https://www.javadoc.io/doc/com.softwaremill.sttp.model/core_2.12/1.4.0/sttp/model/MediaType.html. vs
    https://www.javadoc.io/doc/com.softwaremill.sttp.model/core_2.12/1.1.4/sttp/model/MediaType.html

  2. Uri (host: String vs host: Option[String])

@adamw I think it's time to release core v2 with new package names to achieve compatibility between v2 and v3
at the same time you may want to consider using MIMA?

4 replies
etienne
@crakjie

is it cheating to do

.response(asStream(MonixStreams)(i => Task(i)))

instead of

.response(asStreamUnsafe(MonixStreams))

?

1 reply
Glen Marchesani
@fizzy33
I am trying to limit the total number of http connections at any given moment. Is there an idiomatic way to do this ? I tried using the AsyncHttpCLient setting for that BUT the AsyncHttpClient appears to fail when you meet that number instead of waiting for a connection...
11:23:50.465 | DEBUG | 18 | a8.sync.http | http request failed on the 2 retry -- https://rm-api-dev-1-ext.goodville-dev.assure.dxc.com/riskmasterapi/events/34864/claimgc/12420/claimants - (http.scala:42)
sttp.client3.SttpClientException$ReadException: Exception when sending request: GET https://rm-api-dev-1-ext.goodville-dev.assure.dxc.com/riskmasterapi/events/34864/claimgc/12420/claimants
    at sttp.client3.SttpClientException$.defaultExceptionToSttpClientException(SttpClientException.scala:44)
    at sttp.client3.asynchttpclient.AsyncHttpClientBackend.$anonfun$adjustExceptions$1(AsyncHttpClientBackend.scala:227)
    at sttp.client3.SttpClientException$$anonfun$adjustExceptions$1.applyOrElse(SttpClientException.scala:57)
    at sttp.client3.SttpClientException$$anonfun$adjustExceptions$1.applyOrElse(SttpClientException.scala:56)
    at cats.ApplicativeError.$anonfun$recoverWith$1(ApplicativeError.scala:106)
    at cats.effect.IOFiber.handleErrorWithK(IOFiber.scala:1283)
    at cats.effect.IOFiber.failed(IOFiber.scala:1057)
    at cats.effect.IOFiber.uncancelableFailureK(IOFiber.scala:1308)
    at cats.effect.IOFiber.failed(IOFiber.scala:1059)
    at cats.effect.IOFiber.onCancelFailureK(IOFiber.scala:1296)
    at cats.effect.IOFiber.failed(IOFiber.scala:1058)
    at cats.effect.IOFiber.unmaskFailureK(IOFiber.scala:1318)
    at cats.effect.IOFiber.failed(IOFiber.scala:1060)
    at cats.effect.IOFiber.onCancelFailureK(IOFiber.scala:1296)
    at cats.effect.IOFiber.failed(IOFiber.scala:1058)
    at cats.effect.IOFiber.runLoop(IOFiber.scala:752)
    at cats.effect.IOFiber.asyncContinueSuccessfulR(IOFiber.scala:1132)
    at cats.effect.IOFiber.run(IOFiber.scala:126)
    at cats.effect.unsafe.WorkerThread.run(WorkerThread.scala:359)
Caused by: org.asynchttpclient.exception.TooManyConnectionsException: Too many connections: 20
anyone have any recommendations on how to do this in a composable way...
I could hack this to make it work inside our retry framework but I am figuring someone has had to do this already
hmm even simpler I can just wrap my use in a semaphore
3 replies
Glen Marchesani
@fizzy33
nm and thanks for listening
harrylaou
@harrylaou:matrix.org
[m]

Hi ,
I am trying to stub a response to be used in a asStreamUnsafe response.
When using a asByteArray response the stub is working.

When using the a asStreamUnsafe response
I am getting

An unchecked error was produced.
java.lang.ClassCastException: [B incompatible with scala.util.Either

I have prepared a scastie similar to what I am doing. https://scastie.scala-lang.org/QOf83EyOSZCQsfnGoZrUPg
The only difference is that instead of a typed error I am using a throwable in scastie.

and the error in scastie is

An unchecked error was produced.
java.lang.ClassCastException: java.lang.String cannot be cast to scala.util.Either

I am not sure if it is related to softwaremill/sttp#389, and is a similar thing that has to do with the stub
or if I am doing something wrong ?

Any help would be appreciated.

harrylaou
@harrylaou:matrix.org
[m]
Stubbing works for asStreamAlwaysUnsafe and when stubbing with .thenRespond(Response.ok(ZStream.fromIterable("Stub response".getBytes)))
( I have updated the scastie link)
What would be the correct way to stub for asStreamUnsafe ?
7 replies
Jeremiah Malina
@jjmalina

I'm trying to upgrade a spark app from Scala 2.11 to Scala 2.12 (I know it's old..) but currently running into this issue on sttp 2.2.9:

java.lang.NoSuchMethodError: scala.Product.$init$(Lscala/Product;)V
    at sttp.client.SttpBackendOptions.<init>(SttpBackendOptions.scala:12)
    at sttp.client.SttpBackendOptions$.<init>(SttpBackendOptions.scala:100)
    at sttp.client.SttpBackendOptions$.<clinit>(SttpBackendOptions.scala)
    at sttp.client.HttpURLConnectionBackend$.apply$default$1(HttpURLConnectionBackend.scala:308)
    at com.newscred.services.NewsCredAnalyticsAPIClient.<init>(NewsCredAnalyticsAPI.scala:46)

The offending line of code is implicit var backend = HttpURLConnectionBackend()
Anyone have an idea what the issue might be? Thanks in advance :)

harrylaou
@harrylaou:matrix.org
[m]
@jjmalina: usually , when NoSuchMethodError happens, it is a mixup with library versions.
you can use sbt dependencyTree to see the versions of the library in question, and then use exclude in build.sbt exclude transitive dependencies
Jeremiah Malina
@jjmalina
@harrylaou:matrix.org thanks! how do I know which transitive dependencies to exclude? is it correct to assume that the java.lang.NoSuchMethodError: scala.Product.$init$(Lscala/Product;) error implies that the wrong version of scala is being used somehow?
it looks like everything is ok with scala 2.12
Jeremiah Malina
@jjmalina
Turns out that the issue was that I was running my app in EMR on Spark which was running Scala 2.11, upgraded EMR and it solved the error I got with sttp, though now I'm having a similar error with json4s :/
Saad Khawaja
@SaadKhawaja
The sttp doc page here https://sttp.softwaremill.com/en/latest/backends/http4s.html ask to use "com.softwaremill.sttp.client3" %% "http4s-backend" % "3.3.6" but this is not in maven central. Where could this be found. Thanks.
8 replies
Philippe Derome
@phderome
I’ve been toying with WebSocketZio and WebSocketStreamFs2 examples and I see the Fs2 example uses API asWebSocketStream which is quite nice and useful and the Zio one uses asWebSocketAlways which while useful is a bit less interesting. Would it make sense to extend both examples to achieve some parity on API usage (i.e. both using asWebSocketStream and asWebSocketAlways)? I didn’t look at the Akka example mind you.
4 replies
If there’s some interest, I could do a PR to add asWebSocketStream to th ZIO solution.
Philippe Derome
@phderome
Ashwin Bhaskar
@ashwinbhaskar
How can I mock requests and response when using AsyncHttpClientZioBackend.stubLayer? When using AsyncHttpClientZioBackend.stub I could do AsyncHttpClientZioBackend.stub.whenRequestMatches(...).thenResponse(...).
2 replies
Łukasz Drygała
@ldrygala
Hi guys, I would like to test a client that streams data from a websocket. Unfortunately, it fails with class sttp.ws.testing.WebSocketStub cannot be cast to class akka.stream.scaladsl.Flow (sttp.ws.testing.WebSocketStub and akka.stream.scaladsl.Flow are in unnamed module of loader 'app')
4 replies
Ashwin Bhaskar
@ashwinbhaskar
Is there an equivalent of akka.http.scaladsl.model.Uri's parseAndResolve for sttp.model.Uri?
1 reply
rabzu
@rabzu
How can I get BinaryStream from
(sttp.capabilities.Streams[sttp.capabilities.zio.ZioStreams] & Singleton)# BinaryStream?
I have:
val fileStream: (Streams[ZioStreams] & Singleton)#BinaryStream <- sttpClient
                            .send(downloadRequest)

uploadRequest = basicRequest.streamBody(ZioStreams)(fileStream)
Found:    (fileStream : 
  (sttp.capabilities.Streams[sttp.capabilities.zio.ZioStreams] & Singleton)#
    BinaryStream
)
Required: sttp.capabilities.zio.ZioStreams.BinaryStream²

where:    BinaryStream  is a type in class Streams with bounds 
          BinaryStream² is a type in trait ZioStreams which is an alias of zio.stream.Stream[Throwable, Byte]
rabzu
@rabzu
So error is in basicRequest.streamBody(ZioStreams)(fileStream)
9 replies
catostrophe
@catostrophe
The latest tapir 0.18.0 is CE2-only compatible and its http4s module depends on http4s 0.22.0-RC1, while sttp 3.3.9 CE2 http4s module depends on http4s 0.21.x, so they are incompatible. It may be force-fixed in sbt but the risk of runtime bincompat issues is high
6 replies
truongio
@truongio

Hi, I'm getting some weird EOF error from sttp that I'm unsure about.

o.h.b.p.Command$EOF$: EOF
from:

logger_name: "sttp.client3.logging.slf4j.Slf4jLoggingBackend"
logger_name: "sttp.tapir.server.http4s.Http4sServerInterpreter"

I'm using sttp client version 3.2.3. Does anyone know what might be causing this and how to resolve it?

3 replies
catostrophe
@catostrophe
@adamw for those who's still on CE2, can we have constistent versions of tapir 0.18.x and sttp 3.3.x compatible with each other and http4s 0.22.0 ?
8 replies
Julien Richard-Foy
@julienrf
Hello! What is the versioning scheme used by sttp? Are all the minor releases backward binary compatible? Are all the patch releases backward source compatible?
6 replies
Ravi
@r4ravi2008
Hi qq: Is there a zio integration with FetchBackend for scalajs?
2 replies
Looking for something like AsyncZioHttpBackend but for scalajs
Colin Aygalinc
@aygalinc

Hi, I'm getting weird behavior with AkkaSttpBackend & retry when one of the service I rely is down.
I have draw a small test case :
"When constraint server is in error then we " should " get an error when asking for constraint" in {
val sttp = AkkaHttpBackend()

val request: () => Future[String] = () => {
  println("Launch some stuff")
  val startTime = System.currentTimeMillis()

  basicRequest
    .get(uri"https://fake.url:9000")
    .response(asString.getRight)
    .send(sttp)
    .map(_.body)
    .recoverWith {
      case error => {

        println(s"${System.currentTimeMillis() - startTime} millis")
        println(error.printStackTrace())
        Future.failed(error)

      }
    }
}

implicit val successForFuture: Success[String] = Success.always

recoverToSucceededIf[SttpClientException] {
  val response = retry.Pause(max = 3, delay = 20.milliseconds).apply {
    request
  }
  response
}

}

What I observe is inconsistent timeout for detecting the failure : 4366 millis - 200920 millis - 117760 millis - 138533 millis
So basically error detection occurs btw ' seconds to more than 3 minutes
Colin Aygalinc
@aygalinc
I expect that the detection of this error would be quicker or at least take the Default 30 second of timeout no ?
uneewk
@uneewk
I am struggling to POST with a simple payload in json using sttp. Wondering if anyone can help me correct what I'm doing wrong. I get a response back that the payload is invalid. I can also see the curl equivalent of my request and it's not what I intend as the data is not being sent as json
def sendMessage(message: String): Unit = {
    val request = basicRequest
      .contentType(ct = "application/json")
      .body(Map("text" -> message))
      .post(uri"<URI goes here>")

    request.send().body match {
      case Left(error) => logger.error(s"Could not send message: $message due to $error")
      case Right(_) => ()
    }
  }
3 replies
Mike Limansky
@limansky

Hi. I'm pretty new both to sttp and zio, so my question might be pretty simple, however I've got stuck with testing.

I've created a service which uses SttpClient. I'd like to test it. So I create service like:

val myService = (ZLayer.succeed(Config("1234", "abc")) ++ HttpClientZioBackend.stubLayer) >>> MyService.live

val stubEffect = for {
        _ <- whenRequestMatches(_.uri.toString().endsWith("/api/v1/doit")).thenRespond("response")
      } yield ()

val result = for {
        a <- MyService.doIt("Some input")
      } yield assert(a)(isRight(equalTo("response")))

result.provideLayer(myService)

What is not clear is how to pass the stubFffect to provide a mocked server response. Are there any examples?

5 replies
Fredrik Wärnsberg
@frekw
What happened to https://github.com/softwaremill/sttp/issues/451#issuecomment-675533291 ? I can't seem to find failLeft anywhere in the code base.
2 replies
Swoorup Joshi
@Swoorup
what is the equivalent package for sttp.tapir.server.stub.*?
in scala 3
1 reply
joules-o
@joules-o
I'm trying to migrate from sttp client 2 to client3, but my linter fails on Any. I don't want to turn this off, but I'd really rather not add ignore annotations to some 40-odd endpoints. Is there some version of a no-op stream type I can use instead of Any?
6 replies