class StubResponseWriter {

    public void writeResponse(final HttpServletRequest req, final HttpServletResponse resp) throws IOException {
        //response generator to create response
        byte[] responseBody = stubResponseGenerator.generateResponse(req, resp);
        if (responseBody != null) {
            //call StubResponseProcessor to compress response body to the appropriate format
            responseBody = stubResponseProcessor.processResponse(req, resp, responseBody);
            //write response to servlet response's output stream
            writeResponseToOutputStream(resp, responseBody);
        } else {
            writeErrorResponse(resp);
            logger.warn("Wilma has got an unwanted request from this address: " + req.getRemoteAddr());
        }
    }

}