spray-client

Can I set a timeout and number of retries on a specific pipeline request?

为君一笑 提交于 2021-02-18 10:34:41
问题 When using spray's pipelining to make an HTTP request like this: val urlpipeline = sendReceive ~> unmarshal[String] urlpipeline { Get(url) } is there a way to specify a timeout for the request and the number of times it should retry for that specific request? All the documentation I've found only references doing in a config (and even then I can't seem to get it to work). thx 回答1: With the configuration file I use Spray 1.2.0 in an Akka system. Inside my actor, I import the existing Akka

Spray Unzip HttpResponse

梦想的初衷 提交于 2019-12-24 08:35:29
问题 I'm using Spray API(spray-client) to hit an external URL and I'm getting gzipped HttpResponse. How do I unzip this HttpResponse to get its entity(json, in my case)? val future: Future[HttpResponse] = (IO(Http) ? Get(uri)).mapTo[HttpResponse] val response = Await.result(future, Duration.inf) val json = response.entity Here, json is gzipped. How do I unzip it? 回答1: You need to use pipelining and the decode directive. Like in this example. Modifying that example your code would look something

How to fix the Dropping Close since the SSL connection is already closing error in spray

三世轮回 提交于 2019-12-21 03:09:29
问题 I’m making a call to an API, but most of the time I keep getting an error: “ Dropping Close since the SSL connection is already closing ” and “ Premature connection close (the server doesn't appear to support request pipelining) .” Like 90% of the time I get that error, meaning: on very rare occasions the query does return the data it supposed to. To make sure this wasn’t the API’s server issue, I replicate the same query using Node.js (Express and Request libs) and it works every time. It

Generic Spray-Client

删除回忆录丶 提交于 2019-12-13 00:43:35
问题 I'm trying to create a generic HTTP client in Scala using spray. Here is the class definition: object HttpClient extends HttpClient class HttpClient { implicit val system = ActorSystem("api-spray-client") import system.dispatcher val log = Logging(system, getClass) def httpSaveGeneric[T1:Marshaller,T2:Unmarshaller](uri: String, model: T1, username: String, password: String): Future[T2] = { val pipeline: HttpRequest => Future[T2] = logRequest(log) ~> sendReceive ~> logResponse(log) ~>

akka timeout when using spray client for multiple request

孤街醉人 提交于 2019-12-12 10:45:28
问题 Using spray 1.3.2 with akka 2.3.6. (akka is used only for spray). I need to read huge files and for each line make a http request. I read the files line by line with iterator, and for each item make the request. It run successfully for some of the lines but at some time it start to fail with: akka.pattern.AskTimeoutException: Ask timed out on [Actor[akka://default/user/IO-HTTP#-35162984]] after [60000 ms] . I first thought I overloading the service, so I set the "spray.can.host-connector.max

How can I tell a specific spray-client request to follow all redirects?

我与影子孤独终老i 提交于 2019-12-12 03:49:57
问题 I have a specific pipeline in my app that must follow all redirects (let's say up to 50 for sanity's sake), across any domain and protocol (e.g. it could follow http://somewhere.com to https://somewhere.else.com), but only for GET requests. No other pipeline in my app should do this. Here's what it looks like now: val pipeline = sendReceive ~> decode(Gzip) ~> decode(Deflate) ~> unmarshal[String] How can I specify this inside the pipeline's configuration in a host-agnostic manner (i.e. not via

spray-testkit: could not find implicit value for parameter ta:

妖精的绣舞 提交于 2019-12-11 09:36:13
问题 First time spray user close to ripping hair out. trait SampleService extends SimpleRoutingApp with JsonProtocol with SprayJsonSupport { implicit val system: ActorSystem = ActorSystem("test") implicit def context: ExecutionContext = system.dispatcher startServer(interface = "localhost", port = 8888) { path("test") { _ => get { complete { "test" } } } } } import org.scalatest.FlatSpec import spray.testkit.ScalatestRouteTest class ApiSpec extends FlatSpec with ScalatestRouteTest with

spray-client throwing “Too many open files” exception when giving more concurrent requests

冷暖自知 提交于 2019-12-10 11:18:41
问题 I have a spray http client which is running in a server X, which will make connections to server Y. Server Y is kind of slow(will take 3+ sec for a request) This is my http client code invocation: def get() { val result = for { response <- IO(Http).ask(HttpRequest(GET,Uri(getUri(msg)),headers)).mapTo[HttpResponse] } yield response result onComplete { case Success(res) => sendSuccess(res) case Failure(error) => sendError(res) } } These are the configurations I have in application.conf: spray

spray-client throwing “Too many open files” exception when giving more concurrent requests

非 Y 不嫁゛ 提交于 2019-12-06 07:37:25
I have a spray http client which is running in a server X, which will make connections to server Y. Server Y is kind of slow(will take 3+ sec for a request) This is my http client code invocation: def get() { val result = for { response <- IO(Http).ask(HttpRequest(GET,Uri(getUri(msg)),headers)).mapTo[HttpResponse] } yield response result onComplete { case Success(res) => sendSuccess(res) case Failure(error) => sendError(res) } } These are the configurations I have in application.conf: spray.can { client { request-timeout = 30s response-chunk-aggregation-limit = 0 max-connections = 50 warn-on

How to fix the Dropping Close since the SSL connection is already closing error in spray

Deadly 提交于 2019-12-03 10:26:37
I’m making a call to an API, but most of the time I keep getting an error: “ Dropping Close since the SSL connection is already closing ” and “ Premature connection close (the server doesn't appear to support request pipelining) .” Like 90% of the time I get that error, meaning: on very rare occasions the query does return the data it supposed to. To make sure this wasn’t the API’s server issue, I replicate the same query using Node.js (Express and Request libs) and it works every time. It makes me almost sure is a spray bug . Here's an example of the code : case class MyClass(user: String,