Package com.google.api.client.json

Examples of com.google.api.client.json.JsonFactory


      + "\"token_type\":\"example\",\"expires_in\":3600,"
      + "\"refresh_token\":\"tGzv3JOkF0XG5Qx2TlKWIA\","
      + "\"example_parameter\":\"example_value\"}";

  public void test() throws Exception {
    JsonFactory jsonFactory = new JacksonFactory();
    TokenResponse response = jsonFactory.fromString(JSON, TokenResponse.class);
    assertEquals("2YotnFZFEjr1zCsicMWpAA", response.getAccessToken());
    assertEquals("example", response.getTokenType());
    assertEquals(3600L, response.getExpiresInSeconds().longValue());
    assertEquals("tGzv3JOkF0XG5Qx2TlKWIA", response.getRefreshToken());
    assertEquals("example_value", response.get("example_parameter"));
View Full Code Here


  private static final String JSON = "{\"error\":\"invalid_request\","
      + "\"error_uri\":\"http://www.example.com/error\","
      + "\"error_description\":\"error description\"}";

  public void test() throws Exception {
    JsonFactory jsonFactory = new JacksonFactory();
    TokenErrorResponse response = jsonFactory.fromString(JSON, TokenErrorResponse.class);
    assertEquals("invalid_request", response.getError());
    assertEquals("http://www.example.com/error", response.getErrorUri());
    assertEquals("error description", response.getErrorDescription());
  }
View Full Code Here

  private static final int AGE = 42;

  public void testBuilder() throws Exception {
    HttpTransport transport = new MockHttpTransport();
    JsonFactory jsonFactory = new JacksonFactory();
    GooglePublicKeysManager.Builder builder = new GooglePublicKeysManager.Builder(transport, jsonFactory);

    GooglePublicKeysManager certs = builder.build();
    assertEquals(transport, certs.getTransport());
    assertEquals(jsonFactory, certs.getJsonFactory());
View Full Code Here

* @author Yaniv Inbar
*/
public class UtilsTest extends TestCase {

  public void testGetDefaultJsonFactory() {
    JsonFactory jsonFactory = Utils.getDefaultJsonFactory();
    assertNotNull(jsonFactory);
    assertTrue(jsonFactory instanceof JacksonFactory);
    JsonFactory secondCall = Utils.getDefaultJsonFactory();
    assertSame(jsonFactory, secondCall);
  }
View Full Code Here

            return result;
          }
        };
      }
    };
    JsonFactory jsonFactory = new JacksonFactory();
    MockGoogleJsonClient client = new MockGoogleJsonClient.Builder(
        transport, jsonFactory, HttpTesting.SIMPLE_URL, "", null, false).setApplicationName(
        "Test Application").build();
    MockGoogleJsonClientRequest<String> request =
        new MockGoogleJsonClientRequest<String>(client, "GET", "foo", null, String.class);
View Full Code Here

  public void testAppEngineCredentialWrapper() throws IOException {
    final String expectedAccessToken = "ExpectedAccessToken";
    final Collection<String> emptyScopes = Collections.emptyList();

    HttpTransport transport = new MockHttpTransport();
    JsonFactory jsonFactory = new JacksonFactory();

    MockAppIdentityService appIdentity = new MockAppIdentityService();
    appIdentity.setAccessTokenText(expectedAccessToken);

    AppIdentityCredential.Builder builder = new AppIdentityCredential.Builder(emptyScopes);
View Full Code Here

    String authHeader = headers.getAuthorization();
    assertTrue(authHeader.contains(expectedAccessToken));
  }

  public void testAppEngineCredentialWrapperNullTransportThrows() throws IOException {
    JsonFactory jsonFactory = new JacksonFactory();
    try {
      new AppIdentityCredential.AppEngineCredentialWrapper(null, jsonFactory);
      fail();
    } catch (NullPointerException expected) {
    }
View Full Code Here

   * @return a GoogleAuthorizationCodeFlow
   */
  protected GoogleAuthorizationCodeFlow getAuthorizationCodeFlow(boolean usePersistedCredentials)
      throws IOException {
    HttpTransport httpTransport = new NetHttpTransport();
    JsonFactory jsonFactory = new JacksonFactory();
    Collection<String> scopes = Arrays.asList(OAUTH2_SCOPE);
    GoogleClientSecrets clientSecrets = getClientSecrets();
    GoogleAuthorizationCodeFlow flow;
    if (usePersistedCredentials) {
      flow = new GoogleAuthorizationCodeFlow.Builder(
View Full Code Here

    this.backupName = backupName;
    this.historyCount = history;
    this.historyName = history > 0 ? backupName + " " + new SimpleDateFormat("yyyy.MM.dd_HH.mm.ss").format(new Date()) : null;

    final HttpTransport httpTransport = new NetHttpTransport();
    final JsonFactory jsonFactory = new JacksonFactory();

    final GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(httpTransport, jsonFactory, googleDriveOptions.getClientID(), googleDriveOptions.getClientSecret(),
        Arrays.asList(DriveScopes.DRIVE)).setAccessType("offline").setApprovalPrompt("auto").build();

    this.clientTokenPath = Paths.get(googleDriveOptions.getClientTokenPath());

    try {
      final String clientTokenAsJson = Files.exists(this.clientTokenPath) ? FileUtils.readFileToString(this.clientTokenPath.toFile()) : null;

      credential = new GoogleCredential.Builder().setTransport(new NetHttpTransport()).setJsonFactory(new GsonFactory())
          .setClientSecrets(googleDriveOptions.getClientID(), googleDriveOptions.getClientSecret()).build();

      if (StringUtils.isEmpty(clientTokenAsJson)) {

        final String url = flow.newAuthorizationUrl().setRedirectUri(REDIRECT_URL).build();
        System.out.println("Please open the following URL in your browser, copy the authorization code and enter below.");
        System.out.println("\n" + url + "\n");
        final String code = new BufferedReader(new InputStreamReader(System.in)).readLine().trim();

        clientToken = flow.newTokenRequest(code).setRedirectUri(REDIRECT_URL).execute();

        storeClientToken(jsonFactory);
        LOGGER.log(Level.INFO, "client token stored in '" + this.clientTokenPath + "'");
      } else {

        clientToken = jsonFactory.createJsonParser(clientTokenAsJson).parse(GoogleTokenResponse.class);
      }

      credential.setFromTokenResponse(clientToken);

    } catch (final IOException e) {
View Full Code Here

    if (service != null)
      return;

    final HttpTransport httpTransport = new NetHttpTransport();
    final JsonFactory jsonFactory = new JacksonFactory();
    service = new Drive.Builder(httpTransport, jsonFactory, credential).setApplicationName("Backup").build();
    credential.setExpiresInSeconds(MIN_TOKEN_REFRESH_TIMEOUT);
    try {
      refreshCredential();
    } catch (IOException e) {
View Full Code Here

TOP

Related Classes of com.google.api.client.json.JsonFactory

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.