@Override
  public void commence(HttpServletRequest req, HttpServletResponse res, AuthenticationException e)
      throws IOException, ServletException {

    res.setContentType(MediaType.APPLICATION_JSON_VALUE);
    Result<Map<String, Object>> result = new Result<Map<String, Object>>();
    Meta meta = new Meta();
    meta.setMessage(e.getMessage());
    meta.setStatus(HttpStatus.UNAUTHORIZED);
    ErrorInfo errorInfo =
        new ErrorInfo(
            e.getMessage(),
            Integer.toString(org.apache.commons.httpclient.HttpStatus.SC_UNAUTHORIZED));
    meta.setErrorInfo(errorInfo);
    result.setMeta(meta);

    PrintWriter out = res.getWriter();

    ObjectMapper mapper = new ObjectMapper();
    mapper.setSerializationInclusion(Include.NON_EMPTY);
    out.print(mapper.writeValueAsString(result));
    out.close();
  }