org.datatransferproject.api.launcher.Monitor.severe()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(11.6k)|赞(0)|评价(0)|浏览(100)

本文整理了Java中org.datatransferproject.api.launcher.Monitor.severe()方法的一些代码示例,展示了Monitor.severe()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Monitor.severe()方法的具体详情如下:
包路径:org.datatransferproject.api.launcher.Monitor
类名称:Monitor
方法名:severe

Monitor.severe介绍

[英]Records a severe (error) level event.
[中]记录严重(错误)级别的事件。

代码示例

代码示例来源:origin: google/data-transfer-project

@Override
public void severe(Supplier<String> supplier, Object... data) {
 for (Monitor delegate : delegates) {
  delegate.severe(supplier, data);
 }
}

代码示例来源:origin: google/data-transfer-project

@Override
 public PublicKey parse(byte[] encoded) {
  KeyFactory factory;
  try {
   factory = KeyFactory.getInstance(ALGORITHM);
   return factory.generatePublic(new X509EncodedKeySpec(encoded));
  } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
   monitor.severe(() -> "Error parsing public key for: " + ALGORITHM, e);
   throw new RuntimeException("InvalidKeySpecException generating key", e);
  }
 }
}

代码示例来源:origin: google/data-transfer-project

@Override
public SecretKey generate() {
 try {
  KeyGenerator generator = KeyGenerator.getInstance(ALGORITHM);
  return generator.generateKey();
 } catch (NoSuchAlgorithmException e) {
  monitor.severe(() -> "NoSuchAlgorithmException for: " + ALGORITHM, e);
  throw new RuntimeException("Error creating key generator", e);
 }
}

代码示例来源:origin: google/data-transfer-project

@Override
public KeyPair generate() {
 KeyPairGenerator kpg = null;
 try {
  kpg = KeyPairGenerator.getInstance(ALGORITHM);
 } catch (NoSuchAlgorithmException e) {
  monitor.severe(() -> "NoSuchAlgorithmException for: " + ALGORITHM, e);
  throw new RuntimeException("NoSuchAlgorithmException generating key", e);
 }
 kpg.initialize(1024);
 return kpg.genKeyPair();
}

代码示例来源:origin: google/data-transfer-project

@Override
 public String decrypt(String encrypted) {
  try {
   byte[] decoded = BaseEncoding.base64Url().decode(encrypted);
   Cipher cipher = Cipher.getInstance(transformation);
   cipher.init(Cipher.DECRYPT_MODE, key);
   byte[] decrypted = cipher.doFinal(decoded);
   if (decrypted == null || decrypted.length <= 8) {
    throw new RuntimeException("incorrect decrypted text.");
   }
   byte[] data = new byte[decrypted.length - 8];
   System.arraycopy(decrypted, 8, data, 0, data.length);
   return new String(data, Charsets.UTF_8);
  } catch (BadPaddingException
    | IllegalBlockSizeException
    | InvalidKeyException
    | NoSuchAlgorithmException
    | NoSuchPaddingException e) {
   monitor.severe(() -> format("Error decrypting data, length: %s", encrypted.length()), e);
   throw new RuntimeException(e);
  }
 }
}

代码示例来源:origin: google/data-transfer-project

@Override
 public String encrypt(String data) {
  try {
   Cipher cipher = Cipher.getInstance(transformation);
   cipher.init(Cipher.ENCRYPT_MODE, key);
   byte[] salt = new byte[8];
   SecureRandom random = SecureRandom.getInstance("SHA1PRNG");
   random.nextBytes(salt);
   cipher.update(salt);
   byte[] encrypted = cipher.doFinal(data.getBytes(Charsets.UTF_8));
   return BaseEncoding.base64Url().encode(encrypted);
  } catch (BadPaddingException
    | IllegalBlockSizeException
    | InvalidKeyException
    | NoSuchAlgorithmException
    | NoSuchPaddingException e) {
   monitor.severe(() -> format("Exception encrypting data, length: %s", data.length()), e);
   throw new RuntimeException(e);
  }
 }
}

代码示例来源:origin: google/data-transfer-project

/** Lists the set of data types that support both import and export. */
 @Override
 public DataTypes handle(GetDataTypes request) {
  Set<String> transferDataTypes = registry.getTransferDataTypes();
  if (transferDataTypes.isEmpty()) {
   monitor.severe(
     () ->
       "No transfer data types were registered in "
         + AuthServiceProviderRegistry.class.getName());
  }
  return new DataTypes(transferDataTypes);
 }
}

代码示例来源:origin: google/data-transfer-project

@Override
public AuthData generateAuthData(
  String callbackUrl, String authCode, String id, AuthData initialAuthData, String extra) {
 // callbackbaseurl, id, initialAuthData and extra are not used.
 try {
  return new TokenAuthData(getToken(authCode));
 } catch (IOException e) {
  monitor.severe(() -> "Error getting RememberTheMilk AuthToken: ", e);
  return null;
 }
}

