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


Java JsonFactory類代碼示例

本文整理匯總了Java中com.google.api.client.json.JsonFactory的典型用法代碼示例。如果您正苦於以下問題:Java JsonFactory類的具體用法?Java JsonFactory怎麽用?Java JsonFactory使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


JsonFactory類屬於com.google.api.client.json包,在下文中一共展示了JsonFactory類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getClient

import com.google.api.client.json.JsonFactory; //導入依賴的package包/類
/** Builds a new Pubsub client and returns it. */
public static Pubsub getClient(final HttpTransport httpTransport, final JsonFactory jsonFactory)
    throws IOException {
  checkNotNull(httpTransport);
  checkNotNull(jsonFactory);
  GoogleCredential credential =
      GoogleCredential.getApplicationDefault(httpTransport, jsonFactory);
  if (credential.createScopedRequired()) {
    credential = credential.createScoped(PubsubScopes.all());
  }
  if (credential.getClientAuthentication() != null) {
    System.out.println(
        "\n***Warning! You are not using service account credentials to "
            + "authenticate.\nYou need to use service account credentials for this example,"
            + "\nsince user-level credentials do not have enough pubsub quota,\nand so you will run "
            + "out of PubSub quota very quickly.\nSee "
            + "https://developers.google.com/identity/protocols/application-default-credentials.");
    System.exit(1);
  }
  HttpRequestInitializer initializer = new RetryHttpInitializerWrapper(credential);
  return new Pubsub.Builder(httpTransport, jsonFactory, initializer)
      .setApplicationName(APP_NAME)
      .build();
}
 
開發者ID:mdvorsky,項目名稱:DataflowSME,代碼行數:25,代碼來源:InjectorUtils.java

示例2: performRequest

import com.google.api.client.json.JsonFactory; //導入依賴的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

示例3: BigQueryExporter

import com.google.api.client.json.JsonFactory; //導入依賴的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.JsonFactory; //導入依賴的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: parse

import com.google.api.client.json.JsonFactory; //導入依賴的package包/類
static FirebaseToken parse(JsonFactory jsonFactory, String tokenString) throws IOException {
  try {
    JsonWebSignature jws =
        JsonWebSignature.parser(jsonFactory)
            .setPayloadClass(FirebaseTokenImpl.Payload.class)
            .parse(tokenString);
    return new FirebaseToken(
        new FirebaseTokenImpl(
            jws.getHeader(),
            (FirebaseTokenImpl.Payload) jws.getPayload(),
            jws.getSignatureBytes(),
            jws.getSignedContentBytes()));
  } catch (IOException e) {
    throw new IOException(
        "Decoding Firebase ID token failed. Make sure you passed the entire string JWT "
            + "which represents an ID token. See https://firebase.google.com/docs/auth/admin/"
            + "verify-id-tokens for details on how to retrieve an ID token.",
        e);
  }
}
 
開發者ID:firebase,項目名稱:firebase-admin-java,代碼行數:21,代碼來源:FirebaseToken.java

示例6: UserRecord

import com.google.api.client.json.JsonFactory; //導入依賴的package包/類
UserRecord(User response, JsonFactory jsonFactory) {
  checkNotNull(response, "response must not be null");
  checkNotNull(jsonFactory, "jsonFactory must not be null");
  checkArgument(!Strings.isNullOrEmpty(response.getUid()), "uid must not be null or empty");
  this.uid = response.getUid();
  this.email = response.getEmail();
  this.phoneNumber = response.getPhoneNumber();
  this.emailVerified = response.isEmailVerified();
  this.displayName = response.getDisplayName();
  this.photoUrl = response.getPhotoUrl();
  this.disabled = response.isDisabled();
  if (response.getProviders() == null || response.getProviders().length == 0) {
    this.providers = new ProviderUserInfo[0];
  } else {
    this.providers = new ProviderUserInfo[response.getProviders().length];
    for (int i = 0; i < this.providers.length; i++) {
      this.providers[i] = new ProviderUserInfo(response.getProviders()[i]);
    }
  }
  this.userMetadata = new UserMetadata(response.getCreatedAt(), response.getLastLoginAt());
  this.customClaims = parseCustomClaims(response.getCustomClaims(), jsonFactory);
}
 
開發者ID:firebase,項目名稱:firebase-admin-java,代碼行數:23,代碼來源:UserRecord.java

