本文整理汇总了Java中com.google.api.client.json.jackson2.JacksonFactory类的典型用法代码示例。如果您正苦于以下问题:Java JacksonFactory类的具体用法?Java JacksonFactory怎么用?Java JacksonFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JacksonFactory类属于com.google.api.client.json.jackson2包,在下文中一共展示了JacksonFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: performRequest
import com.google.api.client.json.jackson2.JacksonFactory; //导入依赖的package包/类
private static void performRequest(String accessToken, String refreshToken, String apiKey, String apiSecret) throws GeneralSecurityException, IOException, MessagingException {
HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
JsonFactory jsonFactory = new JacksonFactory();
final Credential credential = convertToGoogleCredential(accessToken, refreshToken, apiSecret, apiKey);
Builder builder = new Gmail.Builder(httpTransport, jsonFactory, credential);
builder.setApplicationName("OAuth API Sample");
Gmail gmail = builder.build();
MimeMessage content = createEmail("[email protected]", "[email protected]", "Test Email", "It works");
Message message = createMessageWithEmail(content);
gmail.users().messages().send("[email protected]", message).execute();
}
示例2: getCredential
import com.google.api.client.json.jackson2.JacksonFactory; //导入依赖的package包/类
public final Credential getCredential() {
if (googleCredential == null) {
try {
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
secureHttpTransport,
JacksonFactory.getDefaultInstance(),
googleSecrets,
requiredScopes)
.setAccessType("offline")
.setDataStoreFactory(new MemoryDataStoreFactory())
.build();
googleCredential = new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver())
.authorize("user");
} catch (IOException e) {
//Will not occur
logger.fatal(e);
throw new RuntimeException();
}
}
return googleCredential;
}
示例3: BigQueryExporter
import com.google.api.client.json.jackson2.JacksonFactory; //导入依赖的package包/类
public BigQueryExporter(BigQueryExporterConfiguration config) {
this.config = config;
this.checkedSchemas = new HashSet<String>();
this.existingSchemaMap = new HashMap<String, com.google.api.services.bigquery.model.TableSchema>();
HttpTransport transport = new NetHttpTransport();
JsonFactory jsonFactory = new JacksonFactory();
GoogleCredential credential;
try {
credential = GoogleCredential.getApplicationDefault(transport,
jsonFactory);
} catch (IOException e) {
throw new RuntimeException(e);
}
if (credential.createScopedRequired()) {
credential = credential.createScoped(BigqueryScopes.all());
}
this.bq = new Bigquery.Builder(transport, jsonFactory, credential)
.setApplicationName(this.config.applicationName).build();
}
示例4: createAuthorizedClient
import com.google.api.client.json.jackson2.JacksonFactory; //导入依赖的package包/类
/**
* 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);
// Depending on the environment that provides the default credentials (e.g. Compute Engine, App
// Engine), the credentials may require us to specify the scopes we need explicitly.
// 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();
}
示例5: authorize
import com.google.api.client.json.jackson2.JacksonFactory; //导入依赖的package包/类
private static void authorize(DataStoreFactory storeFactory, String userId) throws Exception {
// Depending on your application, there may be more appropriate ways of
// performing the authorization flow (such as on a servlet), see
// https://developers.google.com/api-client-library/java/google-api-java-client/oauth2#authorization_code_flow
// for more information.
GoogleAuthorizationCodeFlow authorizationFlow = new GoogleAuthorizationCodeFlow.Builder(
new NetHttpTransport(),
new JacksonFactory(),
CLIENT_ID,
CLIENT_SECRET,
Arrays.asList(SCOPE))
.setDataStoreFactory(storeFactory)
// Set the access type to offline so that the token can be refreshed.
// By default, the library will automatically refresh tokens when it
// can, but this can be turned off by setting
// api.dfp.refreshOAuth2Token=false in your ads.properties file.
.setAccessType("offline").build();
String authorizeUrl =
authorizationFlow.newAuthorizationUrl().setRedirectUri(CALLBACK_URL).build();
System.out.printf("Paste this url in your browser:%n%s%n", authorizeUrl);
// Wait for the authorization code.
System.out.println("Type the code you received here: ");
@SuppressWarnings("DefaultCharset") // Reading from stdin, so default charset is appropriate.
String authorizationCode = new BufferedReader(new InputStreamReader(System.in)).readLine();
// Authorize the OAuth2 token.
GoogleAuthorizationCodeTokenRequest tokenRequest =
authorizationFlow.newTokenRequest(authorizationCode);
tokenRequest.setRedirectUri(CALLBACK_URL);
GoogleTokenResponse tokenResponse = tokenRequest.execute();
// Store the credential for the user.
authorizationFlow.createAndStoreCredential(tokenResponse, userId);
}
示例6: getScriptService
import com.google.api.client.json.jackson2.JacksonFactory; //导入依赖的package包/类
@NotNull
public final Script getScriptService() {
@NotNull Script service = (Script) cacheClients.computeIfAbsent(Script.class,
(clazz) ->
new Script.Builder(
secureHttpTransport(),
JacksonFactory.getDefaultInstance(),
getCredential())
.setApplicationName(EventManager.getInstance().getName())
.setScriptRequestInitializer(new ScriptRequestInitializer(GoogleAPIToken.value()))
.setGoogleClientRequestInitializer(new ScriptRequestInitializer(GoogleAPIToken.value()))
.setHttpRequestInitializer(createHttpTimeout(getCredential(), 380000))
.build());
Timers.cacheCleanUpTimer().schedule(cacheClients, Script.class, service, 30, TimeUnit.MINUTES);
return service;
}
示例7: getSheetsService
import com.google.api.client.json.jackson2.JacksonFactory; //导入依赖的package包/类
@NotNull
public final Sheets getSheetsService() {
@NotNull Sheets service = (Sheets) cacheClients.computeIfAbsent(Sheets.class,
(clazz) ->
new Sheets.Builder(
secureHttpTransport(),
JacksonFactory.getDefaultInstance(),
getCredential())
.setApplicationName(EventManager.getInstance().getName())
.setSheetsRequestInitializer(new SheetsRequestInitializer(GoogleAPIToken.value()))
.setGoogleClientRequestInitializer(new SheetsRequestInitializer(GoogleAPIToken.value()))
.build());
Timers.cacheCleanUpTimer().schedule(cacheClients, Sheets.class, service, 30, TimeUnit.MINUTES);
return service;
}
示例8: getUrlShortenerService
import com.google.api.client.json.jackson2.JacksonFactory; //导入依赖的package包/类
@NotNull
public final Urlshortener getUrlShortenerService() {
@NotNull Urlshortener service = (Urlshortener) cacheClients.computeIfAbsent(Urlshortener.class,
(clazz) ->
new Urlshortener.Builder(
secureHttpTransport(),
JacksonFactory.getDefaultInstance(),
getCredential())
.setApplicationName(EventManager.getInstance().getName())
.setUrlshortenerRequestInitializer(new UrlshortenerRequestInitializer(GoogleAPIToken.value()))
.setGoogleClientRequestInitializer(new UrlshortenerRequestInitializer(GoogleAPIToken.value()))
.build());
Timers.cacheCleanUpTimer().schedule(cacheClients, Urlshortener.class, service, 30, TimeUnit.MINUTES);
return service;
}
示例9: getSurveyService
import com.google.api.client.json.jackson2.JacksonFactory; //导入依赖的package包/类
@NotNull
public final Surveys getSurveyService() {
@NotNull Surveys service = (Surveys) cacheClients.computeIfAbsent(Surveys.class,
(clazz) ->
new Surveys.Builder(
secureHttpTransport(),
JacksonFactory.getDefaultInstance(),
getCredential())
.setApplicationName(EventManager.getInstance().getName())
.setSurveysRequestInitializer(new SurveysRequestInitializer(GoogleAPIToken.value()))
.setGoogleClientRequestInitializer(new SurveysRequestInitializer(GoogleAPIToken.value()))
.build());
Timers.cacheCleanUpTimer().schedule(cacheClients, Urlshortener.class, service, 30, TimeUnit.MINUTES);
return service;
}
示例10: testSimpleRetry
import com.google.api.client.json.jackson2.JacksonFactory; //导入依赖的package包/类
public void testSimpleRetry() throws Exception {
FailThenSuccessBackoffTransport fakeTransport =
new FailThenSuccessBackoffTransport(HttpStatusCodes.STATUS_CODE_SERVER_ERROR, 3);
MockGoogleCredential credential = RetryHttpInitializerWrapper.newMockCredentialBuilder()
.build();
MockSleeper mockSleeper = new MockSleeper();
RetryHttpInitializerWrapper retryHttpInitializerWrapper = new RetryHttpInitializerWrapper(credential, mockSleeper,
TimeValue.timeValueSeconds(5));
Compute client = new Compute.Builder(fakeTransport, new JacksonFactory(), null)
.setHttpRequestInitializer(retryHttpInitializerWrapper)
.setApplicationName("test")
.build();
HttpRequest request = client.getRequestFactory().buildRequest("Get", new GenericUrl("http://elasticsearch.com"), null);
HttpResponse response = request.execute();
assertThat(mockSleeper.getCount(), equalTo(3));
assertThat(response.getStatusCode(), equalTo(200));
}
示例11: testIOExceptionRetry
import com.google.api.client.json.jackson2.JacksonFactory; //导入依赖的package包/类
public void testIOExceptionRetry() throws Exception {
FailThenSuccessBackoffTransport fakeTransport =
new FailThenSuccessBackoffTransport(HttpStatusCodes.STATUS_CODE_SERVER_ERROR, 1, true);
MockGoogleCredential credential = RetryHttpInitializerWrapper.newMockCredentialBuilder()
.build();
MockSleeper mockSleeper = new MockSleeper();
RetryHttpInitializerWrapper retryHttpInitializerWrapper = new RetryHttpInitializerWrapper(credential, mockSleeper,
TimeValue.timeValueMillis(500));
Compute client = new Compute.Builder(fakeTransport, new JacksonFactory(), null)
.setHttpRequestInitializer(retryHttpInitializerWrapper)
.setApplicationName("test")
.build();
HttpRequest request = client.getRequestFactory().buildRequest("Get", new GenericUrl("http://elasticsearch.com"), null);
HttpResponse response = request.execute();
assertThat(mockSleeper.getCount(), equalTo(1));
assertThat(response.getStatusCode(), equalTo(200));
}
示例12: getTubeService
import com.google.api.client.json.jackson2.JacksonFactory; //导入依赖的package包/类
private synchronized YouTube getTubeService()
{
if( tubeService == null )
{
tubeService = new YouTube.Builder(new NetHttpTransport(), new JacksonFactory(),
new HttpRequestInitializer()
{
@Override
public void initialize(HttpRequest request) throws IOException
{
// Nothing?
}
}).setApplicationName(EQUELLA).build();
}
return tubeService;
}
示例13: 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();
}
示例14: YouTubeSingleton
import com.google.api.client.json.jackson2.JacksonFactory; //导入依赖的package包/类
private YouTubeSingleton() {
credential = GoogleAccountCredential.usingOAuth2(
YTApplication.getAppContext(), Arrays.asList(SCOPES))
.setBackOff(new ExponentialBackOff());
youTube = new YouTube.Builder(new NetHttpTransport(), new JacksonFactory(), new HttpRequestInitializer() {
@Override
public void initialize(HttpRequest httpRequest) throws IOException {
}
}).setApplicationName(YTApplication.getAppContext().getString(R.string.app_name))
.build();
youTubeWithCredentials = new YouTube.Builder(new NetHttpTransport(), new JacksonFactory(), credential)
.setApplicationName(YTApplication.getAppContext().getString(R.string.app_name))
.build();
}
示例15: 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;
}