akka-http

How to use Akka-HTTP client websocket send message

有些话、适合烂在心里 提交于 2019-12-03 08:47:25
I'm trying client-side websocket by following doc at webSocketClientFlow . sample code is: import akka.actor.ActorSystem import akka.Done import akka.http.scaladsl.Http import akka.stream.ActorMaterializer import akka.stream.scaladsl._ import akka.http.scaladsl.model._ import akka.http.scaladsl.model.ws._ import scala.concurrent.Future object WebSocketClientFlow { def main(args: Array[String]) = { implicit val system = ActorSystem() implicit val materializer = ActorMaterializer() import system.dispatcher // Future[Done] is the materialized value of Sink.foreach, // emitted when the stream

akka-http with multiple route configurations

隐身守侯 提交于 2019-12-03 05:58:35
Quick Background I am running through some examples learning the Akka HTTP stack for creating a new REST project (completely non-UI). I have been using and augmenting the Akka HTTP Microservice Example to work through a bunch of use cases and configurations and have been pleasantly surprised by how well Scala & Akka HTTP work. Current Setup Currently I have a configuration like this: object AkkaHttpMicroservice extends App with Service { override implicit val system = ActorSystem() override implicit val executor = system.dispatcher override implicit val materializer = ActorMaterializer()

Spray, Akka-http and Play, Which is the best bet for a new HTTP/REST project

半腔热情 提交于 2019-12-03 05:31:58
问题 I'm going to develop new HTTP/REST services using Scala and Akka Actors. I have experience working with Play, but I don't really need a complete web Framework. From what I read, I think Spray is a suitable choice. My question come from the future of Spray after the new arrived AKKA-HTTP. Does the Spray project will grow independently from the Akka-HTTP project, or are the two project going to be merged into one Akka-HTTTP? What is the impact of this if I start developing with Spray? Also I

Chain Akka-http-client requests in a Stream

我只是一个虾纸丫 提交于 2019-12-03 03:08:39
I would like to chain http request using akka-http-client as Stream. Each http request in a chain depends on a success/response of a previous requests and uses it to construct a new request. If a request is not successful, the Stream should return the response of the unsuccessful request. How can I construct such a stream in akka-http? which akka-http client level API should I use? If you're making a web crawler, have a look at this post . This answer tackles a more simple case, such as downloading paginated resources, where the link to the next page is in a header of the current page response

AkkaHTTP: Getting content out of an HttpEntity

天涯浪子 提交于 2019-12-02 10:21:59
I'm working with AkkaHTTP in Scala, trying to interact with an API, but I'm having some trouble getting data with certain API calls. Basically, I have a curl command which works in my terminal for any valid API call to this certain API, but in my current code I only get the actual data for calls whose responses are small enough. My first attempt was using sys.process._ and the !! method on a string with "curl (url) -X GET -H \"Authorization: Bearer (auth token)\" (which is the command that works in my terminal), but that failed with an error in scala due to issues parsing the header; so after

How to make a POST call to self-certified server with akka-http

自闭症网瘾萝莉.ら 提交于 2019-12-02 06:01:59
I have a akka-streams topology, where I make a POST call using akka-http. I am getting following error when hitting the post request to a un-secure server(having self-signed certs). It is a internal server, so I am fine from security point of view. javax.net.ssl.SSLHandshakeException: General SSLEngine problem at sun.security.ssl.Handshaker.checkThrown(Handshaker.java:1478) ~[?:1.8.0_131] at sun.security.ssl.SSLEngineImpl.checkTaskThrown(SSLEngineImpl.java:535) ~[?:1.8.0_131] at sun.security.ssl.SSLEngineImpl.readNetRecord(SSLEngineImpl.java:813) ~[?:1.8.0_131] at sun.security.ssl

How to respond with the result of an actor call?

怎甘沉沦 提交于 2019-12-01 18:35:03
问题 We are looking at using Akka-HTTP Java API - using Routing DSL. It's not clear how to use the Routing functionality to respond to an HttpRequest; using an Untyped Akka Actor. For example, upon matching a Route path, how do we hand off the request to a "handler" ActorRef, which will then respond with a HttpResponse in a asynchronous way? A similar question was posted on Akka-User mailing list, but with no followup solutions as such - https://groups.google.com/d/msg/akka-user/qHe3Ko7EVvg/KC-aKz

Scala Akka HTTP casting parameter as java.time.ZonedDateTime

强颜欢笑 提交于 2019-12-01 12:38:59
I'm working on a REST service using Akka HTTP (in Scala). I would like a parameter that is passed in to a http get request to be converted to the ZonedDateTime type. The code works fine if I try to use String or Int but fails with a ZonedDateTime type. The code would look like so: parameters('testparam.as[ZonedDateTime]) Here is the error that I'm seeing: Error:(23, 35) type mismatch; found : akka.http.scaladsl.common.NameReceptacle[java.time.ZonedDateTime] required: akka.http.scaladsl.server.directives.ParameterDirectives.ParamMagnet parameters('testparam.as[ZonedDateTime]){ If I add more

Scala Akka HTTP casting parameter as java.time.ZonedDateTime

人走茶凉 提交于 2019-12-01 11:59:21
问题 I'm working on a REST service using Akka HTTP (in Scala). I would like a parameter that is passed in to a http get request to be converted to the ZonedDateTime type. The code works fine if I try to use String or Int but fails with a ZonedDateTime type. The code would look like so: parameters('testparam.as[ZonedDateTime]) Here is the error that I'm seeing: Error:(23, 35) type mismatch; found : akka.http.scaladsl.common.NameReceptacle[java.time.ZonedDateTime] required: akka.http.scaladsl.server

Idiomatic way to use Spark DStream as Source for an Akka stream

試著忘記壹切 提交于 2019-12-01 06:03:28
I'm building a REST API that starts some calculation in a Spark cluster and responds with a chunked stream of the results. Given the Spark stream with calculation results, I can use dstream.foreachRDD() to send the data out of Spark. I'm sending the chunked HTTP response with akka-http: val requestHandler: HttpRequest => HttpResponse = { case HttpRequest(HttpMethods.GET, Uri.Path("/data"), _, _, _) => HttpResponse(entity = HttpEntity.Chunked(ContentTypes.`text/plain`, source)) } For simplicity, I'm trying to get plain text working first, will add JSON marshalling later. But what is the