|
25 | 25 | import com.google.api.gax.httpjson.GaxHttpJsonProperties; |
26 | 26 | import com.google.api.gax.httpjson.HttpJsonCallSettings; |
27 | 27 | import com.google.api.gax.httpjson.HttpJsonCallableFactory; |
28 | | -import com.google.api.gax.httpjson.HttpJsonTransportChannel; |
29 | 28 | import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider; |
30 | 29 | import com.google.api.gax.httpjson.ProtoMessageRequestFormatter; |
31 | 30 | import com.google.api.gax.httpjson.ProtoMessageResponseParser; |
32 | 31 | import com.google.api.gax.httpjson.ProtoRestSerializer; |
33 | 32 | import com.google.api.gax.rpc.ApiClientHeaderProvider; |
34 | 33 | import com.google.api.gax.rpc.ClientContext; |
35 | 34 | import com.google.api.gax.rpc.ResumableUploadCallable; |
| 35 | +import com.google.api.gax.rpc.ResumableUploadTransportBridge; |
36 | 36 | import com.google.protobuf.TypeRegistry; |
37 | 37 | import com.google.showcase.v1beta1.UploadMediaRequest; |
38 | 38 | import com.google.showcase.v1beta1.UploadMediaResponse; |
39 | 39 | import java.io.IOException; |
| 40 | +import java.util.Collections; |
40 | 41 | import java.util.HashMap; |
41 | 42 | import java.util.List; |
42 | 43 | import java.util.Map; |
@@ -97,48 +98,42 @@ class HttpJsonResumableUploadServiceResumableUploadStub implements BackgroundRes |
97 | 98 | uploadMediaCallable; |
98 | 99 |
|
99 | 100 | public static HttpJsonResumableUploadServiceResumableUploadStub create( |
100 | | - ResumableUploadServiceStubSettings settings) throws IOException { |
101 | | - if (settings |
102 | | - .getTransportChannelProvider() |
103 | | - .getTransportName() |
104 | | - .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) { |
| 101 | + ResumableUploadServiceStubSettings settings) { |
| 102 | + ClientContext clientContext; |
| 103 | + try { |
| 104 | + clientContext = |
| 105 | + ResumableUploadTransportBridge.createUploadClientContext( |
| 106 | + settings, |
| 107 | + InstantiatingHttpJsonChannelProvider.newBuilder().build(), |
| 108 | + ApiClientHeaderProvider.newBuilder() |
| 109 | + .setGeneratedLibToken( |
| 110 | + "gapic", |
| 111 | + GaxProperties.getLibraryVersion(ResumableUploadServiceStubSettings.class)) |
| 112 | + .setTransportToken( |
| 113 | + GaxHttpJsonProperties.getHttpJsonTokenName(), |
| 114 | + GaxHttpJsonProperties.getHttpJsonVersion()) |
| 115 | + .build()); |
| 116 | + } catch (IOException e) { |
105 | 117 | return new HttpJsonResumableUploadServiceResumableUploadStub( |
106 | | - ClientContext.create(settings), settings); |
| 118 | + ResumableUploadTransportBridge.failingCallable(e), |
| 119 | + new BackgroundResourceAggregation(Collections.emptyList())); |
107 | 120 | } |
108 | | - return new HttpJsonResumableUploadServiceResumableUploadStub( |
109 | | - deriveHttpJsonClientContext(settings), settings); |
110 | | - } |
111 | | - |
112 | | - private static ClientContext deriveHttpJsonClientContext( |
113 | | - ResumableUploadServiceStubSettings settings) throws IOException { |
114 | | - return ClientContext.create( |
115 | | - settings.toBuilder() |
116 | | - .setHttpJsonInternalHeaderProvider( |
117 | | - ApiClientHeaderProvider.newBuilder() |
118 | | - .setGeneratedLibToken( |
119 | | - "gapic", |
120 | | - GaxProperties.getLibraryVersion(ResumableUploadServiceStubSettings.class)) |
121 | | - .setTransportToken( |
122 | | - GaxHttpJsonProperties.getHttpJsonTokenName(), |
123 | | - GaxHttpJsonProperties.getHttpJsonVersion()) |
124 | | - .build()) |
125 | | - .setTransportChannelProvider(InstantiatingHttpJsonChannelProvider.newBuilder().build()) |
126 | | - .build()); |
127 | | - } |
128 | | - |
129 | | - private HttpJsonResumableUploadServiceResumableUploadStub( |
130 | | - ClientContext clientContext, ResumableUploadServiceStubSettings settings) { |
131 | 121 | HttpJsonCallSettings<UploadMediaRequest, UploadMediaResponse> uploadMediaTransportSettings = |
132 | 122 | HttpJsonCallSettings.<UploadMediaRequest, UploadMediaResponse>newBuilder() |
133 | 123 | .setMethodDescriptor(uploadMediaMethodDescriptor) |
134 | 124 | .setTypeRegistry(typeRegistry) |
135 | 125 | .build(); |
136 | | - this.uploadMediaCallable = |
| 126 | + return new HttpJsonResumableUploadServiceResumableUploadStub( |
137 | 127 | HttpJsonCallableFactory.createResumableUploadCallable( |
138 | | - uploadMediaTransportSettings, settings.uploadMediaSettings(), clientContext); |
| 128 | + uploadMediaTransportSettings, settings.uploadMediaSettings(), clientContext), |
| 129 | + new BackgroundResourceAggregation(clientContext.getBackgroundResources())); |
| 130 | + } |
139 | 131 |
|
140 | | - this.backgroundResources = |
141 | | - new BackgroundResourceAggregation(clientContext.getBackgroundResources()); |
| 132 | + private HttpJsonResumableUploadServiceResumableUploadStub( |
| 133 | + ResumableUploadCallable<UploadMediaRequest, UploadMediaResponse> uploadMediaCallable, |
| 134 | + BackgroundResource backgroundResources) { |
| 135 | + this.uploadMediaCallable = uploadMediaCallable; |
| 136 | + this.backgroundResources = backgroundResources; |
142 | 137 | } |
143 | 138 |
|
144 | 139 | public ResumableUploadCallable<UploadMediaRequest, UploadMediaResponse> uploadMediaCallable() { |
|
0 commit comments