2017-06-22 87 views
0

這裏是我試圖創建通過噴霧HTTP 包org.exadatum.xstream.service.http噴霧HTTP POST請求

import akka.actor.ActorSystem 
import akka.util.Timeout 
import spray.http._ 
import spray.httpx.SprayJsonSupport 
import spray.client.pipelining._ 
import spray.json._ 

import scala.concurrent.duration._ 
import scala.concurrent.{ExecutionContext, Future} 

object Update extends App with SprayJsonSupport with AdditionalFormats{ 
    implicit val system: ActorSystem = ActorSystem("UpdateJob") 
    implicit val executor: ExecutionContext = system.dispatcher 
    implicit val timeout: Timeout = Timeout(1.seconds) 

    val pipe: HttpRequest => Future[HttpResponse] = sendReceive 

    val json = """{ 
       | "jobName" : "land", 
       | "appId" : "application_12323121211223", 
       | "status" : "started", 
       | "runningSince" : 1498144649660 
       |}""".parseJson.asJsObject() 

    pipe(Post("http://localhost:3000/job/v1/updateJobDetails/land",json)) 
} 

我休息服務正在運行localhost:3000 POST請求的代碼。這樣做的結果錯誤

Exception in thread "main" java.lang.NoSuchMethodError: scala.collection.immutable.HashSet$.empty()Lscala/collection/immutable/HashSet; 
at akka.actor.ActorCell$.<init>(ActorCell.scala:336) 
at akka.actor.ActorCell$.<clinit>(ActorCell.scala) 
at akka.actor.RootActorPath.$div(ActorPath.scala:159) 
at akka.actor.LocalActorRefProvider.<init>(ActorRefProvider.scala:464) 
at akka.actor.LocalActorRefProvider.<init>(ActorRefProvider.scala:452) 
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) 
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) 
at java.lang.reflect.Constructor.newInstance(Constructor.java:423) 
at akka.actor.ReflectiveDynamicAccess$$anonfun$createInstanceFor$2.apply(DynamicAccess.scala:78) 
at scala.util.Try$.apply(Try.scala:192) 
at akka.actor.ReflectiveDynamicAccess.createInstanceFor(DynamicAccess.scala:73) 
at akka.actor.ReflectiveDynamicAccess$$anonfun$createInstanceFor$3.apply(DynamicAccess.scala:84) 
at akka.actor.ReflectiveDynamicAccess$$anonfun$createInstanceFor$3.apply(DynamicAccess.scala:84) 
at scala.util.Success.flatMap(Try.scala:231) 
at akka.actor.ReflectiveDynamicAccess.createInstanceFor(DynamicAccess.scala:84) 
at akka.actor.ActorSystemImpl.liftedTree1$1(ActorSystem.scala:584) 
at akka.actor.ActorSystemImpl.<init>(ActorSystem.scala:577) 
at akka.actor.ActorSystem$.apply(ActorSystem.scala:141) 
at akka.actor.ActorSystem$.apply(ActorSystem.scala:108) 
at org.exadatum.xstream.service.http.Update$.delayedEndpoint$org$exadatum$xstream$service$http$Update$1(UpdateJob.scala:14) 
at org.exadatum.xstream.service.http.Update$delayedInit$body.apply(UpdateJob.scala:13) 
at scala.Function0$class.apply$mcV$sp(Function0.scala:34) 
at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12) 
at scala.App$$anonfun$main$1.apply(App.scala:76) 
at scala.App$$anonfun$main$1.apply(App.scala:76) 
at scala.collection.immutable.List.foreach(List.scala:381) 
at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:35) 
at scala.App$class.main(App.scala:76) 
at com.job.service.http.Update$.main(UpdateJob.scala:13) 
at com.job.service.http.Update.main(UpdateJob.scala) 

我試着在帖子中提到的解決方案Sending post with json using spray?

回答

0

很可能是一個Scala庫不匹配(根據你的特定錯誤引用hashmap)。嘗試使用scala-library-2.10.jar(from here:(run-main-0) java.lang.NoSuchMethodError

此外,也許您需要正確導入SprayJsonSupport? :

import spray.httpx.SprayJsonSupport._ 

注後._