示例7: getProperties

import com.google.api.client.json.JsonFactory; //導入依賴的package包/類
Map<String, Object> getProperties(JsonFactory jsonFactory) {
  Map<String, Object> copy = new HashMap<>(properties);
  List<String> remove = new ArrayList<>();
  for (Map.Entry<String, String> entry : REMOVABLE_FIELDS.entrySet()) {
    if (copy.containsKey(entry.getKey()) && copy.get(entry.getKey()) == null) {
      remove.add(entry.getValue());
      copy.remove(entry.getKey());
    }
  }

  if (!remove.isEmpty()) {
    copy.put("deleteAttribute", ImmutableList.copyOf(remove));
  }

  if (copy.containsKey("phoneNumber") && copy.get("phoneNumber") == null) {
    copy.put("deleteProvider", ImmutableList.of("phone"));
    copy.remove("phoneNumber");
  }

  if (copy.containsKey(CUSTOM_ATTRIBUTES)) {
    Map customClaims = (Map) copy.remove(CUSTOM_ATTRIBUTES);
    copy.put(CUSTOM_ATTRIBUTES, serializeCustomClaims(customClaims, jsonFactory));
  }
  return ImmutableMap.copyOf(copy);
}
 
開發者ID:firebase,項目名稱:firebase-admin-java,代碼行數:26,代碼來源:UserRecord.java

示例8: testSetCustomAttributes

import com.google.api.client.json.JsonFactory; //導入依賴的package包/類
@Test
public void testSetCustomAttributes() throws Exception {
  MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
  response.setContent(TestUtils.loadResource("createUser.json"));
  MockHttpTransport transport = new MockHttpTransport.Builder()
      .setLowLevelHttpResponse(response)
      .build();
  FirebaseUserManager userManager = new FirebaseUserManager(gson, transport, credentials);
  TestResponseInterceptor interceptor = new TestResponseInterceptor();
  userManager.setInterceptor(interceptor);
  // should not throw
  ImmutableMap<String, Object> claims = ImmutableMap.<String, Object>of(
      "admin", true, "package", "gold");
  JsonFactory jsonFactory = Utils.getDefaultJsonFactory();
  userManager.updateUser(new UpdateRequest("testuser")
      .setCustomClaims(claims), jsonFactory);
  checkRequestHeaders(interceptor);

  ByteArrayOutputStream out = new ByteArrayOutputStream();
  interceptor.getResponse().getRequest().getContent().writeTo(out);
  GenericJson parsed = jsonFactory.fromString(new String(out.toByteArray()), GenericJson.class);
  assertEquals("testuser", parsed.get("localId"));
  assertEquals(jsonFactory.toString(claims), parsed.get("customAttributes"));
}
 
開發者ID:firebase,項目名稱:firebase-admin-java,代碼行數:25,代碼來源:FirebaseUserManagerTest.java

示例9: getClient

import com.google.api.client.json.JsonFactory; //導入依賴的package包/類
/**
 * Builds a new Pubsub client and returns it.
 */
public static Pubsub getClient(final HttpTransport httpTransport,
                               final JsonFactory jsonFactory)
         throws IOException {
    checkNotNull(httpTransport);
    checkNotNull(jsonFactory);
    GoogleCredential credential =
        GoogleCredential.getApplicationDefault(httpTransport, jsonFactory);
    if (credential.createScopedRequired()) {
        credential = credential.createScoped(PubsubScopes.all());
    }
    if (credential.getClientAuthentication() != null) {
      System.out.println("\n***Warning! You are not using service account credentials to "
        + "authenticate.\nYou need to use service account credentials for this example,"
        + "\nsince user-level credentials do not have enough pubsub quota,\nand so you will run "
        + "out of PubSub quota very quickly.\nSee "
        + "https://developers.google.com/identity/protocols/application-default-credentials.");
      System.exit(1);
    }
    HttpRequestInitializer initializer =
        new RetryHttpInitializerWrapper(credential);
    return new Pubsub.Builder(httpTransport, jsonFactory, initializer)
            .setApplicationName(APP_NAME)
            .build();
}
 
開發者ID:davorbonaci,項目名稱:beam-portability-demo,代碼行數:28,代碼來源:InjectorUtils.java

示例10: getProjectsApiStub

import com.google.api.client.json.JsonFactory; //導入依賴的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

示例11: getServiceAccountsApiStub

