I am trying to write java code to list the dataflow job. I have taken reference from https://cloud.google.com/dataflow/docs/reference/rest/v1b3/projects.jobs/list But the 'GoogleCredential' Class is deprecated. I tried replacing GoogleCredential
to GoogleCredentials
but at this below line
Dataflow dataflowService = new Dataflow.Builder(httpTransport, jsonFactory, credential)
.setApplicationName("Google Cloud Platform Sample")
.build();
it expects HttpRequestInitializer instead of credential.
Can anyone help me how can I use credential itself and fix this issue?
HttpRequestInitializer
is required to perform automatic retry upon failures. A simple HttpRequestInitializer
can be constructed using com.google.api.client.auth.oauth2.Credential
as follows:
private HttpRequestInitializer buildInitializer(Credential credential) {
return httpRequest -> {
// handles abnormal HTTP responses (non 2XX responses)
final HttpUnsuccessfulResponseHandler unsuccessfulResponseHandler =
new HttpBackOffUnsuccessfulResponseHandler(new ExponentialBackOff())
.setSleeper(Sleeper.DEFAULT);
/*
this is designed to work with only one HttpRequest at a time.
Hence, a new instance of HttpBackOffIOExceptionHandler with new instance of
BackOff is created for each instance of HttpRequest
*/
HttpBackOffIOExceptionHandler httpBackOffIOExceptionHandler =
new HttpBackOffIOExceptionHandler(new ExponentialBackOff()).setSleeper(Sleeper.DEFAULT);
httpRequest.setInterceptor(credential).setUnsuccessfulResponseHandler(unsuccessfulResponseHandler)
.setIOExceptionHandler(httpBackOffIOExceptionHandler)
.setConnectTimeout((int) TimeUnit.MINUTES.toMillis(3))
.setReadTimeout((int) TimeUnit.MINUTES.toMillis(3))
.setThrowExceptionOnExecuteError(false).setSuppressUserAgentSuffix(true);
};
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.