当前位置: 首页>>代码示例>>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;未经允许,请勿转载。