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