代码示例来源:origin: google/data-transfer-project

@Override
 public void initialize(ExtensionContext context) {
  if (initialized) {
   Monitor monitor = context.getMonitor();
   monitor.severe(() -> "InstagramTransferExtension already initialized");
   return;
  }

  ObjectMapper mapper =
    new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

  HttpTransport httpTransport = context.getService(HttpTransport.class);
  exporter = new InstagramPhotoExporter(mapper, httpTransport);
  initialized = true;
 }
}

代码示例来源:origin: google/data-transfer-project

@Override
public AuthFlowConfiguration generateConfiguration(String callbackBaseUrl, String id) {
 // NOTE: callbackBaseUrl is unused. After authentication, RememberTheMilk will redirect
 // to the callback set when we configured the application. To change this visit:
 // https://www.rememberthemilk.com/help/contact/support/?ctx=api.update&report=1
 URL authUrlSigned;
 try {
  authUrlSigned = signatureGenerator.getSignature(AUTH_URL, ImmutableMap.of("perms", perms));
 } catch (Exception e) {
  monitor.severe(() -> "Error generating RememberTheMilk Authentication URL", e);
  return null;
 }
 return new AuthFlowConfiguration(authUrlSigned.toString(), getTokenUrl(), AUTH_PROTOCOL, null);
}

代码示例来源:origin: google/data-transfer-project

/** Starts the api server, currently the reference implementation. */
public static void main(String[] args) {
 Monitor monitor = loadMonitor();
 monitor.info(() -> "Starting API Server.");
 Thread.setDefaultUncaughtExceptionHandler(
   (thread, t) ->
     monitor.severe(() -> "Uncaught exception in thread: " + thread.getName(), t));
 ApiMain apiMain = new ApiMain(monitor);
 apiMain.initializeHttp();
 apiMain.start();
}

代码示例来源:origin: google/data-transfer-project

@Override
public ExportResult<TaskContainerResource> export(
    UUID jobId, TokensAndUrlAuthData authData, Optional<ExportInformation> exportInformation) {
 // Create a new tasks service for the authorized user
 Tasks tasksService = getOrCreateTasksService(authData);
 IdOnlyContainerResource resource =
   exportInformation.isPresent()
     ? (IdOnlyContainerResource) exportInformation.get().getContainerResource()
     : null;
 PaginationData paginationData =
   exportInformation.isPresent() ? exportInformation.get().getPaginationData() : null;
 try {
  if (resource != null) {
   return getTasks(tasksService, resource, Optional.ofNullable(paginationData));
  } else {
   return getTasksList(tasksService, Optional.ofNullable(paginationData));
  }
 } catch (Exception e) {
  monitor.severe(() -> "Error occurred trying to retrieve task", e);
  return new ExportResult<>(e);
 }
}

代码示例来源:origin: google/data-transfer-project

@Override
public ExportResult<PhotosContainerResource> export(
    UUID jobId, TokenSecretAuthData authData, Optional<ExportInformation> exportInformation)
  throws IOException {
 StringPaginationToken paginationToken =
   exportInformation.isPresent()
     ? (StringPaginationToken) exportInformation.get().getPaginationData()
     : null;
 IdOnlyContainerResource resource =
   exportInformation.isPresent()
     ? (IdOnlyContainerResource) exportInformation.get().getContainerResource()
     : null;
 SmugMugInterface smugMugInterface;
 try {
  smugMugInterface = getOrCreateSmugMugInterface(authData);
 } catch (IOException e) {
  monitor.severe(() -> "Unable to create Smugmug service for user", e);
  throw e;
 }
 if (resource != null) {
  return exportPhotos(resource, paginationToken, smugMugInterface, jobId);
 } else {
  return exportAlbums(paginationToken, smugMugInterface);
 }
}

代码示例来源:origin: google/data-transfer-project

@Override
protected void runOneIteration() {
 if (JobMetadata.isInitialized()) {
  if (stopwatch.elapsed(TimeUnit.SECONDS) > credsTimeoutSeconds) {
   UUID jobId = JobMetadata.getJobId();
   markJobTimedOut(jobId);
   String message =
     format(
       "Waited over %d seconds for the creds to be provided on the claimed job: %s",
       credsTimeoutSeconds, jobId);
   monitor.severe(() -> message);
   throw new CredsTimeoutException(message, jobId);
  }
  pollUntilJobIsReady();
 } else {
  // Poll for an unassigned job to process with this transfer worker instance.
  // Once a transfer worker instance is assigned, the client will populate storage with
  // auth data encrypted with this instances public key and the copy process can begin
  pollForUnassignedJob();
 }
}

