@Test public void testFileNotFound() { String fileName = certDir + UNKNOWN_ID + ".pem"; String pem = service.getPem(fileName); assertTrue(StringUtils.isBlank(pem)); }
public String getPem(String fileName) { File pemFile = new File(fileName); if (!pemFile.isFile()) { return StringUtils.EMPTY; } else { StringWriter sw = new StringWriter(); try (JcaPEMWriter pemWriter = new JcaPEMWriter(sw)) { X509Certificate cert = readCertFromFile(fileName); pemWriter.writeObject(cert); pemWriter.flush(); return sw.toString(); } catch (IOException e) { throw new CompanyCertificateException(logMessage.getMessage(FAIL_READ_CERT, fileName), logMessage.getMessage(FAIL_READ_CERT_INVALID_FILE, fileName)); } } }
CompanyCertificateService { public String getPem(String fileName) { File pemFile = new File(fileName); if (!pemFile.isFile()) { return StringUtils.EMPTY; } else { StringWriter sw = new StringWriter(); try (JcaPEMWriter pemWriter = new JcaPEMWriter(sw)) { X509Certificate cert = readCertFromFile(fileName); pemWriter.writeObject(cert); pemWriter.flush(); return sw.toString(); } catch (IOException e) { throw new CompanyCertificateException(logMessage.getMessage(FAIL_READ_CERT, fileName), logMessage.getMessage(FAIL_READ_CERT_INVALID_FILE, fileName)); } } } }
CompanyCertificateService { public String getPem(String fileName) { File pemFile = new File(fileName); if (!pemFile.isFile()) { return StringUtils.EMPTY; } else { StringWriter sw = new StringWriter(); try (JcaPEMWriter pemWriter = new JcaPEMWriter(sw)) { X509Certificate cert = readCertFromFile(fileName); pemWriter.writeObject(cert); pemWriter.flush(); return sw.toString(); } catch (IOException e) { throw new CompanyCertificateException(logMessage.getMessage(FAIL_READ_CERT, fileName), logMessage.getMessage(FAIL_READ_CERT_INVALID_FILE, fileName)); } } }  }
CompanyCertificateService { public String getPem(String fileName) { File pemFile = new File(fileName); if (!pemFile.isFile()) { return StringUtils.EMPTY; } else { StringWriter sw = new StringWriter(); try (JcaPEMWriter pemWriter = new JcaPEMWriter(sw)) { X509Certificate cert = readCertFromFile(fileName); pemWriter.writeObject(cert); pemWriter.flush(); return sw.toString(); } catch (IOException e) { throw new CompanyCertificateException(logMessage.getMessage(FAIL_READ_CERT, fileName), logMessage.getMessage(FAIL_READ_CERT_INVALID_FILE, fileName)); } } }  @PostConstruct void init(); void importCertificate(Application application); void importUserCertificate(Application application); void importAppCertificate(Application application); String getPem(String fileName); String getCommonNameFromApplicationCertificate(Application application); String getEmailAddressFromApplicationCertificate(Application application); }
CompanyCertificateService { public String getPem(String fileName) { File pemFile = new File(fileName); if (!pemFile.isFile()) { return StringUtils.EMPTY; } else { StringWriter sw = new StringWriter(); try (JcaPEMWriter pemWriter = new JcaPEMWriter(sw)) { X509Certificate cert = readCertFromFile(fileName); pemWriter.writeObject(cert); pemWriter.flush(); return sw.toString(); } catch (IOException e) { throw new CompanyCertificateException(logMessage.getMessage(FAIL_READ_CERT, fileName), logMessage.getMessage(FAIL_READ_CERT_INVALID_FILE, fileName)); } } }  @PostConstruct void init(); void importCertificate(Application application); void importUserCertificate(Application application); void importAppCertificate(Application application); String getPem(String fileName); String getCommonNameFromApplicationCertificate(Application application); String getEmailAddressFromApplicationCertificate(Application application);  }