【问题标题】:Proxy Authentication for Google Speech Api CredentialGoogle Speech Api 凭据的代理身份验证
【发布时间】:2018-02-20 00:54:43
【问题描述】:

我正在尝试配置谷歌语音 api 以在公司防火墙内的我的项目中工作。我已将 SpeechSettings 配置如下:

InputStream is = this.getClass().getResourceAsStream("/my-service-account.json");           
CredentialsProvider credentialsProvider = FixedCredentialsProvider.create(ServiceAccountCredentials.fromStream(is));
SpeechSettings.Builder builder = SpeechSettings.newBuilder();
builder.setTransportProvider(SpeechSettings.defaultTransportProvider());
builder.setCredentialsProvider(credentialsProvider);
SpeechSettings settings =  builder.build();
SpeechClient.create(settings);

使用它可以在代理网络之外正确工作并启动语音识别会话。但它无法在经过代理身份验证的网络下转录任何内容,并出现此错误 - UNAVAILABLE: Transport closed for unknown reasonin ApiStreamObserver 类。我认为由于防火墙超时,Grpc 传输正在关闭。

是否可以在创建语音客户端会话时使用代理身份验证凭据进行身份验证?谢谢。

【问题讨论】:

    标签: java authentication proxy google-cloud-endpoints grpc-java


    【解决方案1】:

    环境变量GRPC_PROXY_EXP 已被弃用,虽然它目前仍然有效,但您应该能够使用标准的java 属性https.proxyHosthttps.proxyPort。 直接在当前 JVM 中以编程方式设置它们(不推荐):

    System.setProperty("https.proxyHost", "myproxy.host.local");
    System.setProperty("https.proxyPort", "8080");
    

    或在启动 JVM 时,例如

    java   .... -Dhtts.proxyHost=myproxy.host.local -Dhttps.proxyPort=8080 ...
    

    【讨论】:

      【解决方案2】:

      您能否说明您使用的是什么代理网络?您是否使用 Google Cloud Endpoints (https://cloud.google.com/endpoints)?您的项目是否在 Google Cloud Platform 上运行?如果有,具体是什么平台?应用引擎灵活?应用引擎标准?计算引擎?容器引擎?

      【讨论】:

      • 代理网络是一个带有用户名和密码的http代理。我没有使用端点或在 Google Cloud Platform 上运行项目。我与 api 连接所做的只是使用服务帐户 json 文件。
      • 在做了一些研究之后,我找到了一种从这篇文章中设置代理的方法:github.com/grpc/grpc-java/issues/2983。如果我将环境变量 GRPC_PROXY_EXP 设置为我的代理 url:my.proxy.com:8080,它可以工作!
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-02
      • 2010-12-28
      • 2021-07-03
      • 2020-11-09
      • 2013-04-11
      • 1970-01-01
      相关资源
      最近更新 更多