Как передать aws iot x.509 путь сертификата в Java - PullRequest
1 голос
/ 19 апреля 2019

Я использую лямбда-функцию aws, которая внутренне использует ядро ​​aws iot для публикации сообщений на подключенных устройствах. Я сгенерировал сертификат x509 из консоли aws и сохранил его в папке ресурсов проекта весенней загрузки, но вызвал лямбда-функцию, выдавшую FileNotFoundException

Я уже пробовал следующие способы:

1)

    ClassLoader classLoader = getClass().getClassLoader();
    File cityFile = new 
    File(classLoader.getResource("test.txt").getFile());

2) Добавлен следующий тег ресурса в pom.xml внутри тега сборки

    <resources>
        <resource>
            <directory>resources</directory>
                <targetPath>${project.build.outputDirectory}</targetPath>
                <includes>
                    <include>7913fa14e2-certificate.pem.crt</include>
                    <include>7913fa14e2-private.pem.key</include>
                </includes>
        </resource>
    </resources>

3) Мои поля:

    private static final String certificateFile = "src/main/resources/7913fa14e2-certificate.pem.crt";

4) Код:

    File file = new File(certificateFile);
    if (!file.exists()) {
        System.out.println("Certificate file: " + filename + " is not found.");
        return null;
    }

    try (BufferedInputStream stream = new BufferedInputStream(new 
    FileInputStream(file))) {
        final CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
        return (List<Certificate>) certFactory.generateCertificates(stream);
    } catch (IOException | CertificateException e) {
        System.out.println("Failed to load certificate file " + filename);
    }
    return null;

5) Ошибка:

    File file = new File(filename);

эта строка метания FileNotFoundException

...