@Override
    public void handle(final ClassicHttpRequest request,
                       final ClassicHttpResponse response,
                       final HttpContext context)
        throws HttpException, IOException {

        final String method = request.getMethod();
        if (!"GET".equalsIgnoreCase(method) &&
                !"HEAD".equalsIgnoreCase(method) &&
                !"POST".equalsIgnoreCase(method) &&
                !"PUT".equalsIgnoreCase(method)) {
            throw new MethodNotSupportedException(method + " not supported by " + getClass().getName());
        }
        final URI uri;
        try {
            uri = request.getUri();
        } catch (final URISyntaxException ex) {
            throw new ProtocolException(ex.getMessage(), ex);
        }
        final String path = uri.getPath();
        final int slash = path.lastIndexOf('/');
        if (slash != -1) {
            final String payload = path.substring(slash + 1);
            final long n;
            if (!payload.isEmpty()) {
                try {
                    n = Long.parseLong(payload);
                } catch (final NumberFormatException ex) {
                    throw new ProtocolException("Invalid request path: " + path);
                }
            } else {
                // random length, but make sure at least something is sent
                n = 1 + (int)(Math.random() * 79.0);
            }
            response.setCode(HttpStatus.SC_OK);
            response.setEntity(new RandomEntity(n));
        } else {
            throw new ProtocolException("Invalid request path: " + path);
        }
    }
Handles a request by generating random data.
The length of the response can be specified in the request URI
as a number after the last /. For example /random/whatever/20
will generate 20 random bytes in the printable ASCII range.
If the request URI ends with /, a random number of random bytes
is generated, but at least one.

@param request   the request
@param response  the response
@param context   the context

@throws HttpException    in case of a problem
@throws IOException      in case of an IO problem
httpclient5-testing/src/main/java/org/apache/hc/client5/testing/classic/RandomHandler.java