Source:
public SimpleCertificateResponseMessageType importToTruststore(ImportToTruststoreRequestMessageType request) { if (StringUtils.isBlank(request.getAlias()) || CollectionUtils.isEmpty(request.getIntermediateList()) || null == request.getRootCert()) { return buildSimpleResponse(false, "Alias, CA Root and CA Intermediate are required."); } tempTruststore = null; if(!copyFile(FILE_JKS_CACERTS, FILE_JKS_CACERTS_NEW)){ return buildSimpleResponse(false, "unable to create the temporary Truststore."); } try{ String alias = request.getAlias(); Certificate certRoot = CertificateUtil.createCertificate(request.getRootCert()); Map<String, Certificate> mapCerts = new HashMap<>(); int indexInt = 0; for (DataHandler cert : request.getIntermediateList()) { mapCerts.put(MessageFormat.format("{0}_intermediate_{1}", alias, indexInt++), CertificateUtil.createCertificate(cert)); } if (MapUtils.isEmpty(mapCerts) || null == certRoot) { return buildSimpleResponse(false, "Error creating certificate chain for truststore."); } Certificate certAlias = CertificateManagerImpl.getInstance().getCertificateBy(alias); List<ListCertificateType> certChain = buildChain(certAlias, getTempTruststore()); for(ListCertificateType item: certChain){ getTempTruststore().deleteEntry(item.getAlias()); } getTempTruststore().setCertificateEntry(MessageFormat.format("{0}_root",alias), certRoot); for (Entry<String, Certificate> entryCert : mapCerts.entrySet()) { getTempTruststore().setCertificateEntry(entryCert.getKey(), entryCert.getValue()); } CoreHelpUtils.saveJksTo(getTempTruststore(), getPasswordTruststore(), FILE_JKS_CACERTS_NEW); }catch(CertificateManagerException | KeyStoreException | UtilException | CertificateEncodingException e){ LOG.error("error while importing to the temporary truststore: {}",e.getLocalizedMessage(), e); return buildSimpleResponse(false, "error while importing to the temporary truststore."); } return buildSimpleResponse(true, "Import is successful into the temporary truststore."); }

Target:
public SimpleCertificateResponseMessageType importToTruststore(ImportToTruststoreRequestMessageType request) { if (StringUtils.isBlank(request.getAlias()) || CollectionUtils.isEmpty(request.getIntermediateList()) || null == request.getRootCert()) { return buildSimpleResponse(false, "Alias, CA Root and CA Intermediate are required."); } tempTruststore = null; if(!copyFile(FILE_JKS_CACERTS, FILE_JKS_CACERTS_NEW)){ return buildSimpleResponse(false, "Unable to create the temporary TrustStore."); } try{ String alias = request.getAlias(); Certificate certRoot = CertificateUtil.createCertificate(request.getRootCert()); Map<String, Certificate> mapCerts = new HashMap<>(); int indexInt = 0; for (DataHandler cert : request.getIntermediateList()) { mapCerts.put(MessageFormat.format("{0}_intermediate_{1}", alias, indexInt++), CertificateUtil.createCertificate(cert)); } if (MapUtils.isEmpty(mapCerts) || null == certRoot) { return buildSimpleResponse(false, "Error creating certificate chain for TrustStore."); } Certificate certAlias = CertificateManagerImpl.getInstance().getCertificateBy(alias); List<ListCertificateType> certChain = buildChain(certAlias, getTempTruststore()); for(ListCertificateType item: certChain){ getTempTruststore().deleteEntry(item.getAlias()); } getTempTruststore().setCertificateEntry(MessageFormat.format("{0}_root",alias), certRoot); for (Entry<String, Certificate> entryCert : mapCerts.entrySet()) { getTempTruststore().setCertificateEntry(entryCert.getKey(), entryCert.getValue()); } CoreHelpUtils.saveJksTo(getTempTruststore(), getPasswordTruststore(), FILE_JKS_CACERTS_NEW); }catch(CertificateManagerException | KeyStoreException | UtilException | CertificateEncodingException e){ LOG.error("Error occurred while importing to the temporary TrustStore: {}", e.getLocalizedMessage(), e); return buildSimpleResponse(false, "Error occurred while importing to the temporary TrustStore."); } return buildSimpleResponse(true, "Import into the temporary TrustStore is successful."); }