@Override
    public PolicyTestBackEndApiResponse invoke(ApiRequest request, byte[] requestBody) {
        try {
            EchoResponse echoResponse = new EchoResponse();
            if (requestBody != null) {
                echoResponse.setBodyLength(new Long(requestBody.length));
                echoResponse.setBodySha1(DigestUtils.sha1Hex(requestBody));
            }
            echoResponse.setCounter(counter++);
            echoResponse.setHeaders(request.getHeaders());
            echoResponse.setMethod(request.getType());
            echoResponse.setResource(request.getDestination());
            echoResponse.setUri("urn:" + request.getDestination());

            ApiResponse apiResponse = new ApiResponse();

            String errorCode = request.getHeaders().get("X-Echo-ErrorCode");
            if (errorCode != null) {
                int ec = Integer.parseInt(errorCode);
                String errorMsg = request.getHeaders().get("X-Echo-ErrorMessage");
                apiResponse.setCode(ec);
                apiResponse.setMessage(errorMsg);
            } else {
                apiResponse.setCode(200);
                apiResponse.setMessage("OK");
            }
            apiResponse.getHeaders().put("Date", new Date().toString());
            apiResponse.getHeaders().put("Server", "apiman.policy-test");
            apiResponse.getHeaders().put("Content-Type", "application/json");

            String responseBody = normalize(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(echoResponse));
            apiResponse.getHeaders().put("Content-Length", String.valueOf(responseBody.length()));

            PolicyTestBackEndApiResponse response = new PolicyTestBackEndApiResponse(apiResponse, responseBody);
            return response;
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
@see io.apiman.test.policies.IPolicyTestBackEndApi#invoke(io.apiman.gateway.engine.beans.ApiRequest, byte[])
test/policies/src/main/java/io/apiman/test/policies/EchoBackEndApi.java