通过公司代理从 Java 调用 Watson 语音转文本
Invoking Watson speech-to-text from Java through a corporate proxy
我正在使用 Watson Java SDK 从 github (https://github.com/watson-developer-cloud/java-sdk) 到 运行 语音到文本服务的测试。我运行举了我工作场所的一个例子,它设置了防火墙和 HTTP 代理。
由于无法访问远程服务器,测试失败。堆栈跟踪如下:
Exception in thread "main" java.lang.RuntimeException: java.net.UnknownHostException: stream.watsonplatform.net
at com.ibm.watson.developer_cloud.service.WatsonService.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.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.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.execute(WatsonService.java:179)
... 2 more
在我看来,okhttp3 支持 HTTP 代理,但不支持通过环境变量或系统属性。
我错过了什么吗?是否可以通过代理从 Java 调用 Watson 语音转文本服务?
编辑
我不再与 Watson 合作(甚至不是同一份工作!),但很明显,我想做的事情在当时的当前实施中是不可能的。对该问题的评论(不是答案)提供了实际答案:如果不更改实现,就无法做到这一点。我会投票作为答案,但可惜这只是评论。我希望这对其他寻求答案的人有用。
Juanjo 这是您可以通过公司代理传递请求的方法。
创建一个从 TextToSpeech 扩展的 class(如 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:无法找到请求目标的有效证书路径,然后
- 登录 stream.watsonplatform。net/text-to-speech/api/v1 使用从您的 watson 帐户的 text-to-speech 服务收到的 username/password
- 单击浏览器地址栏中的锁形标志并导出证书。
- 按照此处的步骤操作http://magicmonster.com/kb/prg/java/ssl/pkix_path_building_failed.html
我正在使用 Watson Java SDK 从 github (https://github.com/watson-developer-cloud/java-sdk) 到 运行 语音到文本服务的测试。我运行举了我工作场所的一个例子,它设置了防火墙和 HTTP 代理。
由于无法访问远程服务器,测试失败。堆栈跟踪如下:
Exception in thread "main" java.lang.RuntimeException: java.net.UnknownHostException: stream.watsonplatform.net
at com.ibm.watson.developer_cloud.service.WatsonService.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.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.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.execute(WatsonService.java:179)
... 2 more
在我看来,okhttp3 支持 HTTP 代理,但不支持通过环境变量或系统属性。
我错过了什么吗?是否可以通过代理从 Java 调用 Watson 语音转文本服务?
编辑
我不再与 Watson 合作(甚至不是同一份工作!),但很明显,我想做的事情在当时的当前实施中是不可能的。对该问题的评论(不是答案)提供了实际答案:如果不更改实现,就无法做到这一点。我会投票作为答案,但可惜这只是评论。我希望这对其他寻求答案的人有用。
Juanjo 这是您可以通过公司代理传递请求的方法。
创建一个从 TextToSpeech 扩展的 class(如 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:无法找到请求目标的有效证书路径,然后
- 登录 stream.watsonplatform。net/text-to-speech/api/v1 使用从您的 watson 帐户的 text-to-speech 服务收到的 username/password
- 单击浏览器地址栏中的锁形标志并导出证书。
- 按照此处的步骤操作http://magicmonster.com/kb/prg/java/ssl/pkix_path_building_failed.html