我正在尝试从运行在需要通过代理服务器访问外部 Web 服务的环境中的 playframework 2 应用程序调用 Web 服务。在我的 application.conf 文件中,我添加了以下属性:
http.proxyPort=8000
http.proxyHost=myproxyhost.innitech.com
在我的 play 应用程序代码中,我可以访问系统属性并验证它们是否已被拾取。然而,在运行时代理配置没有被使用。如果我在不需要使用代理来访问服务的环境中运行应用程序,则服务调用可以正常工作。
是否可以使用 play 框架通过代理调用 Web 服务,如果可以,如何?
下面是一个调用示例:
def watched(username: String, password: String): Promise[Seq[Repo]] = {
val promiseResponse = WS.url(baseUrl + "/user/watched")
.withAuth(username, password, com.ning.http.client.Realm.AuthScheme.BASIC)
.get
promiseResponse.map(_.json.as[Seq[Repo]])
}
以下堆栈跟踪代表我在运行时看到的内容:
play.core.ActionInvoker$$anonfun$receive$1$$anon$1: Execution exception [[Connec
tException: https://api.github.com/user]]
at play.core.ActionInvoker$$anonfun$receive$1.apply(Invoker.scala:82) [p
lay_2.9.1.jar:2.0]
at play.core.ActionInvoker$$anonfun$receive$1.apply(Invoker.scala:63) [p
lay_2.9.1.jar:2.0]
at akka.actor.Actor$class.apply(Actor.scala:290) [akka-actor.jar:2.0]
at play.core.ActionInvoker.apply(Invoker.scala:61) [play_2.9.1.jar:2.0]
at akka.actor.ActorCell.invoke(ActorCell.scala:617) [akka-actor.jar:2.0]
at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:179) [akka-actor.jar:2.0]
Caused by: java.net.ConnectException: https://api.github.com/user
at com.ning.http.client.providers.netty.NettyConnectListener.operationCo
mplete(NettyConnectListener.java:100) ~[async-http-client.jar:na]
at org.jboss.netty.channel.DefaultChannelFuture.notifyListener(DefaultCh
annelFuture.java:397) ~[netty.jar:na]
at org.jboss.netty.channel.DefaultChannelFuture.addListener(DefaultChann
elFuture.java:143) ~[netty.jar:na]
at com.ning.http.client.providers.netty.NettyAsyncHttpProvider.doConnect
(NettyAsyncHttpProvider.java:1004) ~[async-http-client.jar:na]
at com.ning.http.client.providers.netty.NettyAsyncHttpProvider.execute(N
ettyAsyncHttpProvider.java:829) ~[async-http-client.jar:na]
at com.ning.http.client.AsyncHttpClient.executeRequest(AsyncHttpClient.j
ava:499) ~[async-http-client.jar:na]
Caused by: java.nio.channels.UnresolvedAddressException: null
at sun.nio.ch.Net.checkAddress(Net.java:30) ~[na:1.6.0_25]
at sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:480) ~[na
:1.6.0_25]
at org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink.connec
t(NioClientSocketPipelineSink.java:142) ~[netty.jar:na]
at org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink.eventS
unk(NioClientSocketPipelineSink.java:105) ~[netty.jar:na]
at org.jboss.netty.handler.ssl.SslHandler.handleDownstream(SslHandler.ja
va:459) ~[netty.jar:na]
at org.jboss.netty.handler.codec.oneone.OneToOneEncoder.handleDownstream
(OneToOneEncoder.java:55) ~[netty.jar:na]