/** Helper method, which extracts a valid X509 certificate for an end point. */ private X509Certificate getX509CertificateFromEndpointType(EndpointType endpointType) { try { String body = endpointType.getCertificate(); String endpointCertificate = "-----BEGIN CERTIFICATE-----\n" + body + "\n-----END CERTIFICATE-----"; CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509"); X509Certificate cert = (X509Certificate) certificateFactory.generateCertificate( new ByteArrayInputStream(endpointCertificate.getBytes())); cert.checkValidity(); return cert; } catch (CertificateException e) { throw new RuntimeException("Failed to get valid certificate from Endpoint data", e); } }