class SamplesHandler extends Mongo {


  def get(database: String, name: String) = {
    println("sending samples")
    val samples = getSamples(database, Array(name))
    complete(samples)
  }


  def post(req: HttpRequest)(implicit m: ActorMaterializer, e: 
ExecutionContextExecutor) = {
    println("processing sample")
    val body = Await.result(req.entity.toStrict(5.seconds).map(_.data.
decodeString("UTF-8")), Inf)
    val database = "jaar"
    insertSample(database, body)
    complete(StatusCodes.OK)
  }
}


val route =
      path("") {
        get {
          parameter("database", "name") {(database, name) => new 
SamplesHandler().get(database, name)}
        } ~
        post {
          extractRequest {(request) => new SamplesHandler().post(request)}
        }
      }


    val bindingFuture = Http().bindAndHandle(route, "0.0.0.0", 4040)
    println(s"Server online at http://localhost:4040/\nPress RETURN to 
stop...")
    StdIn.readLine() // let it run until user presses return
    bindingFuture
      .flatMap(_.unbind()) // trigger unbinding from the port
      .onComplete(_ => system.terminate()) // and shutdown when done


  }


[ERROR] [04/10/2017 11:03:35.992] [default-akka.actor.default-dispatcher-7] 
[akka.actor.ActorSystemImpl(default)] Error during processing of request: 
'HttpEntity.toStrict 
timed out after 5 seconds while still waiting for outstanding data'. 
Completing with 500 Internal Server Error response.


I have a problem with post requests. After starting the server, the first 
post request always works correctly. The data is read from the body of the 
request and passed to the insertSample method. But, starting from the 
second request, they start timing out when trying to read the body.

-- 
>>>>>>>>>>      Read the docs: http://akka.io/docs/
>>>>>>>>>>      Check the FAQ: 
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>>      Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups "Akka 
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to