Scala Twitter欺骗客户端:如何进行外部RESTAPI调用?

Scala Twitter欺骗客户端:如何进行外部RESTAPI调用?,scala,rest,finagle,twitter-finagle,Scala,Rest,Finagle,Twitter Finagle,我试图在我的欺骗代码中发出一个外部(到欺骗服务器)REST GET请求,其URI为: 我正在使用示例中的客户机代码: 我的代码(用Scala编写)如下所示,但它只是挂起,即使我设置了超时限制: val client: Service[HttpRequest, HttpResponse] = ClientBuilder() .codec(Http()) .hosts("http://service.site-dev.com") // If >1 host, client does s

我试图在我的欺骗代码中发出一个外部(到欺骗服务器)REST GET请求,其URI为:

我正在使用示例中的客户机代码:

我的代码(用Scala编写)如下所示,但它只是挂起,即使我设置了超时限制:

val client: Service[HttpRequest, HttpResponse] = ClientBuilder()
  .codec(Http())
  .hosts("http://service.site-dev.com") // If >1 host, client does simple load-balancing
  .hostConnectionLimit(1)
  .tcpConnectTimeout(1.second)
  .requestTimeout(20.seconds)
  .retries(2)
  .build()

val req = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "http://service.site-dev.com/subservices/list")

val f = client(req) // Client, send the request

// Handle the response:
f onSuccess { res =>
  println("got response", res)
} onFailure { exc =>
  println("failed :-(", exc)
}

我怀疑我的主机参数是错的?但是我想在这里放什么呢?这是对外部REST服务的调用?

主机的字符串参数不是URI,而是应该具有格式
“host:port”
(或者对于一组主机,
“host1:port1,host2:port”
),因此将该行更改为
.hosts(“service.site-dev.com:80”)
应该可以解决这个问题


我有点惊讶,你没有看到一个
NumberFormatException
-你使用的是什么版本的欺骗?

你可能想检查一下


这是一个基于骗局的Resteasy客户端执行器替代品。

你应该使用Future.Wait,这样你的主线程就不会死或结束。