List of usage examples for org.bouncycastle.asn1.ocsp OCSPRequest getEncoded
public byte[] getEncoded() throws IOException
From source file:support.revocation.OCSP.java
License:Apache License
/** * Performs the given OCSP request to the given URL * @return the received OCSP response/*from w w w.j a v a2 s . c o m*/ * @param url * @param request * @throws IOException * @throws SocketTimeoutException */ private static OCSPResponse performOCSPRequest(URL url, OCSPRequest request, int timeoutMillis) throws IOException { try { // setup connection URLConnection connection = url.openConnection(); if (timeoutMillis >= 0) { connection.setConnectTimeout(timeoutMillis); connection.setReadTimeout(timeoutMillis); } connection.setRequestProperty("Content-Type", "application/ocsp-request"); connection.setRequestProperty("Accept", "application/ocsp-response"); connection.setDoOutput(true); // send request try (OutputStream stream = connection.getOutputStream(); BufferedOutputStream bufferedStream = new BufferedOutputStream(stream); DataOutputStream dataStream = new DataOutputStream(bufferedStream)) { dataStream.write(request.getEncoded()); } // process HTTP ststus code if (connection instanceof HttpURLConnection && ((HttpURLConnection) connection).getResponseCode() / 100 != 2) throw new FileNotFoundException(url.toString()); // receive response try (InputStream stream = connection.getInputStream(); BufferedInputStream bufferedStream = new BufferedInputStream(stream); ASN1InputStream asn1stream = new ASN1InputStream(bufferedStream)) { return OCSPResponse.getInstance(asn1stream.readObject()); } } catch (ClassCastException | IllegalArgumentException e) { throw new IOException(e); } }