diff --git a/cloud-language-starter/src/main/java/com/sample/autoconfig/LanguageAutoConfig.java b/cloud-language-starter/src/main/java/com/sample/autoconfig/LanguageAutoConfig.java index 474cc9f..46aaa2d 100644 --- a/cloud-language-starter/src/main/java/com/sample/autoconfig/LanguageAutoConfig.java +++ b/cloud-language-starter/src/main/java/com/sample/autoconfig/LanguageAutoConfig.java @@ -91,6 +91,9 @@ public CredentialsProvider languageServiceCredentials() throws IOException { // @Bean @ConditionalOnMissingBean(name = "defaultLanguageTransportChannelProvider") public TransportChannelProvider defaultLanguageTransportChannelProvider() { + if (clientProperties.isUseRest()) { + return LanguageServiceSettings.defaultHttpJsonTransportProviderBuilder().build(); + } return LanguageServiceSettings.defaultTransportChannelProvider(); } @@ -100,8 +103,16 @@ public LanguageServiceClient languageServiceClient(@Qualifier("languageServiceCr @Qualifier("defaultLanguageTransportChannelProvider") TransportChannelProvider defaultTransportChannelProvider) throws IOException { - LanguageServiceSettings.Builder clientSettingsBuilder = - LanguageServiceSettings.newBuilder() + LanguageServiceSettings.Builder clientSettingsBuilder; + + if (clientProperties.isUseRest()) { + // To use REST (HTTP1.1/JSON) transport (instead of gRPC) + clientSettingsBuilder = LanguageServiceSettings.newHttpJsonBuilder(); + } else { + clientSettingsBuilder = LanguageServiceSettings.newBuilder(); + } + + clientSettingsBuilder .setCredentialsProvider(credentialsProvider) // default transport channel provider, allow user to override bean for example to configure a proxy // https://github.com/googleapis/google-cloud-java#configuring-a-proxy @@ -132,13 +143,6 @@ public LanguageServiceClient languageServiceClient(@Qualifier("languageServiceCr .setBackgroundExecutorProvider(executorProvider); } - // To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending and receiving requests over - // can set a property to enable this if specified, but seems too niche usecase? - if (clientProperties.isUseRest()) { - clientSettingsBuilder.setTransportChannelProvider( - LanguageServiceSettings.defaultHttpJsonTransportProviderBuilder().build()); - } - // Retry Settings: set for each method. // Useful settings for users. should expose settings for each method. // If property not set, set to default -- need to access from gapic-context for each method.