From ce2a8019343806449255f2a2674890e6a86c825a Mon Sep 17 00:00:00 2001 From: prabathabey Date: Thu, 7 Jul 2016 14:10:03 +0530 Subject: [PATCH] Fixing https://wso2.org/jira/browse/EMM-1448 which fixes issues while persisting certificates when PostgreSQL is used as the underlying certificate management repository database --- .../mgt/core/dao/impl/GenericCertificateDAOImpl.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/dao/impl/GenericCertificateDAOImpl.java b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/dao/impl/GenericCertificateDAOImpl.java index 3c3278f89f..9d1129d067 100644 --- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/dao/impl/GenericCertificateDAOImpl.java +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/dao/impl/GenericCertificateDAOImpl.java @@ -67,10 +67,9 @@ public class GenericCertificateDAOImpl implements CertificateDAO { serialNumber = String.valueOf(certificate.getCertificate().getSerialNumber()); } byte[] bytes = Serializer.serialize(certificate.getCertificate()); - ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes); stmt.setString(1, serialNumber); - stmt.setObject(2, byteArrayInputStream); + stmt.setBytes(2, bytes); stmt.setInt(3, certificate.getTenantId()); stmt.setString(4, username); stmt.addBatch(); @@ -102,7 +101,7 @@ public class GenericCertificateDAOImpl implements CertificateDAO { stmt.setInt(2, tenantId); resultSet = stmt.executeQuery(); - while (resultSet.next()) { + if (resultSet.next()) { certificateResponse = new CertificateResponse(); byte [] certificateBytes = resultSet.getBytes("CERTIFICATE"); certificateResponse.setCertificate(certificateBytes); @@ -110,7 +109,6 @@ public class GenericCertificateDAOImpl implements CertificateDAO { certificateResponse.setTenantId(resultSet.getInt("TENANT_ID")); certificateResponse.setUsername(resultSet.getString("USERNAME")); CertificateGenerator.extractCertificateDetails(certificateBytes, certificateResponse); - break; } } catch (SQLException e) { String errorMsg =