代码示例来源:origin: google/data-transfer-project

@Override
public AuthData generateAuthData(
  String callbackBaseUrl, String authCode, String id, AuthData initialAuthData, String extra) {
 Preconditions.checkArgument(
   Strings.isNullOrEmpty(extra), "Extra data not expected for OAuth flow");
 Preconditions.checkArgument(
   initialAuthData != null, "Initial auth data expected for " + config.getServiceName());
 OAuthGetAccessToken accessTokenRequest = new OAuthGetAccessToken(config.getAccessTokenUrl());
 accessTokenRequest.transport = httpTransport;
 accessTokenRequest.temporaryToken = ((TokenSecretAuthData) initialAuthData).getToken();
 accessTokenRequest.consumerKey = clientId;
 accessTokenRequest.verifier = authCode;
 accessTokenRequest.signer =
   config.getAccessTokenSigner(
     clientSecret, ((TokenSecretAuthData) initialAuthData).getSecret());
 TokenSecretAuthData accessToken;
 try {
  OAuthCredentialsResponse response = accessTokenRequest.execute();
  accessToken = new TokenSecretAuthData(response.token, response.tokenSecret);
 } catch (IOException e) {
  monitor.severe(() -> "Error retrieving request token", e);
  return null;
 }
 return accessToken;
}

代码示例来源:origin: google/data-transfer-project

() -> format("Polled job %s has auth data as expected. Done polling.", jobId));
} else {
 monitor.severe(
   () ->
     format(

代码示例来源:origin: google/data-transfer-project

@Override
public ImportResult importItem(
  UUID jobId, TokenSecretAuthData authData, PhotosContainerResource data) {
 try {
  SmugMugInterface smugMugInterface = getOrCreateSmugMugInterface(authData);
  for (PhotoAlbum album : data.getAlbums()) {
   importSingleAlbum(jobId, album, smugMugInterface);
  }
  for (PhotoModel photo : data.getPhotos()) {
   importSinglePhoto(jobId, photo, smugMugInterface);
  }
 } catch (IOException e) {
  monitor.severe(() -> "Error importing", e);
  return new ImportResult(e);
 }
 return ImportResult.OK;
}

代码示例来源:origin: google/data-transfer-project

@Override
 public void initialize(ExtensionContext context) {
  Monitor monitor = context.getMonitor();
  monitor.debug(() -> "Starting Twitter initialization");
  if (initialized) {
   monitor.severe(() -> "TwitterTransferExtension already initialized.");
   return;
  }

  AppCredentials appCredentials;
  try {
   appCredentials =
     context
       .getService(AppCredentialStore.class)
       .getAppCredentials(TWITTER_KEY, TWITTER_SECRET);
  } catch (IOException e) {
   monitor.info(
     () ->
       format(
         "Unable to retrieve Twitter AppCredentials. Did you set %s and %s?",
         TWITTER_KEY, TWITTER_SECRET),
     e);
   return;
  }

  exporter = new TwitterPhotosExporter(appCredentials, monitor);
  importer = new TwitterPhotosImporter(appCredentials, monitor);
  initialized = true;
 }
}

代码示例来源:origin: google/data-transfer-project

private void markJobTimedOut(UUID jobId) {
 PortabilityJob job = store.findJob(jobId);
 try {
  store.updateJob(
    jobId,
    job.toBuilder()
      .setState(PortabilityJob.State.ERROR)
      .setAndValidateJobAuthorization(
        job.jobAuthorization()
          .toBuilder()
          .setState(JobAuthorization.State.TIMED_OUT)
          .build())
      .build());
 } catch (IOException e) {
  // Suppress exception so we still pass out the original exception
  monitor.severe(
    () ->
      format(
        "IOException while marking job as timed out. JobId: %s; Exception: %s",
        jobId, e));
 }
}

代码示例来源:origin: google/data-transfer-project

@Override
public ImportResult importItem(
  UUID jobId, TokenSecretAuthData authData, PhotosContainerResource data) {
 Twitter twitterApi = TwitterApiWrapper.getInstance(appCredentials, authData);
 // Twitter doesn't support an 'Albums' concept, so that information is just lost.
 for (PhotoModel image : data.getPhotos()) {
  try {
   StatusUpdate update = new StatusUpdate(image.getDescription());
   InputStreamContent content =
     new InputStreamContent(null, getImageAsStream(image.getFetchableUrl()));
   update.media(image.getTitle(), content.getInputStream());
   twitterApi.tweets().updateStatus(update);
  } catch (IOException | TwitterException e) {
   monitor.severe(() -> "Error importing twitter photo", e);
   return new ImportResult(e);
  }
 }
 return new ImportResult(ResultType.OK);
}

相关文章