Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scala example doesn't terminate #235

Open
hbuerger opened this issue Feb 19, 2018 · 0 comments
Open

Scala example doesn't terminate #235

hbuerger opened this issue Feb 19, 2018 · 0 comments

Comments

@hbuerger
Copy link

Are you looking for help?

The current Play-WS standalone Scala example doesn't terminate.

sbt new scala/scala-seed.g8

Play WS Version (2.5.x / etc)

libraryDependencies += "com.typesafe.play" %% "play-ahc-ws-standalone" % "1.1.3",
libraryDependencies += "com.typesafe.play" %% "play-ws-standalone-json" % "1.1.3",

I used the following to create the project:

sbt new scala/scala-seed.g8

added the following to the build.sbt

libraryDependencies += "com.typesafe.play" %% "play-ahc-ws-standalone" % "1.1.3",
libraryDependencies += "com.typesafe.play" %% "play-ws-standalone-json" % "1.1.3",
libraryDependencies += "org.slf4j" % "slf4j-jdk14" % "1.7.9"

API (Scala / Java / Neither / Both)

Scala

Operating System (Ubuntu 15.10 / MacOS 10.10 / Windows 10)

Linux myMachine 4.13.0-32-generic #35~16.04.1-Ubuntu SMP Thu Jan 25 10:13:43 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

JDK (Oracle 1.8.0_72, OpenJDK 1.8.x, Azul Zing)

java version "1.8.0_161"
Java(TM) SE Runtime Environment (build 1.8.0_161-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)

Library Dependencies

Expected Behavior

sbt run returns

Actual Behavior

Output: Got a response OK

No prompt. I expect the example to terminate properly.

Reproducible Test Case

build.sbt:

import Dependencies._

lazy val root = (project in file(".")).
settings(
inThisBuild(List(
organization := "com.example",
scalaVersion := "2.12.4",
version := "0.1.0-SNAPSHOT"
)),
name := "demo",
libraryDependencies += "com.typesafe.play" %% "play-ahc-ws-standalone" % "1.1.3",
libraryDependencies += "com.typesafe.play" %% "play-ws-standalone-json" % "1.1.3",
libraryDependencies += "org.slf4j" % "slf4j-jdk14" % "1.7.9",
libraryDependencies += scalaTest % Test
)

Hello.scala:

package example

import akka.actor.ActorSystem
import akka.stream.ActorMaterializer
import play.api.libs.ws._
import play.api.libs.ws.ahc._

import scala.concurrent.Future

object Hello {
import DefaultBodyReadables._
import scala.concurrent.ExecutionContext.Implicits._

def main(args: Array[String]): Unit = {
// Create Akka system for thread and streaming management
implicit val system = ActorSystem()
system.registerOnTermination {
System.exit(0)
}
implicit val materializer = ActorMaterializer()

// Create the standalone WS client
// no argument defaults to a AhcWSClientConfig created from
// "AhcWSClientConfigFactory.forConfig(ConfigFactory.load, this.getClass.getClassLoader)"
val wsClient = StandaloneAhcWSClient()

call(wsClient)
  .andThen { case _ => wsClient.close() }
  .andThen { case _ => system.terminate() }

}

def call(wsClient: StandaloneWSClient): Future[Unit] = {
wsClient.url("http://www.google.com").get().map { response ⇒
val statusText: String = response.statusText
val body = response.body[String]
println(s"Got a response $statusText")
}
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants