use of com.google.api.client.http.HttpTransport in project local-data-aragopedia by aragonopendata.
the class GoogleDriveAPI method authorize.
/**
* Creates an authorized Credential object.
*
* @return an authorized Credential object.
* @throws IOException
* @throws GeneralSecurityException
*/
private static GoogleCredential authorize() throws IOException, GeneralSecurityException {
HttpTransport httpTransport = new NetHttpTransport();
httpTransport = httpTransport.createRequestFactory().getTransport();
HttpRequestInitializer httpRequestInitializer = new HttpRequestInitializer() {
@Override
public void initialize(HttpRequest httpRequest) throws IOException {
httpRequest.setConnectTimeout(300 * 60000);
httpRequest.setReadTimeout(300 * 60000);
}
};
JacksonFactory jsonFactory = new JacksonFactory();
GoogleCredential credential = new GoogleCredential.Builder().setRequestInitializer(httpRequestInitializer).setTransport(httpTransport).setJsonFactory(jsonFactory).setServiceAccountId(Prop.acountId).setServiceAccountScopes(SCOPES).setServiceAccountPrivateKeyFromP12File(new java.io.File(Prop.p12File)).build();
return credential;
}
use of com.google.api.client.http.HttpTransport in project java-docs-samples by GoogleCloudPlatform.
the class CryptFile method createAuthorizedClient.
/**
* Creates an authorized CloudKMS client service using Application Default Credentials.
*
* @return an authorized CloudKMS client
* @throws IOException if there's an error getting the default credentials.
*/
public static CloudKMS createAuthorizedClient() throws IOException {
// Create the credential
HttpTransport transport = new NetHttpTransport();
JsonFactory jsonFactory = new JacksonFactory();
// Authorize the client using Application Default Credentials
// @see https://g.co/dv/identity/protocols/application-default-credentials
GoogleCredential credential = GoogleCredential.getApplicationDefault(transport, jsonFactory);
// Check for this case, and inject the scope if required.
if (credential.createScopedRequired()) {
credential = credential.createScoped(CloudKMSScopes.all());
}
return new CloudKMS.Builder(transport, jsonFactory, credential).setApplicationName("CloudKMS CryptFile").build();
}
use of com.google.api.client.http.HttpTransport in project java-docs-samples by GoogleCloudPlatform.
the class Quickstart method createAuthorizedClient.
/**
* Creates an authorized CloudKMS client service using Application Default Credentials.
*
* @return an authorized CloudKMS client
* @throws IOException if there's an error getting the default credentials.
*/
public static CloudKMS createAuthorizedClient() throws IOException {
// Create the credential
HttpTransport transport = new NetHttpTransport();
JsonFactory jsonFactory = new JacksonFactory();
// Authorize the client using Application Default Credentials
// @see https://g.co/dv/identity/protocols/application-default-credentials
GoogleCredential credential = GoogleCredential.getApplicationDefault(transport, jsonFactory);
// Check for this case, and inject the scope if required.
if (credential.createScopedRequired()) {
credential = credential.createScoped(CloudKMSScopes.all());
}
return new CloudKMS.Builder(transport, jsonFactory, credential).setApplicationName("CloudKMS snippets").build();
}
use of com.google.api.client.http.HttpTransport in project java-docs-samples by GoogleCloudPlatform.
the class CreateTaskServlet method createAuthorizedClient.
/**
* Creates an authorized CloudTasks client service using Application Default Credentials.
*
* @return an authorized CloudTasks client
* @throws IOException if there's an error getting the default credentials.
*/
private static CloudTasks createAuthorizedClient() throws IOException {
// Create the credential
HttpTransport transport = new NetHttpTransport();
JsonFactory jsonFactory = new JacksonFactory();
// Authorize the client using Application Default Credentials
// @see https://g.co/dv/identity/protocols/application-default-credentials
GoogleCredential credential = GoogleCredential.getApplicationDefault(transport, jsonFactory);
// Check for this case, and inject the scope if required.
if (credential.createScopedRequired()) {
credential = credential.createScoped(CloudTasksScopes.all());
}
return new CloudTasks.Builder(transport, jsonFactory, credential).setApplicationName("Cloud Tasks Snippets").build();
}
use of com.google.api.client.http.HttpTransport in project google-cloud-intellij by GoogleCloudPlatform.
the class CloudRepositoryService method list.
@NotNull
public ListReposResponse list(CredentialedUser user, String cloudProject) throws CloudRepositoryServiceException {
try {
Credential credential = user.getCredential();
HttpRequestInitializer initializer = httpRequest -> {
HttpHeaders headers = new HttpHeaders();
httpRequest.setConnectTimeout(LIST_TIMEOUT_MS);
httpRequest.setReadTimeout(LIST_TIMEOUT_MS);
httpRequest.setHeaders(headers);
credential.initialize(httpRequest);
};
HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
String userAgent = ServiceManager.getService(PluginInfoService.class).getUserAgent();
Source source = new Source.Builder(httpTransport, JacksonFactory.getDefaultInstance(), initializer).setRootUrl(CLOUD_SOURCE_API_ROOT_URL).setServicePath("").setApplicationName(userAgent).build();
return new CustomUrlSourceRequest(source, cloudProject).execute();
} catch (IOException | GeneralSecurityException ex) {
throw new CloudRepositoryServiceException();
}
}
Aggregations