本文整理汇总了Java中com.google.api.client.json.jackson2.JacksonFactory.getDefaultInstance方法的典型用法代码示例。如果您正苦于以下问题:Java JacksonFactory.getDefaultInstance方法的具体用法?Java JacksonFactory.getDefaultInstance怎么用?Java JacksonFactory.getDefaultInstance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.api.client.json.jackson2.JacksonFactory
的用法示例。
在下文中一共展示了JacksonFactory.getDefaultInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: GoogleConnector
import com.google.api.client.json.jackson2.JacksonFactory; //导入方法依赖的package包/类
/**
* Instances the google connector configuring all required resources.
*/
private GoogleConnector() throws IOException, GeneralSecurityException {
super();
// 1. JSON library
jsonFactory = JacksonFactory.getDefaultInstance();
// 2. Configure HTTP transport
httpTransport = GoogleNetHttpTransport.newTrustedTransport();
// 3. Load the credentials
secrets = GoogleClientSecrets.load(jsonFactory, new InputStreamReader(GoogleConnector.class.getResourceAsStream("client-secrets.json")));
// 4. Configure the authentication flow
dataStoreFactory = new FileDataStoreFactory(CREDENTIALS_DIRECTORY);
// 5. Create flow
imp_buildAuthorizationFlow();
}
示例2: getProjectsApiStub
import com.google.api.client.json.jackson2.JacksonFactory; //导入方法依赖的package包/类
/**
* Return the Projects api object used for accessing the Cloud Resource Manager Projects API.
* @return Projects api object used for accessing the Cloud Resource Manager Projects API
* @throws GeneralSecurityException Thrown if there's a permissions error.
* @throws IOException Thrown if there's an IO error initializing the API object.
*/
public static synchronized Projects getProjectsApiStub()
throws GeneralSecurityException, IOException {
if (projectApiStub != null) {
return projectApiStub;
}
HttpTransport transport;
GoogleCredential credential;
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
transport = GoogleNetHttpTransport.newTrustedTransport();
credential = GoogleCredential.getApplicationDefault(transport, jsonFactory);
if (credential.createScopedRequired()) {
Collection<String> scopes = CloudResourceManagerScopes.all();
credential = credential.createScoped(scopes);
}
projectApiStub = new CloudResourceManager
.Builder(transport, jsonFactory, credential)
.build()
.projects();
return projectApiStub;
}
示例3: getServiceAccountsApiStub
import com.google.api.client.json.jackson2.JacksonFactory; //导入方法依赖的package包/类
/**
* Get the API stub for accessing the IAM Service Accounts API.
* @return ServiceAccounts api stub for accessing the IAM Service Accounts API.
* @throws IOException Thrown if there's an IO error initializing the api connection.
* @throws GeneralSecurityException Thrown if there's a security error
* initializing the connection.
*/
public static ServiceAccounts getServiceAccountsApiStub() throws IOException, GeneralSecurityException {
if (serviceAccountsApiStub == null) {
HttpTransport transport;
GoogleCredential credential;
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
transport = GoogleNetHttpTransport.newTrustedTransport();
credential = GoogleCredential.getApplicationDefault(transport, jsonFactory);
if (credential.createScopedRequired()) {
Collection<String> scopes = IamScopes.all();
credential = credential.createScoped(scopes);
}
serviceAccountsApiStub = new Iam.Builder(transport, jsonFactory, credential)
.build()
.projects()
.serviceAccounts();
}
return serviceAccountsApiStub;
}
示例4: createAdminApiClient
import com.google.api.client.json.jackson2.JacksonFactory; //导入方法依赖的package包/类
private static SQLAdmin createAdminApiClient(Credential credential) {
HttpTransport httpTransport;
try {
httpTransport = GoogleNetHttpTransport.newTrustedTransport();
} catch (GeneralSecurityException | IOException e) {
throw new RuntimeException("Unable to initialize HTTP transport", e);
}
String rootUrl = System.getProperty(API_ROOT_URL_PROPERTY);
String servicePath = System.getProperty(API_SERVICE_PATH_PROPERTY);
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
SQLAdmin.Builder adminApiBuilder =
new Builder(httpTransport, jsonFactory, credential)
.setApplicationName("Cloud SQL Java Socket Factory");
if (rootUrl != null) {
logTestPropertyWarning(API_ROOT_URL_PROPERTY);
adminApiBuilder.setRootUrl(rootUrl);
}
if (servicePath != null) {
logTestPropertyWarning(API_SERVICE_PATH_PROPERTY);
adminApiBuilder.setServicePath(servicePath);
}
return adminApiBuilder.build();
}
示例5: googleStorage
import com.google.api.client.json.jackson2.JacksonFactory; //导入方法依赖的package包/类
@Bean
public Storage googleStorage() {
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
String applicationName = "Spinnaker/Halyard";
HttpRequestInitializer requestInitializer;
try {
requestInitializer = GoogleCredentials.setHttpTimeout(GoogleCredential.getApplicationDefault());
log.info("Loaded application default credential for reading BOMs & profiles.");
} catch (Exception e) {
requestInitializer = GoogleCredentials.retryRequestInitializer();
log.debug("No application default credential could be loaded for reading BOMs & profiles. Continuing unauthenticated: {}", e.getMessage());
}
return new Storage.Builder(GoogleCredentials.buildHttpTransport(), jsonFactory, requestInitializer)
.setApplicationName(applicationName)
.build();
}
示例6: deleteDevice
import com.google.api.client.json.jackson2.JacksonFactory; //导入方法依赖的package包/类
/** Delete the given device from the registry. */
public static void deleteDevice(String deviceId, String projectId, String cloudRegion,
String registryName)
throws GeneralSecurityException, IOException {
GoogleCredential credential =
GoogleCredential.getApplicationDefault().createScoped(CloudIotScopes.all());
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
HttpRequestInitializer init = new RetryHttpInitializerWrapper(credential);
final CloudIot service = new CloudIot.Builder(
GoogleNetHttpTransport.newTrustedTransport(),jsonFactory, init)
.setApplicationName(APP_NAME).build();
final String devicePath = String.format("projects/%s/locations/%s/registries/%s/devices/%s",
projectId, cloudRegion, registryName, deviceId);
System.out.println("Deleting device " + devicePath);
service.projects().locations().registries().devices().delete(devicePath).execute();
}
示例7: getAuthorizationCodeFlow
import com.google.api.client.json.jackson2.JacksonFactory; //导入方法依赖的package包/类
/**
* Returns a authorization code flow for OAuth requests.
* @param forTokenRequest <code>true</code> for token requests, or
* <code>false</code> for authorization requests
* @return {@link AuthorizationCodeFlow} object
* @throws NullPointerException if this object has no client credentials
*/
protected AuthorizationCodeFlow getAuthorizationCodeFlow(
boolean forTokenRequest) {
if (!isConfiguredForOAuth()) {
throw new NullPointerException("No OAuth client credentials");
}
HttpExecuteInterceptor clientAuthenticator;
if (forTokenRequest) {
clientAuthenticator = getBasicAuthentication();
} else {
clientAuthenticator = getClientParameters();
}
return new AuthorizationCodeFlow(
BearerToken.authorizationHeaderAccessMethod(),
getHttpTransport(), JacksonFactory.getDefaultInstance(),
new GenericUrl(TOKEN_ENDPOINT_URI), clientAuthenticator,
getClientId(), AUTHORIZATION_ENDPOINT_URI);
}
示例8: setUp
import com.google.api.client.json.jackson2.JacksonFactory; //导入方法依赖的package包/类
@Before public void setUp() throws Exception {
// Mock out the vision service for unit tests.
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
HttpTransport transport = new MockHttpTransport() {
@Override
public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
return new MockLowLevelHttpRequest() {
@Override
public LowLevelHttpResponse execute() throws IOException {
MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
response.setStatusCode(200);
response.setContentType(Json.MEDIA_TYPE);
response.setContent("{\"responses\": [{\"textAnnotations\": []}]}");
return response;
}
};
}
};
Vision vision = new Vision(transport, jsonFactory, null);
appUnderTest = new TextApp(vision, null /* index */);
}
示例9: getRegistry
import com.google.api.client.json.jackson2.JacksonFactory; //导入方法依赖的package包/类
/** Retrieves registry metadata from a project. **/
public static DeviceRegistry getRegistry(
String projectId, String cloudRegion, String registryName)
throws GeneralSecurityException, IOException {
GoogleCredential credential =
GoogleCredential.getApplicationDefault().createScoped(CloudIotScopes.all());
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
HttpRequestInitializer init = new RetryHttpInitializerWrapper(credential);
final CloudIot service = new CloudIot.Builder(
GoogleNetHttpTransport.newTrustedTransport(),jsonFactory, init)
.setApplicationName(APP_NAME).build();
final String registryPath = String.format("projects/%s/locations/%s/registries/%s",
projectId, cloudRegion, registryName);
return service.projects().locations().registries().get(registryPath).execute();
}
示例10: createStandardBuilder
import com.google.api.client.json.jackson2.JacksonFactory; //导入方法依赖的package包/类
protected static ShoppingContent.Builder createStandardBuilder(
CommandLine parsedArgs, ContentConfig config) throws IOException {
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
HttpTransport httpTransport = null;
try {
httpTransport = GoogleNetHttpTransport.newTrustedTransport();
} catch (GeneralSecurityException e) {
e.printStackTrace();
System.exit(1);
}
Authenticator authenticator =
new Authenticator(httpTransport, jsonFactory, ShoppingContentScopes.all(), config);
Credential credential = authenticator.authenticate();
return new ShoppingContent.Builder(
httpTransport, jsonFactory, BaseOption.installLogging(credential, parsedArgs))
.setApplicationName("Content API for Shopping Samples");
}
示例11: buildStorageWithCredentials
import com.google.api.client.json.jackson2.JacksonFactory; //导入方法依赖的package包/类
public static Storage buildStorageWithCredentials(Path credentialFilePath) {
try {
HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
Credential credential =
GoogleCredential.fromStream(
Files.newInputStream(credentialFilePath), httpTransport, jsonFactory)
.createScoped(
ImmutableSet.of("https://www.googleapis.com/auth/devstorage.read_write"));
return new Storage.Builder(httpTransport, jsonFactory, credential)
.setApplicationName("Gletscher/1.0")
.build();
} catch (GeneralSecurityException | IOException e) {
throw new IllegalStateException(e);
}
}
示例12: ReportsFeature
import com.google.api.client.json.jackson2.JacksonFactory; //导入方法依赖的package包/类
public ReportsFeature(EventDispatcher<BuildServerListener> dispatcher, @NotNull ReportsDescriptor descriptor, @NotNull ReportsConstants constants) {
this.editParametersUrl = descriptor.getFeaturePath();
this.constants = constants;
this.jsonFactory = JacksonFactory.getDefaultInstance();
try {
this.httpTransport = GoogleNetHttpTransport.newTrustedTransport();
} catch (GeneralSecurityException | IOException e) {
throw new RuntimeException(e);
}
if (dispatcher != null) {
dispatcher.addListener(new BuildServerAdapter() {
@Override
public void buildFinished(SRunningBuild build) {
handleBuildFinished(build);
}
});
}
}
示例13: getCalendarEventCount
import com.google.api.client.json.jackson2.JacksonFactory; //导入方法依赖的package包/类
private Integer getCalendarEventCount() throws GeneralSecurityException, IOException {
NetHttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
TokenResponse tokenResponse = new TokenResponse();
tokenResponse.setRefreshToken(REFRESH_TOKEN);
Credential credential = createCredentialWithRefreshToken(httpTransport, jsonFactory, tokenResponse);
Calendar calendar = new com.google.api.services.calendar.Calendar.Builder(
httpTransport, jsonFactory, credential).setApplicationName(APPLICATION_NAME).build();
Calendar.Events.List events = calendar.events().list(CALENDAR_ID);
return events.execute().getItems().size();
}
示例14: isClusterCollected
import com.google.api.client.json.jackson2.JacksonFactory; //导入方法依赖的package包/类
private boolean isClusterCollected(SpydraArgument arguments)
throws IOException, GeneralSecurityException {
GoogleCredential credential = GoogleCredential.fromStream(
new ByteArrayInputStream(gcpUtils.credentialJsonFromEnv().getBytes()));
if (credential.createScopedRequired()) {
credential =
credential.createScoped(
Collections.singletonList("https://www.googleapis.com/auth/cloud-platform"));
}
HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
Dataproc dataprocService =
new Dataproc.Builder(httpTransport, jsonFactory, credential)
.setApplicationName("Google Cloud Platform Sample")
.build();
Dataproc.Projects.Regions.Clusters.List request =
dataprocService.projects().regions().clusters().list(
arguments.getCluster().getOptions().get(SpydraArgument.OPTION_PROJECT),
arguments.getRegion());
ListClustersResponse response;
do {
response = request.execute();
if (response.getClusters() == null) continue;
String clusterName = arguments.getCluster().getName();
for (Cluster cluster : response.getClusters()) {
if (cluster.getClusterName().equals(clusterName)) {
String status = cluster.getStatus().getState();
LOGGER.info("Cluster state is" + status);
return status.equals("DELETING");
}
}
request.setPageToken(response.getNextPageToken());
} while (response.getNextPageToken() != null);
return true;
}
示例15: createClient
import com.google.api.client.json.jackson2.JacksonFactory; //导入方法依赖的package包/类
@Override
public Storage createClient(String serviceAccount, String application, TimeValue connectTimeout, TimeValue readTimeout)
throws Exception {
try {
GoogleCredential credentials = (DEFAULT.equalsIgnoreCase(serviceAccount)) ? loadDefault() : loadCredentials(serviceAccount);
NetHttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
Storage.Builder storage = new Storage.Builder(httpTransport, JacksonFactory.getDefaultInstance(),
new DefaultHttpRequestInitializer(credentials, connectTimeout, readTimeout));
storage.setApplicationName(application);
logger.debug("initializing client with service account [{}/{}]",
credentials.getServiceAccountId(), credentials.getServiceAccountUser());
return storage.build();
} catch (IOException e) {
throw new ElasticsearchException("Error when loading Google Cloud Storage credentials file", e);
}
}