mardi 21 avril 2015

WS API in Play framework using Scala is giving java.net.ConnectException error

I am trying to read a remote json file and then parse it by using the WS API in Scala using the play framework. I am getting the following error.

[info] application - Application has just started
[info] application - scheduler-initalDelay in minutes : 13
[info] application - The json file is scala.concurrent.impl.Promise$DefaultPromise@2f2fbc09
[info] application - Application shutdown...
java.net.ConnectException: http://ift.tt/1Gg89aO
    at com.ning.http.client.providers.netty.NettyConnectListener.operationComplete(NettyConnectListener.java:103)
    at org.jboss.netty.channel.DefaultChannelFuture.notifyListener(DefaultChannelFuture.java:427)
    at org.jboss.netty.channel.DefaultChannelFuture.notifyListeners(DefaultChannelFuture.java:418)
    at org.jboss.netty.channel.DefaultChannelFuture.setFailure(DefaultChannelFuture.java:380)
    at org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink$1.operationComplete(NioClientSocketPipelineSink.java:115)
    at org.jboss.netty.channel.DefaultChannelFuture.notifyListener(DefaultChannelFuture.java:427)
    at org.jboss.netty.channel.DefaultChannelFuture.notifyListeners(DefaultChannelFuture.java:413)
    at org.jboss.netty.channel.DefaultChannelFuture.setSuccess(DefaultChannelFuture.java:362)
    at org.jboss.netty.channel.AbstractChannel$ChannelCloseFuture.setClosed(AbstractChannel.java:355)
    at org.jboss.netty.channel.AbstractChannel.setClosed(AbstractChannel.java:185)
    at org.jboss.netty.channel.socket.nio.AbstractNioChannel.setClosed(AbstractNioChannel.java:197)
    at org.jboss.netty.channel.socket.nio.NioSocketChannel.setClosed(NioSocketChannel.java:84)
    at org.jboss.netty.channel.socket.nio.AbstractNioWorker.close(AbstractNioWorker.java:357)
    at org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink.eventSunk(NioClientSocketPipelineSink.java:58)
.
.
.
.
.
.
    at sbt.RunnerWrapper$1.runRunner(FrameworkWrapper.java:200)
    at sbt.RunnerWrapper$1.execute(FrameworkWrapper.java:236)
    at sbt.ForkMain$Run.runTest(ForkMain.java:239)
    at sbt.ForkMain$Run.runTestSafe(ForkMain.java:211)
    at sbt.ForkMain$Run.runTests(ForkMain.java:187)
    at sbt.ForkMain$Run.run(ForkMain.java:251)
    at sbt.ForkMain.main(ForkMain.java:97)
Caused by: java.nio.channels.ClosedChannelException
    ... 98 more

Below is the code snippet that is throwing the error.

case class Payout(payout: Double)
implicit val readPayout: Reads[Payout] = (__ \ "data" \ "data" \ "Stat" \ "payout").read[Double].map { Payout(_)}
  def PayoutChange() = {

    val apiUrl: String = "http://ift.tt/1Gg89aO"

    Logger.info("Requesting the payout")
    val temp = WS.url(apiUrl).withRequestTimeout(1000)
    val result: Future[JsValue] = temp.get().map {
      response =>
        (response.json).as[JsValue]
    }
    Logger.info("The json file is " + result)
    result.onComplete {
      result =>
        val jsonurl = result.get
        val payout = jsonurl.\("payout")
       Logger.debug("payout "+payout)
    }

  }

I am able to access the "apiUrl" when I put the url in browser. The url has some identification keys, but the keys are hardcoded within the URL. If I am able to access the url through browser, what might be preventing it from getting accessed from the code?

Aucun commentaire:

Enregistrer un commentaire