logo
down
shadow

Scala Play 2.3 Working with gCloud Storage - any libs to go async?


Scala Play 2.3 Working with gCloud Storage - any libs to go async?

By : user2952616
Date : November 19 2020, 01:01 AM
seems to work fine No, The Google API client is just a simple wrapper around REST calls. If you want async, you will need to code that into your app.
code :


Share : facebook icon twitter icon
type mismatch; found : scala.concurrent.Future[play.api.libs.ws.Response] required: play.api.libs.ws.Response

type mismatch; found : scala.concurrent.Future[play.api.libs.ws.Response] required: play.api.libs.ws.Response


By : S. Scott
Date : March 29 2020, 07:55 AM
I wish this helpful for you The request you are making with post is asynchronous. That call returns immediately, but does not return a Response object. Instead, it returns a Future[Response] object, which will contain the Response object once the http request is completed asynchronously.
If you want to block execution until the request is completed, do:
code :
val f = Ws.url(...).post(...)
Await.result(f)
Play 2 : play.libs.WS VS 3rd party client library for async processing

Play 2 : play.libs.WS VS 3rd party client library for async processing


By : Phan Tom
Date : March 29 2020, 07:55 AM
I wish this helpful for you As Guillaume Bort said on the Play mailing list, play.libs.WS API "has its own thread-pool, managed by the AsyncHttp library itself, but since it uses NIO under the hood, it doesn't matter as it is basically really non-blocking."
So it should be used as often as possible.
Scala/Play/REPL: Configuration error (play.api.libs.Crypto)

Scala/Play/REPL: Configuration error (play.api.libs.Crypto)


By : Kushinho
Date : March 29 2020, 07:55 AM
it helps some times You need a running Play application to encrypt anything with that method, because it needs to get the application secret to use to encrypt the data.
Two solutions:
code :
Crypto.encryptAES("password", "yourapplicationsecret".substring(0, 16))
import play.api.test._
Helpers.running(FakeApplication()) { Crypto.encryptAES("password") }
Scala - Play - How to mock import play.api.libs.concurrent.CustomExecutionContext in Test and use it as an implicit para

Scala - Play - How to mock import play.api.libs.concurrent.CustomExecutionContext in Test and use it as an implicit para


By : xinwei lei
Date : March 29 2020, 07:55 AM
should help you out You can create a sub class of your custom dispatcher and override the necessary methods:
code :
import org.specs2.mutable.Specification

import akka.actor.ActorSystem
import scala.concurrent.ExecutionContext

class MySomethingSpec extends Specification with Mockito {

  "MySomething" should {    

    "mock repository dispatcher itself" in {
      class MyMockedRepositoryDispatcher(executionContext: ExecutionContext) extends RepositoryDispatcherContext(ActorSystem()) {
        override def execute(command: Runnable) = executionContext.execute(command)
        override def reportFailure(cause: Throwable) = executionContext.reportFailure(cause)
      }

      val executionContext: ExecutionContext = ??? // whatever you need
      val repositoryDispatcher: RepositoryDispatcherContext = new MyMockedRepositoryDispatcher(executionContext)

      // do what you need
      // assertions
    }
  }
}
No instance of play.api.libs.json.Format is available for scala.Predef.Map[java.lang.String, scala.Option[scala.Double]]

No instance of play.api.libs.json.Format is available for scala.Predef.Map[java.lang.String, scala.Option[scala.Double]]


By : GanapatiKor
Date : March 29 2020, 07:55 AM
it helps some times Trying to write a json format for an entity which contains a Map of Option. It throws following error , You can define implicits:
code :
  import scala.collection.Map

  object Person {
    implicit object MapReads extends Reads[Map[String, Option[Double]]] {
      def reads(jsValue: JsValue): JsResult[Map[String, Option[Double]]] = jsValue match {
        case JsObject(map) => JsSuccess(
          map.mapValues {
            case JsNumber(d) => Some(d.toDouble)
            case _ => None
          }
        )
        case _ => JsError()
      }
    }

    implicit object MapWrites extends Writes[Map[String, Option[Double]]] {
      def writes(map: Map[String, Option[Double]]): JsValue =
        JsObject(map.mapValues(optd => JsNumber(optd.getOrElse[Double](0.0))))
    }

    implicit val personFormat: OFormat[Person] = Json.format[Person]
  }

  println(Json.toJson(Person(a)))//{"x":{"a":0}}
Related Posts Related Posts :
  • Recommended Scala io library
  • Thread-safely transforming a value in a mutable map
  • Why does chaining match expressions does not compile?
  • Ebean not persisting foreign keys
  • Difference between def m(p: T forSome {type T} and def m1(p:Any), is there any ? Explanation needed based on Scala Langu
  • macro does not find out enclosing vals
  • Spark : how to run spark file from spark shell
  • Flattening a list of lists to a set with exceptions in scala
  • flatMap implementation in Scala
  • Confused about a few lines code in a scala official document page
  • How to input parameters when running bash command with Scala
  • Location header is lost if max-redirects > 1
  • Controller Spec is using FakeApplication, but can't load test configuration
  • Scala code analyzer targets case variable names that are identical to the outer matched varables - "suspicous shado
  • Why does authorize directive execute after the code it's supposed to protect?
  • Scala. Checking if a Type is Comparable
  • Does having a private constructor on a value class negate the benefits of a value class?
  • How to transform submitted json in Play 2.0?
  • Scala warning match may not be exhaustive
  • Pure not a member of objective Promise in PlayFramework
  • How to unmarshal POST params and JSON body in a single route?
  • Spark:How to use join method?
  • is client thread-safe in Twitter Finagle
  • Why is the method accepts only one argument?
  • spray.io strange get/delete/detach directives behavior
  • SBT cannot resolve class declared in src/main/scala in a src/test/scala test class
  • Scala typeclass without function argument
  • Configuring actor behavior using typesafe Config and HOCON
  • Scalatra: Migrating Jersey Filters to Scalatra
  • Compilation error when using Scaldi
  • Scalac hanging in phase typer
  • how to have different source code when cross-compiling Scala with sbt? (changes in MurmurHash)
  • How to set different scalacOptions per Scala version when cross-compiling using Build.scala?
  • Possible Bug in JDBC?
  • Is there a Scala compiler flag to warn when tail recursion is applied without annotation?
  • scala case class put methods in companion object?
  • multiproject sbt doesn't generate file structure
  • Scala "multilevel" abstract class / abstract objects replacement
  • Scala, getting the type parameters of a KList as an HList
  • Why does Play refuse form reporting "Cannot resolve method apply with such signature: Missing arguments"?
  • How to split string with trailing empty strings in result?
  • Scala group by list of list and subtracts grouped values
  • Scala - Creating a function to produce Unary string or integer values
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org