通过公司代理

时间:2017-01-17 10:59:06

标签: ibm-watson

我正在使用github(https://github.com/watson-developer-cloud/java-sdk)的Watson Java SDK来运行语音到文本服务的测试。我正在我的工作场所运行一个示例,它有一个防火墙和一个http代理设置。

测试失败,因为无法访问远程服务器。堆栈跟踪如下:

Exception in thread "main" java.lang.RuntimeException: java.net.UnknownHostException: stream.watsonplatform.net
    at com.ibm.watson.developer_cloud.service.WatsonService$1.execute(WatsonService.java:182)
    at com.costaisa.app.api.test.ibm.watson.TestIBMWatson.testSpeechToText(TestIBMWatson.java:76)
    at com.costaisa.app.api.test.ibm.watson.TestIBMWatson.main(TestIBMWatson.java:37)
Caused by: java.net.UnknownHostException: stream.watsonplatform.net
    at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
    at java.net.InetAddress$2.lookupAllHostAddr(InetAddress.java:928)
    at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1323)
    at java.net.InetAddress.getAllByName0(InetAddress.java:1276)
    at java.net.InetAddress.getAllByName(InetAddress.java:1192)
    at java.net.InetAddress.getAllByName(InetAddress.java:1126)
    at okhttp3.Dns$1.lookup(Dns.java:39)
    at okhttp3.internal.http.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:173)
    at okhttp3.internal.http.RouteSelector.nextProxy(RouteSelector.java:139)
    at okhttp3.internal.http.RouteSelector.next(RouteSelector.java:81)
    at okhttp3.internal.http.StreamAllocation.findConnection(StreamAllocation.java:172)
    at okhttp3.internal.http.StreamAllocation.findHealthyConnection(StreamAllocation.java:123)
    at okhttp3.internal.http.StreamAllocation.newStream(StreamAllocation.java:93)
    at okhttp3.internal.http.HttpEngine.connect(HttpEngine.java:296)
    at okhttp3.internal.http.HttpEngine.sendRequest(HttpEngine.java:248)
    at okhttp3.RealCall.getResponse(RealCall.java:243)
    at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:201)
    at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:163)
    at okhttp3.RealCall.execute(RealCall.java:57)
    at com.ibm.watson.developer_cloud.service.WatsonService$1.execute(WatsonService.java:179)
    ... 2 more

在我看来,okhttp3支持HTTP代理,但不支持环境变量或系统属性。

我错过了什么吗?是否可以通过代理从Java调用Watson语音到文本服务?

修改

我不再与Watson合作(甚至不是同一份工作!),但很明显我当时的实现无法实现我想做的事情。对这个问题的评论(不是答案)提供了实际的答案:如果不改变实施,你就无法做到。我将此作为答案投票,但唉它只是一个评论。我希望这对其他寻找答案的人有用。

1 个答案:

答案 0 :(得分:0)

Juanjo 这是您通过公司代理传递请求的方法。

创建一个从TextToSpeech扩展的类(作为ExtendedTextToSpeech that I wrote for me.)。 然后更改watson示例附带的DemoServlet,如下所示

             TextToSpeech textService = new com.ibm.cloudoe.samples.ExtendedTextToSpeech();
             textService.setUsernameAndPassword("username", "password");
             String voice = req.getParameter("voice");
             String text = req.getParameter("text");
             String format = "audio/ogg; codecs=opus";
             in = textService.synthesize(text, new Voice(voice, null, null), format);

如果你得到javax.net.ssl.SSLHandshakeException:sun.security.validator.ValidatorException:PKIX路径构建失败:sun.security.provider.certpath.SunCertPathBuilderException:无法找到所请求目标的有效证书路径,那么