2929 */
3030package com .google .api .gax .httpjson ;
3131
32+ import static com .google .api .gax .httpjson .ResumableUploadHeaders .UPLOAD_COMMAND_HEADER ;
33+ import static com .google .api .gax .httpjson .ResumableUploadHeaders .UPLOAD_SIZE_RECEIVED_HEADER ;
34+
3235import com .google .api .client .http .HttpMethods ;
3336import com .google .api .core .ApiFuture ;
3437import com .google .api .gax .resumable .QueryStatusRequest ;
3538import com .google .api .gax .resumable .QueryStatusResponse ;
39+ import com .google .api .gax .resumable .ResumableUploadSession ;
3640import com .google .api .gax .resumable .ResumableUploadStatus ;
3741import com .google .api .gax .rpc .ApiCallContext ;
38- import com .google .api .gax .rpc .ApiExceptionFactory ;
3942import com .google .api .gax .rpc .ClientContext ;
40- import com .google .api .gax .rpc .StatusCode ;
4143import com .google .api .gax .rpc .UnaryCallable ;
4244import com .google .api .pathtemplate .PathTemplate ;
4345import com .google .common .base .Preconditions ;
6163class ResumableUploadQueryStatusCallable <ResponseT >
6264 extends UnaryCallable <QueryStatusRequest , QueryStatusResponse <ResponseT >> {
6365
64- private static final String UPLOAD_COMMAND_HEADER = "X-Goog-Upload-Command" ;
65- private static final String UPLOAD_STATUS_HEADER = "X-Goog-Upload-Status" ;
66- private static final String UPLOAD_SIZE_RECEIVED_HEADER = "X-Goog-Upload-Size-Received" ;
6766 private static final String COMMAND_QUERY = "query" ;
6867
6968 private static final Map <String , List <String >> QUERY_STATUS_HEADERS =
@@ -152,25 +151,20 @@ private static Long parseSizeReceived(HttpJsonMetadata responseHeaders) {
152151 try {
153152 long parsed = Long .parseLong (sizeReceivedStr );
154153 if (parsed < 0 ) {
155- throw ApiExceptionFactory . createException (
154+ throw new IllegalStateException (
156155 "Response contained negative "
157156 + UPLOAD_SIZE_RECEIVED_HEADER
158157 + " header: "
159- + sizeReceivedStr ,
160- /* cause= */ null ,
161- HttpJsonStatusCode .of (StatusCode .Code .INTERNAL ),
162- /* retryable= */ false );
158+ + sizeReceivedStr );
163159 }
164160 return parsed ;
165161 } catch (NumberFormatException e ) {
166- throw ApiExceptionFactory . createException (
162+ throw new IllegalStateException (
167163 "Response contained invalid "
168164 + UPLOAD_SIZE_RECEIVED_HEADER
169165 + " header: "
170166 + sizeReceivedStr ,
171- e ,
172- HttpJsonStatusCode .of (StatusCode .Code .INTERNAL ),
173- /* retryable= */ false );
167+ e );
174168 }
175169 }
176170 return null ;
@@ -183,6 +177,7 @@ private static class QueryStatusResponseListener<ResponseT>
183177 private final ResumableUploadHttpJsonFuture <QueryStatusResponse <ResponseT >> future ;
184178 private final HttpResponseParser <ResponseT > responseParser ;
185179 private ResumableUploadStatus uploadStatus = ResumableUploadStatus .UNKNOWN ;
180+ private int chunkGranularity = ResumableUploadSession .DEFAULT_CHUNK_GRANULARITY ;
186181 @ Nullable private Long committedOffset = null ;
187182 @ Nullable private Throwable headerParsingException ;
188183 private String responseBody = "" ;
@@ -196,12 +191,10 @@ private QueryStatusResponseListener(
196191
197192 @ Override
198193 public void onHeaders (HttpJsonMetadata responseHeaders ) {
199- Map <String , Object > headers = responseHeaders .getHeaders ();
200- this .uploadStatus =
201- ResumableUploadStatus .fromHeader (
202- HttpHeadersUtils .getSingleHeader (headers , UPLOAD_STATUS_HEADER ));
194+ this .uploadStatus = ResumableUploadHeaders .parseUploadStatus (responseHeaders );
203195 try {
204196 this .committedOffset = parseSizeReceived (responseHeaders );
197+ this .chunkGranularity = ResumableUploadHeaders .parseChunkGranularity (responseHeaders );
205198 } catch (Throwable t ) {
206199 this .headerParsingException = t ;
207200 }
@@ -228,23 +221,23 @@ public void onClose(int statusCode, HttpJsonMetadata trailers) {
228221 future .set (
229222 QueryStatusResponse .<ResponseT >newBuilder ()
230223 .setUploadStatus (uploadStatus )
224+ .setCommittedOffset (committedOffset )
231225 .setResponse (responseParser .parse (stream ))
226+ .setChunkGranularity (chunkGranularity )
232227 .build ());
233228 } else if (committedOffset != null ) {
234229 future .set (
235230 QueryStatusResponse .<ResponseT >newBuilder ()
236231 .setCommittedOffset (committedOffset )
237232 .setUploadStatus (uploadStatus )
233+ .setChunkGranularity (chunkGranularity )
238234 .build ());
239235 } else {
240236 future .setException (
241- ApiExceptionFactory . createException (
237+ new IllegalStateException (
242238 "Query status response did not contain valid "
243239 + UPLOAD_SIZE_RECEIVED_HEADER
244- + " header" ,
245- /* cause= */ null ,
246- HttpJsonStatusCode .of (StatusCode .Code .INTERNAL ),
247- /* retryable= */ false ));
240+ + " header" ));
248241 }
249242 } else {
250243 Throwable cause = trailers .getException ();
0 commit comments