code: static void writeResponse(Configuration conf, Writer out, String format)
      throws IOException, BadFormatException {
      if (FORMAT_JSON.equals(format)) {
        Configuration.dumpConfiguration(conf, out);
      } else if (FORMAT_XML.equals(format)) {
        conf.writeXml(out);
      } else {
        throw new BadFormatException("Bad format: " + format);
      }
    }
docs: Guts of the servlet - extracted for easy testing.