本文整理了Java中com.google.api.client.json.jackson2.JacksonFactory
类的一些代码示例,展示了JacksonFactory
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JacksonFactory
类的具体详情如下:
包路径:com.google.api.client.json.jackson2.JacksonFactory
类名称:JacksonFactory
[英]Low-level JSON library implementation based on Jackson 2.
Implementation is thread-safe, and sub-classes must be thread-safe. For maximum efficiency, applications should use a single globally-shared instance of the JSON factory.
[中]基于Jackson 2的低级JSON库实现。
实现是线程安全的,子类必须是线程安全的。为了获得最大效率,应用程序应该使用JSON工厂的单个全局共享实例。
代码示例来源:origin: stackoverflow.com
new YouTube.Builder(new NetHttpTransport(), new JacksonFactory(), new HttpRequestInitializer()
代码示例来源:origin: apache/incubator-druid
@Provides
@LazySingleton
public GoogleStorage getGoogleStorage(final GoogleAccountConfig config)
throws IOException, GeneralSecurityException
{
LOG.info("Building Cloud Storage Client...");
HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
GoogleCredential credential = GoogleCredential.getApplicationDefault(httpTransport, jsonFactory);
if (credential.createScopedRequired()) {
credential = credential.createScoped(StorageScopes.all());
}
Storage storage = new Storage.Builder(httpTransport, jsonFactory, credential).setApplicationName(APPLICATION_NAME).build();
return new GoogleStorage(storage);
}
}
代码示例来源:origin: googleapis/google-cloud-java
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
rule = new JacksonFactory().fromString(in.readUTF(), Rule.class);
}
代码示例来源:origin: googleapis/google-cloud-java
new JacksonFactory()
.createJsonParser(new FileInputStream(args[0]))
.parseAndClose(String[].class);
代码示例来源:origin: GoogleCloudPlatform/java-docs-samples
/**
* Connects to the Vision API using Application Default Credentials.
*/
public static Vision getVisionService() throws IOException, GeneralSecurityException {
GoogleCredential credential =
GoogleCredential.getApplicationDefault().createScoped(VisionScopes.all());
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
return new Vision.Builder(GoogleNetHttpTransport.newTrustedTransport(), jsonFactory, credential)
.setApplicationName(APPLICATION_NAME)
.build();
}
代码示例来源:origin: stackoverflow.com
GoogleCredential credential = new GoogleCredential().setAccessToken(accessToken);
Oauth2 oauth2 = new Oauth2.Builder(new NetHttpTransport(), new JacksonFactory(), credential).setApplicationName(
"Oauth2").build();
Userinfoplus userinfo = oauth2.userinfo().get().execute();
userinfo.toPrettyString();
代码示例来源:origin: cdapio/cdap
/**
* Creates an authorized CloudKMS client service.
*
* @return an authorized CloudKMS client
* @throws IOException if credentials can not be created in current environment
*/
private CloudKMS createCloudKMS(String serviceAccountFile) throws IOException {
HttpTransport transport = new NetHttpTransport();
JsonFactory jsonFactory = new JacksonFactory();
GoogleCredential credential;
if (serviceAccountFile == null) {
credential = GoogleCredential.getApplicationDefault(transport, jsonFactory);
} else {
File credentialsPath = new File(serviceAccountFile);
try (FileInputStream serviceAccountStream = new FileInputStream(credentialsPath)) {
credential = GoogleCredential.fromStream(serviceAccountStream, transport, jsonFactory);
}
}
if (credential.createScopedRequired()) {
credential = credential.createScoped(CloudKMSScopes.all());
}
return new CloudKMS.Builder(transport, jsonFactory, credential)
.setApplicationName(CLOUD_KMS)
.build();
}
代码示例来源:origin: stackoverflow.com
HttpTransport httpTransport = new NetHttpTransport();
JsonFactory jsonFactory = new JacksonFactory();
GoogleCredential credential = new GoogleCredential.Builder()
.setTransport(httpTransport)
.setJsonFactory(jsonFactory)
.setClientSecrets("client_id", "client_secret").build();
credential.setAccessToken("access_token");
代码示例来源:origin: com.google.endpoints/endpoints-management-config
/**
* Create a {@link ServiceConfigSupplier} instance.
*
* @return a {@code ServiceConfigSuppler}
*/
public static ServiceConfigSupplier create() {
NetHttpTransport httpTransport = new NetHttpTransport();
JacksonFactory jsonFactory = new JacksonFactory();
GoogleCredential credential;
try {
credential = GoogleCredential.getApplicationDefault(httpTransport, jsonFactory)
.createScoped(SCOPES);
} catch (IOException e) {
throw new IllegalStateException("could not get credentials for fetching service config!");
}
return new ServiceConfigSupplier(
new SystemEnvironment(), httpTransport, jsonFactory, credential);
}
代码示例来源:origin: google/data-transfer-project
MediaItemSearchResponse listMediaItems(Optional<String> albumId, Optional<String> pageToken)
throws IOException {
Map<String, Object> params = new LinkedHashMap<>();
params.put(PAGE_SIZE_KEY, String.valueOf(MEDIA_PAGE_SIZE));
if (albumId.isPresent()) {
params.put(ALBUM_ID_KEY, albumId.get());
} else {
params.put(FILTERS_KEY, ImmutableMap.of(INCLUDE_ARCHIVED_KEY, String.valueOf(true)));
}
if (pageToken.isPresent()) {
params.put(TOKEN_KEY, pageToken.get());
}
HttpContent content = new JsonHttpContent(new JacksonFactory(), params);
return makePostRequest(BASE_URL + "mediaItems:search", Optional.empty(), content,
MediaItemSearchResponse.class);
}
代码示例来源:origin: simpleci/simpleci
private Storage createClient() throws IOException, GeneralSecurityException {
GoogleCredential credential = GoogleCredential.fromStream(
new ByteArrayInputStream(settings.serviceAccount.getBytes(StandardCharsets.UTF_8)))
.createScoped(Collections.singleton(StorageScopes.CLOUD_PLATFORM));
NetHttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
return new Storage.Builder(
httpTransport, JSON_FACTORY, null).setApplicationName(APPLICATION_NAME)
.setHttpRequestInitializer(credential).build();
}
}
代码示例来源:origin: com.google.crypto.tink/tink
/** Loads the provided credential. */
private KmsClient withCredentials(GoogleCredential credential) {
if (credential.createScopedRequired()) {
credential = credential.createScoped(CloudKMSScopes.all());
}
this.client =
new CloudKMS.Builder(new NetHttpTransport(), new JacksonFactory(), credential)
.setApplicationName(APPLICATION_NAME)
.build();
return this;
}
代码示例来源:origin: GoogleCloudPlatform/java-docs-samples
private static Storage buildService() throws IOException, GeneralSecurityException {
HttpTransport transport = GoogleNetHttpTransport.newTrustedTransport();
JsonFactory jsonFactory = new JacksonFactory();
GoogleCredential credential = GoogleCredential.getApplicationDefault(transport, jsonFactory);
// Depending on the environment that provides the default credentials (for
// example: Compute Engine, App Engine), the credentials may require us to
// specify the scopes we need explicitly. Check for this case, and inject
// the Cloud Storage scope if required.
if (credential.createScopedRequired()) {
Collection<String> scopes = StorageScopes.all();
credential = credential.createScoped(scopes);
}
return new Storage.Builder(transport, jsonFactory, credential)
.setApplicationName("GCS Samples")
.build();
}
}
代码示例来源:origin: pentaho/pentaho-kettle
public static GoogleAnalyticsApiFacade createFor(
String application, String oauthServiceAccount, String oauthKeyFile )
throws GeneralSecurityException, IOException, KettleFileException {
return new GoogleAnalyticsApiFacade(
GoogleNetHttpTransport.newTrustedTransport(),
JacksonFactory.getDefaultInstance(),
application,
oauthServiceAccount,
new File( KettleVFS.getFileObject( oauthKeyFile ).getURL().getPath() )
);
}
代码示例来源:origin: siom79/jdrivesync
public Optional<Credential> load() {
Properties properties = new Properties();
try {
File file = getAuthenticationFile(options);
if(!file.exists() || !file.canRead()) {
LOGGER.log(Level.FINE, "Cannot find or read properties file. Returning empty credentials.");
return Optional.empty();
}
properties.load(new FileReader(file));
HttpTransport httpTransport = new NetHttpTransport();
JsonFactory jsonFactory = new JacksonFactory();
GoogleCredential credential = new GoogleCredential.Builder().setJsonFactory(jsonFactory)
.setTransport(httpTransport).setClientSecrets(OAuth2ClientCredentials.CLIENT_ID, OAuth2ClientCredentials.CLIENT_SECRET).build();
credential.setAccessToken(properties.getProperty(PROP_ACCESS_TOKEN));
credential.setRefreshToken(properties.getProperty(PROP_REFRESH_TOKEN));
return Optional.of(credential);
} catch (IOException e) {
throw new JDriveSyncException(JDriveSyncException.Reason.IOException, "Failed to load properties file: " + e.getMessage(), e);
}
}
代码示例来源:origin: rakam-io/rakam
@JsonRequest
@Path("/login_with_google")
public Response<WebUser> loginWithGoogle(@ApiParam("access_token") String accessToken) {
GoogleCredential credential = new GoogleCredential().setAccessToken(accessToken);
Oauth2 oauth2 = new Oauth2.Builder(new NetHttpTransport(),
new JacksonFactory(), credential).setApplicationName("Oauth2").build();
Userinfoplus userinfo;
try {
userinfo = oauth2.userinfo().get().execute();
if (!userinfo.getVerifiedEmail()) {
throw new RakamException("The Google email must be verified", BAD_REQUEST);
}
Optional<WebUser> userByEmail = service.getUserByEmail(userinfo.getEmail());
WebUser user = userByEmail.orElseGet(() ->
service.createUser(userinfo.getEmail(),
null, userinfo.getGivenName(),
userinfo.getGender(),
userinfo.getLocale(),
userinfo.getId(), false));
return getLoginResponseForUser(encryptionConfig.getSecretKey(), user, config.getCookieDuration());
} catch (IOException e) {
LOGGER.error(e);
throw new RakamException("Unable to login", INTERNAL_SERVER_ERROR);
}
}
代码示例来源:origin: com.google.crypto.tink/tink
/**
* Loads <a href="https://developers.google.com/accounts/docs/application-default-credentials"
* default Google Cloud credentials</a>.
*/
@Override
public KmsClient withDefaultCredentials() throws GeneralSecurityException {
try {
GoogleCredential credentials =
GoogleCredential.getApplicationDefault(new NetHttpTransport(), new JacksonFactory());
return withCredentials(credentials);
} catch (IOException e) {
throw new GeneralSecurityException("cannot load default credentials", e);
}
}
代码示例来源:origin: stackoverflow.com
final GoogleCredential credential = new Builder()
.setTransport(new NetHttpTransport())
.setJsonFactory(new JacksonFactory())
.setClientSecrets(OAuth2Provider.GOOGLE_CLIENT_ID, OAuth2Provider.GOOGLE_CLIENT_SECRET)
.build().setRefreshToken(refreshToken);
credential.refreshToken(); //do not forget to call
String newAccessToken = credential.getAccessToken();
代码示例来源:origin: googleads/aw-reporting
/**
* Builds the OAuth 2.0 credential for the user with a known authToken
*
* @param authToken the last authentication token
* @return the new OAuth2 {@link Credential}
*/
private Credential buildOAuth2Credential(String authToken) {
return new GoogleCredential.Builder()
.setClientSecrets(clientId, clientSecret)
.setJsonFactory(new JacksonFactory())
.setTransport(new NetHttpTransport())
.build()
.setRefreshToken(authToken);
}
代码示例来源:origin: stackoverflow.com
List<String> scopes = new ArrayList<String>();
scopes.add("https://www.google.com/m8/feeds/");
GoogleCredential credential = new GoogleCredential.Builder()
.setTransport(new NetHttpTransport())
.setJsonFactory( new JacksonFactory())
.setServiceAccountId("id@developer.gserviceaccount.com")
.setServiceAccountPrivateKeyFromP12File(new File("privatekey.p12"))
.setClientSecrets("clientID", "clientSecret")
.setServiceAccountScopes(scopes)
.build();
credential.refreshToken();
内容来源于网络,如有侵权,请联系作者删除!