Example usage for java.security.cert CertificateException printStackTrace

List of usage examples for java.security.cert CertificateException printStackTrace

Introduction

In this page you can find the example usage for java.security.cert CertificateException printStackTrace.

Prototype

public void printStackTrace(PrintStream s) 

Source Link

Document

Prints this throwable and its backtrace to the specified print stream.

Usage

From source file:org.ejbca.core.protocol.ws.client.NestedCrmfRequestTestCommand.java

private void writeCertificate(X509Certificate cert, String path, String filename) {

    if (!StringUtils.endsWith(path, "/")) {
        path = path + "/";
    }/*from  ww w  . jav  a 2s.c  o m*/
    ArrayList<Certificate> certCollection = new ArrayList<Certificate>();
    certCollection.add(cert);

    try {
        byte[] pemRaCert = CertTools.getPEMFromCerts(certCollection);

        FileOutputStream out = new FileOutputStream(new File(path + filename));
        out.write(pemRaCert);
        out.close();
    } catch (CertificateException e) {
        e.printStackTrace(getPrintStream());
        System.exit(-1);
    } catch (FileNotFoundException e) {
        e.printStackTrace(getPrintStream());
        System.exit(-1);
    } catch (IOException e) {
        e.printStackTrace(getPrintStream());
        System.exit(-1);
    }
}

From source file:org.ejbca.core.protocol.ws.client.NestedCrmfRequestTestCommand.java

/**
 * Creates a new instance of RaAddUserCommand
 *
 * @param args command line arguments//from   w w w.j  a v a  2s  .c  om
 */
public NestedCrmfRequestTestCommand(String[] args) {
    super();

    if (args.length < NR_OF_MANDATORY_ARGS || args.length > MAX_NR_OF_ARGS) {
        usage();
        System.exit(-1); // NOPMD, this is not a JEE app
    }

    hostname = args[ARG_HOSTNAME];
    String certFile = args[ARG_CAFILE];
    createsCertsPath = args.length > ARG_CREATEDCERTSPATH ? args[ARG_CREATEDCERTSPATH] : null;
    port = args.length > ARG_PORT ? Integer.parseInt(args[ARG_PORT].trim()) : 8080;
    urlPath = args.length > ARG_URLPATH && args[ARG_URLPATH].toLowerCase().indexOf("null") < 0
            ? args[ARG_URLPATH].trim()
            : null;

    try {
        cacert = (X509Certificate) this.certificateFactory.generateCertificate(new FileInputStream(certFile));
        final KeyPairGenerator keygen = KeyPairGenerator.getInstance("RSA");
        keygen.initialize(2048);
        popokeys = keygen.generateKeyPair();
    } catch (CertificateException e3) {
        e3.printStackTrace(getPrintStream());
        System.exit(-1);
    } catch (FileNotFoundException e3) {
        e3.printStackTrace(getPrintStream());
        System.exit(-1);
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace(getPrintStream());
        System.exit(-1);
    }

    init(args);

}