Example usage for com.itextpdf.text.error_messages MessageLocalization getComposedMessage

List of usage examples for com.itextpdf.text.error_messages MessageLocalization getComposedMessage

Introduction

In this page you can find the example usage for com.itextpdf.text.error_messages MessageLocalization getComposedMessage.

Prototype

public static String getComposedMessage(final String key, final Object... param) 

Source Link

Document

Get a message with param.length parameters or none if param is null.

Usage

From source file:controller.CCInstance.java

License:Open Source License

private OCSPResp getOcspResponse(X509Certificate checkCert, X509Certificate rootCert)
        throws GeneralSecurityException, OCSPException, IOException, OperatorException {
    if (checkCert == null || rootCert == null) {
        return null;
    }//from w  w w.j a va 2s. c om
    String url = CertificateUtil.getOCSPURL(checkCert);

    if (url == null) {
        return null;
    }
    try {
        OCSPReq request = generateOCSPRequest(rootCert, checkCert.getSerialNumber());
        byte[] array = request.getEncoded();
        URL urlt = new URL(url);
        HttpURLConnection con = (HttpURLConnection) urlt.openConnection();
        con.setRequestProperty("Content-Type", "application/ocsp-request");
        con.setRequestProperty("Accept", "application/ocsp-response");
        con.setDoOutput(true);

        OutputStream out = con.getOutputStream();
        try (DataOutputStream dataOut = new DataOutputStream(new BufferedOutputStream(out))) {
            dataOut.write(array);
            dataOut.flush();
        }

        if (con.getResponseCode() / 100 != 2) {
            throw new IOException(
                    MessageLocalization.getComposedMessage("invalid.http.response.1", con.getResponseCode()));
        }
        //Get Response
        InputStream in = (InputStream) con.getContent();
        return new OCSPResp(in);
    } catch (Exception e) {
        return null;
    }
}