private void _handle(HttpServerRequest req) {
            HttpServerResponse rep = req.response();

            if (req.headers().contains("X-Echo-ErrorCode")) {
                // Check if number, if not then set to 400.
                int errorCode = Optional.of(req.getHeader("X-Echo-ErrorCode"))
                        .filter(NumberUtils::isNumber)
                        .map(Integer::valueOf)
                        .orElse(400);
                // Get error message, else set to "" to avoid NPE.
                String statusMsg = Optional.ofNullable(req.getHeader("X-Echo-ErrorMessage"))
                            .orElse("");
                // #end writes and flushes the response.
                rep.setStatusCode(errorCode)
                   .setStatusMessage(statusMsg)
                   .end();
                return;
            }

            // If redirect query param set, do a 302.
            String query = req.query();
            if (query != null && query.startsWith("redirectTo=")) {
                String redirectTo = query.substring(11);
                rep.putHeader("Location", redirectTo)
                    .setStatusCode(302)
                    .end();
                return;
            }

            // Determine if explicitly needs XML (else, use JSON).
            boolean isXml = Optional.of(req.getHeader("Accept"))
                .filter(accept -> accept.contains("application/xml"))
                .map(accept -> !(accept.contains("application/json")))
                .orElse(false);

            // Build response
            EchoResponse echo = new EchoResponse();
            echo.setMethod(req.method().toString());
            echo.setResource(normaliseResource(req));
            echo.setUri(req.path());

            req.handler(body -> {
                sha1.update(body.getBytes());
                bodyLength += body.length();
            }).endHandler(end -> {
                // If any body was present, encode digest as Base64.
                if (bodyLength > 0) {
                    echo.setBodyLength(bodyLength);
                    echo.setBodySha1(Base64.getEncoder().encodeToString(sha1.digest()));
                }
                echo.setCounter(++counter);
                echo.setHeaders(multimapToMap(req.headers()));
                rep.putHeader("Response-Counter", echo.getCounter().toString());
                rep.setChunked(true);
                if (isXml) { // XML
                    rep.putHeader("Content-Type", "application/xml");
                    writeXmlAndEnd(rep, echo);
                } else { // JSON
                    rep.putHeader("Content-Type", "application/json");
                    writeJsonAndEnd(rep, echo);
                }
            });
        }
<p>
Vert.x edition of Echo servlet, with view to being more amenable
to performance testing.
</p>
<p>
Can be run directly with: <tt>vertx run EchoServerVertx.java</tt>
</p>
<p>
To set port, use the property -Dio.apiman.test.common.echo.port=1234
</p>

@author Marc Savy {@literal <marc@rhymewithgravy.com>}
test/common/src/main/java/io/apiman/test/common/echo/EchoServerVertx.java