spray

Get Json Object using spray.json

∥☆過路亽.° 提交于 2019-12-07 12:59:31
问题 I'm using spray and I need to return a json object through a method. val route = path("all-modules") { get { respondWithMediaType(`text/html`) { complete( configViewer.findAllModules.toString) } } } This prints ConfigResults(S1000,Success,List(testDataTypes, mandate, sdp)) But I need get this as the json object. how can I do it? I tried in this way val route = path("all-modules") { get { respondWithMediaType(`application/json`) { complete{ configViewer.findAllModules } } } } It gives an

required: spray.httpx.marshalling.ToResponseMarshallable Error

五迷三道 提交于 2019-12-07 10:53:27
Hey im pretty new to Spray and reactive mongo . Im trying to return a list of result as json but i'm having some issue with converting the result to list of json. this is my model import reactivemongo.bson.BSONDocumentReader import reactivemongo.bson.BSONObjectID import reactivemongo.bson.Macros case class Post(id: BSONObjectID, likes: Long, message: String, object_id: String, shares: Long) object Post { implicit val reader: BSONDocumentReader[Post] = Macros.reader[Post] } the Mongo method def getAll(): Future[List[Post]] ={ val query = BSONDocument( "likes" -> BSONDocument( "$gt" -> 27))

Spray-can NoClassDefFoundError

久未见 提交于 2019-12-07 07:44:30
问题 I'm new to spray, i can't get it to work... :/ My build.sbt: val apacheDeps = Seq( "commons-validator" % "commons-validator" % "1.4.1" ) val sprayAndAkkaDeps = { val sprayV = "1.3.3" Seq( "io.spray" %% "spray-can" % sprayV, "io.spray" %% "spray-routing" % sprayV, "io.spray" %% "spray-testkit" % sprayV % "test", "com.typesafe.akka" %% "akka-actor" % "2.3.9" ) } name := "myApp" version := "1.0.0" scalaVersion := "2.11.6" libraryDependencies ++= Seq( "org.mongodb" %% "casbah" % "2.8.1", "ch.qos

How to match specific accept headers in a route?

[亡魂溺海] 提交于 2019-12-07 07:28:51
问题 I want to create a route that matches only if the client sends a specific Accept header. I use Spray 1.2-20130822 . I'd like to get the route working: def receive = runRoute { get { path("") { accept("application/json") { complete(...) } } } } Here I found a spec using an accept() function, but I can't figure out what to import in my Spray-Handler to make it work as directive. Also, I did not find other doc on header directives but these stubs. 回答1: I would do this way: def acceptOnly(mr:

Unsupported ciphersuite TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256

强颜欢笑 提交于 2019-12-06 22:39:30
I recently received a certificate from Commodo and I'm trying to integrate it with my Scala Spray Server. I have an trait to configure my Spray sever: import java.io.{BufferedInputStream, FileInputStream} import java.security.{SecureRandom, KeyStore} import java.security.cert.{X509Certificate, CertificateFactory} import javax.net.ssl.{TrustManagerFactory, KeyManagerFactory, SSLContext} import spray.io._ import org.apache.camel.util.jsse._ // for SSL support (if enabled in application.conf) trait MySSLConfig { // if there is no SSLContext in scope implicitly the HttpServer uses the default

Unsupported ciphersuite TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256

半城伤御伤魂 提交于 2019-12-06 22:38:40
I recently received a certificate from Commodo and I'm trying to integrate it with my Scala Spray Server. I have an trait to configure my Spray sever: import java.io.{BufferedInputStream, FileInputStream} import java.security.{SecureRandom, KeyStore} import java.security.cert.{X509Certificate, CertificateFactory} import javax.net.ssl.{TrustManagerFactory, KeyManagerFactory, SSLContext} import spray.io._ import org.apache.camel.util.jsse._ // for SSL support (if enabled in application.conf) trait MySSLConfig { // if there is no SSLContext in scope implicitly the HttpServer uses the default

Sending post with json using spray?

北战南征 提交于 2019-12-06 08:38:17
问题 Sorry I can't manage to make this work: I need to add some json to a post, so following the documentation: http://spray.io/documentation/1.1-M8/spray-httpx/request-building/ : import scala.util.{Success, Failure} import akka.actor.{Props, ActorSystem} import spray.can.client.DefaultHttpClient import spray.client.HttpConduit import spray.httpx.SprayJsonSupport import spray.http._ import spray.json.JsonParser._ import spray.json._ import HttpMethods._ import HttpHeaders._ import MediaTypes._

Can't convert unicode symbols to cyrillic

拜拜、爱过 提交于 2019-12-06 05:19:46
问题 I have a bunch of documents persisted in Apache Lucene with some names in russian, and when I'm trying to print them out it looks like this "\u0410\u0441\u043f\u0430\u0440" , but not in cyrillic symbols. The project is in Scala. I've tried to fix this with Apache Commons unescapeJava method, but it didn't help. Are there any other options? Updated: Project is writen with Spray framework and returns json like this. { "id" : 0, "name" : "\u0410\u0441\u043f\u0430\u0440" } 回答1: I'm going to try

Sending a post request in spray

痴心易碎 提交于 2019-12-05 20:59:27
问题 I need to make a simple HTTP request using spray framework. I found some examples on their web site but they turned out to be complicated and involving Akka which is not necessary for me. Besides, I need to be able to fill in a request's headers (like X-Application , content-type , etc) and, of course, a requests's post data (in my case, it would be a data in JSON). So how do I do that? 回答1: Here is an example. There is going to be a small amount of akka code but as I mentioned in my comment,

spray Marshaller for futures not in implicit scope after upgrading to spray 1.2

家住魔仙堡 提交于 2019-12-05 19:17:50
问题 After updating to spray 1.2 I got a problem regarding my JSON-Marshallers that worked perfectly with 1.1. Doing the following inside a HttpService trait TestHttpService extends HttpService with SprayJsonSupport with DefaultJsonProtocol{ self : ActorLogging => case class Test(hallo: String, test: String) implicit val storyJsonFormat = jsonFormat2(Test.apply) def test(implicit m : Marshaller[Future[Test]]) = 17 def hallo = test } leads to the following error: could not find implicit value for