import com.google.api.client.json.JsonFactory; //導入依賴的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;
}
 
開發者ID:GoogleCloudPlatform,項目名稱:policyscanner,代碼行數:26,代碼來源:GCPServiceAccount.java

示例12: ServiceConfigSupplier

import com.google.api.client.json.JsonFactory; //導入依賴的package包/類
@VisibleForTesting
ServiceConfigSupplier(
    Environment environment,
    HttpTransport httpTransport,
    JsonFactory jsonFactory,
    final GoogleCredential credential) {
  this.environment = environment;
  HttpRequestInitializer requestInitializer = new HttpRequestInitializer() {
    @Override
    public void initialize(HttpRequest request) throws IOException {
      request.setThrowExceptionOnExecuteError(false);
      credential.initialize(request);
    }
  };
  this.serviceManagement =
      new ServiceManagement.Builder(httpTransport, jsonFactory, requestInitializer)
          .setApplicationName("Endpoints Frameworks Java")
          .build();
}
 
開發者ID:cloudendpoints,項目名稱:endpoints-management-java,代碼行數:20,代碼來源:ServiceConfigSupplier.java

示例13: createServiceAccountKeyManager

import com.google.api.client.json.JsonFactory; //導入依賴的package包/類
private static ServiceAccountKeyManager createServiceAccountKeyManager() {
  try {
    final HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
    final JsonFactory jsonFactory = Utils.getDefaultJsonFactory();
    final GoogleCredential credential = GoogleCredential
        .getApplicationDefault(httpTransport, jsonFactory)
        .createScoped(IamScopes.all());
    final Iam iam = new Iam.Builder(
        httpTransport, jsonFactory, credential)
        .setApplicationName(SERVICE_NAME)
        .build();
    return new ServiceAccountKeyManager(iam);
  } catch (GeneralSecurityException | IOException e) {
    throw new RuntimeException(e);
  }
}
 
開發者ID:spotify,項目名稱:styx,代碼行數:17,代碼來源:StyxScheduler.java

示例14: build

import com.google.api.client.json.JsonFactory; //導入依賴的package包/類
@Override
public DataprocHadoopRunner build() {
  CredentialProvider credentialProvider = Optional.ofNullable(this.credentialProvider)
      .orElseGet(DefaultCredentialProvider::new);

  try {
    final HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
    final JsonFactory jsonFactory = new JacksonFactory();

    final GoogleCredential credentials = credentialProvider.getCredential(SCOPES);
    final Dataproc dataproc = new Dataproc.Builder(httpTransport, jsonFactory, credentials)
        .setApplicationName(APPLICATION_NAME).build();
    final Storage storage = new Storage.Builder(httpTransport, jsonFactory, credentials)
        .setApplicationName(APPLICATION_NAME).build();

    final DataprocClient dataprocClient =
        new DataprocClient(dataproc, storage, projectId, clusterId, clusterProperties);

    return new DataprocHadoopRunnerImpl(dataprocClient);
  } catch (Throwable e) {
    throw Throwables.propagate(e);
  }
}
 
開發者ID:spotify,項目名稱:dataproc-java-submitter,代碼行數:24,代碼來源:DataprocHadoopRunnerImpl.java

示例15: setup

import com.google.api.client.json.JsonFactory; //導入依賴的package包/類
@Before
public void setup() throws Exception {
  when(pipelineOptionsHierarchyFactory.forProject(
          eq(project), eq(MajorVersion.ONE), any(IProgressMonitor.class)))
      .thenReturn(pipelineOptionsHierarchy);

  credential = new GoogleCredential.Builder()
      .setJsonFactory(mock(JsonFactory.class))
      .setTransport(mock(HttpTransport.class))
      .setClientSecrets("clientId", "clientSecret").build();
  credential.setRefreshToken("fake-refresh-token");
  when(loginService.getCredential("[email protected]")).thenReturn(credential);

  when(dependencyManager.getProjectMajorVersion(project)).thenReturn(MajorVersion.ONE);
  dataflowDelegate = new DataflowPipelineLaunchDelegate(javaDelegate,
      pipelineOptionsHierarchyFactory, dependencyManager, workspaceRoot, loginService);
}
 
開發者ID:GoogleCloudPlatform,項目名稱:google-cloud-eclipse,代碼行數:18,代碼來源:DataflowPipelineLaunchDelegateTest.java


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