Lotus Notes代理:java.io.IOException:访问被拒绝

时间:2019-06-21 12:03:28

标签: javaagents

我有一个Java代理,它将使用Google开发人员(https://developers.google.com/drive/api/v3/quickstart/java)提供的api列出Google云端硬盘中的所有文件。

但是,当尝试从“ C:\ Program Files(x86)\ IBM \ Notes \ framework”目录创建“ tokens”文件夹时,代理出现“访问被拒绝”错误。

我手动创建了“ tokens”文件夹,但该错误仍然发生。

我已将所有必需的jar文件放在“ / jvm / lib / ext”中,并在本地更新了Java策略,如下所示:

//自定义Java安全策略,以允许外部jar文件访问 授予{权限java.util.PropertyPermission“ http.keepAlive”,“读,写”; }; 授予{权限java.security.AllPermission; }

我的实际代理商代码

private static final String APPLICATION_NAME = "Google Drive API Java Quickstart";
private static final JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
private static final String TOKENS_DIRECTORY_PATH = "tokens";

/**
 * Global instance of the scopes required by this quickstart.
 * If modifying these scopes, delete your previously saved tokens/ folder.
 */
private static final List<String> SCOPES = Collections.singletonList(DriveScopes.DRIVE_METADATA_READONLY);
private static final String CREDENTIALS_FILE_PATH = "/credentials.json";

public void NotesMain() {

  try {
      Session session = getSession();
      AgentContext agentContext = session.getAgentContext();

      this.main();
      // (Your code goes here)

  } catch(Exception e) {
      e.printStackTrace();
   }

}

/**
 * Creates an authorized Credential object.
 * @param HTTP_TRANSPORT The network HTTP Transport.
 * @return An authorized Credential object.
 * @throws IOException If the credentials.json file cannot be found.
 */
private static Credential getCredentials(final NetHttpTransport HTTP_TRANSPORT) throws IOException {
    // Load client secrets.
    InputStream in = JavaAgent.class.getResourceAsStream(CREDENTIALS_FILE_PATH);
    if (in == null) {
        throw new FileNotFoundException("Resource not found: " + CREDENTIALS_FILE_PATH);
    }
    GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(in));

    // Build flow and trigger user authorization request.
    GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
            HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, SCOPES)
            .setDataStoreFactory(new FileDataStoreFactory(new java.io.File(TOKENS_DIRECTORY_PATH)))
            .setAccessType("offline")
            .build();
    LocalServerReceiver receiver = new LocalServerReceiver.Builder().setPort(8888).build();
    return new AuthorizationCodeInstalledApp(flow, receiver).authorize("user");
}

public static void main() throws IOException, GeneralSecurityException {
    // Build a new authorized API client service.
    final NetHttpTransport HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();
    Drive service = new Drive.Builder(HTTP_TRANSPORT, JSON_FACTORY, getCredentials(HTTP_TRANSPORT))
            .setApplicationName(APPLICATION_NAME)
            .build();

    // Print the names and IDs for up to 10 files.
    FileList result = service.files().list()
            .setPageSize(10)
            .setFields("nextPageToken, files(id, name)")
            .execute();
    List<File> files = result.getFiles();
    if (files == null || files.isEmpty()) {
        System.out.println("No files found.");
    } else {
        System.out.println("Files:");
        for (File file : files) {
            System.out.printf("%s (%s)\n", file.getName(), file.getId());
        }
    }
}

}

这是我从Java调试控制台得到的错误。

java.io.IOException:访问被拒绝。     在java.io.File.createNewFile(File.java:894)     位于com.google.api.client.util.store.FileDataStoreFactory $ FileDataStore。(FileDataStoreFactory.java:96)     在com.google.api.client.util.store.FileDataStoreFactory.createDataStore(FileDataStoreFactory.java:73)     在com.google.api.client.util.store.AbstractDataStoreFactory.getDataStore(AbstractDataStoreFactory.java:55)     在com.google.api.client.auth.oauth2.StoredCredential.getDefaultDataStore(StoredCredential.java:171)     在com.google.api.client.auth.oauth2.AuthorizationCodeFlow $ Builder.setDataStoreFactory(AuthorizationCodeFlow.java:744)     在com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow $ Builder.setDataStoreFactory(GoogleAuthorizationCodeFlow.java:209)     在JavaAgent.getCredentials(未知来源)     在JavaAgent.main(未知来源)     在JavaAgent.NotesMain(未知来源)     在Lotus.domino.AgentBase.runNotes(未知来源)     在Lotus.domino.NotesThread.run(未知来源)

0 个答案:

没有答案