Home / Function/ OCSPResp() — netty Function Reference

OCSPResp() — netty Function Reference

Architecture documentation for the OCSPResp() function in OcspUtils.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  d3c5c4ee_1073_0c54_cefb_39c0c8493c5d["OCSPResp()"]
  08ffedd7_4191_0abc_ea5f_a0e3ce4ff56b["OcspUtils"]
  d3c5c4ee_1073_0c54_cefb_39c0c8493c5d -->|defined in| 08ffedd7_4191_0abc_ea5f_a0e3ce4ff56b
  style d3c5c4ee_1073_0c54_cefb_39c0c8493c5d fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

example/src/main/java/io/netty/example/ocsp/OcspUtils.java lines 117–171

    public static OCSPResp request(URI uri, OCSPReq request, long timeout, TimeUnit unit) throws IOException {
        byte[] encoded = request.getEncoded();

        URL url = uri.toURL();
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        try {
            connection.setConnectTimeout((int) unit.toMillis(timeout));
            connection.setReadTimeout((int) unit.toMillis(timeout));
            connection.setDoOutput(true);
            connection.setDoInput(true);
            connection.setRequestMethod("POST");
            connection.setRequestProperty("host", uri.getHost());
            connection.setRequestProperty("content-type", OCSP_REQUEST_TYPE);
            connection.setRequestProperty("accept", OCSP_RESPONSE_TYPE);
            connection.setRequestProperty("content-length", String.valueOf(encoded.length));

            try (OutputStream out = connection.getOutputStream()) {
                out.write(encoded);
                out.flush();

                try (InputStream in = connection.getInputStream()) {
                    int code = connection.getResponseCode();
                    if (code != HttpsURLConnection.HTTP_OK) {
                        throw new IOException("Unexpected status-code=" + code);
                    }

                    String contentType = connection.getContentType();
                    if (!contentType.equalsIgnoreCase(OCSP_RESPONSE_TYPE)) {
                        throw new IOException("Unexpected content-type=" + contentType);
                    }

                    int contentLength = connection.getContentLength();
                    if (contentLength == -1) {
                        // Probably a terrible idea!
                        contentLength = Integer.MAX_VALUE;
                    }

                    ByteArrayOutputStream baos = new ByteArrayOutputStream();
                    byte[] buffer = new byte[8192];
                    int length;

                    while ((length = in.read(buffer)) != -1) {
                        baos.write(buffer, 0, length);

                        if (baos.size() >= contentLength) {
                            break;
                        }
                    }
                    return new OCSPResp(baos.toByteArray());
                }
            }
        } finally {
            connection.disconnect();
        }
    }

Domain

Subdomains

Frequently Asked Questions

What does OCSPResp() do?
OCSPResp() is a function in the netty codebase, defined in example/src/main/java/io/netty/example/ocsp/OcspUtils.java.
Where is OCSPResp() defined?
OCSPResp() is defined in example/src/main/java/io/netty/example/ocsp/OcspUtils.java at line 117.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free