當前位置: 首頁>>代碼示例>>Java>>正文


Java JacksonFactory類代碼示例

本文整理匯總了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();
}
 
開發者ID:tburne,項目名稱:blog-examples,代碼行數:12,代碼來源:ClientRequestAPI.java

示例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;
}
 
開發者ID:ViniciusArnhold,項目名稱:ProjectAltaria,代碼行數:25,代碼來源:GoogleClientServiceFactory.java

示例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();
}
 
開發者ID:frew,項目名稱:chute,代碼行數:21,代碼來源:BigQueryExporter.java

示例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();
}
 
開發者ID:GoogleCloudPlatform,項目名稱:java-docs-samples,代碼行數:26,代碼來源:Snippets.java

示例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);
}
 
開發者ID:googleads,項目名稱:googleads-java-lib,代碼行數:37,代碼來源:AdvancedCreateCredentialFromScratch.java

示例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;
}
 
開發者ID:ViniciusArnhold,項目名稱:ProjectAltaria,代碼行數:19,代碼來源:GoogleClientServiceFactory.java

示例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;
}
 
開發者ID:ViniciusArnhold,項目名稱:ProjectAltaria,代碼行數:18,代碼來源:GoogleClientServiceFactory.java

示例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;
}
 
開發者ID:ViniciusArnhold,項目名稱:ProjectAltaria,代碼行數:18,代碼來源:GoogleClientServiceFactory.java

示例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;
}
 
開發者ID:ViniciusArnhold,項目名稱:ProjectAltaria,代碼行數:18,代碼來源:GoogleClientServiceFactory.java

示例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));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:23,代碼來源:RetryHttpInitializerWrapperTests.java

示例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));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:22,代碼來源:RetryHttpInitializerWrapperTests.java

示例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;
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:17,代碼來源:GoogleServiceImpl.java

示例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();
}
 
開發者ID:dlemmermann,項目名稱:CalendarFX,代碼行數:21,代碼來源:GoogleConnector.java

示例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();
    }
 
開發者ID:pawelpaszki,項目名稱:youtube_background_android,代碼行數:19,代碼來源:YouTubeSingleton.java

示例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;
}
 
開發者ID:GoogleCloudPlatform,項目名稱:policyscanner,代碼行數:27,代碼來源:GCPProject.java


注:本文中的com.google.api.client.json.jackson2.JacksonFactory類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。