code: protected void writeError(final ApiRequest request, final HttpServletResponse resp, final Throwable error) {
          getErrorWriter().write(request, error, new IApiClientResponse() {
              @Override
              public void write(StringBuffer buffer) {
                  write(buffer.toString());
              }
  
              @Override
              public void write(StringBuilder builder) {
                  write(builder.toString());
              }
  
              @Override
              public void write(String body) {
                  try {
                      resp.getOutputStream().write(body.getBytes("UTF-8")); //$NON-NLS-1$
                      resp.getOutputStream().flush();
                  } catch (IOException e) {
                      e.printStackTrace();
                  }
              }
  
              /**
               * @see io.apiman.gateway.engine.IApiClientResponse#setStatusCode(int)
               */
              @Override
              public void setStatusCode(int code) {
                  resp.setStatus(code);
              }
  
              @Override
              public void setHeader(String headerName, String headerValue) {
                  resp.setHeader(headerName, headerValue);
              }
          });
      }
docs: Writes an error to the servlet response object.
  @param request
  @param resp
  @param error