* Certificate and PKCS#7. If the first one fails an error code will be
* returned. I the second fails a Exception will be thrown.
*/
private ErrorCode certreqInternal(UserDataVOWS userdata, String requestdata, int requesttype) throws Exception {
// Request a certificate via the WS API
final CertificateResponse certificateResponse;
try {
certificateResponse = ejbcaraws.certificateRequest(userdata, requestdata, requesttype, null, CertificateHelper.RESPONSETYPE_CERTIFICATE);
} catch (EjbcaException_Exception e) {
final ErrorCode errorCode = e.getFaultInfo().getErrorCode();
log.info(errorCode.getInternalErrorCode(), e);
assertNotNull("error code should not be null", errorCode);
return errorCode;
}
// Verify that the response is of the right type
assertNotNull(certificateResponse);
assertTrue(certificateResponse.getResponseType().equals(CertificateHelper.RESPONSETYPE_CERTIFICATE));
// Verify that the certificate in the response has the same Subject DN
// as in the request.
final X509Certificate cert = certificateResponse.getCertificate();
assertNotNull(cert);
assertTrue(cert.getSubjectDN().toString().equals(userdata.getSubjectDN()));
// Request a PKCS#7 via the WS API
final CertificateResponse pkcs7Response = ejbcaraws.certificateRequest(userdata, requestdata, requesttype, null, CertificateHelper.RESPONSETYPE_PKCS7);
// Verify that the response is of the right type
assertTrue(pkcs7Response.getResponseType().equals(CertificateHelper.RESPONSETYPE_PKCS7));
// Verify that the PKCS#7 response contains a certificate
CMSSignedData cmsSignedData = new CMSSignedData(CertificateHelper.getPKCS7(pkcs7Response.getData()));
assertNotNull(cmsSignedData);
CertStore certStore = cmsSignedData.getCertificatesAndCRLs("Collection", "BC");
assertTrue(certStore.getCertificates(null).size() == 1);
return null;
}