code: @Override
      protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  
          ApplicationProcessor applicationProcessor = ApplicationProcessor.getInstance();
  
          if (request.getMethod().equals(Constants.METHOD_GET)) {
              if (applicationProcessor == null) {
                  Writer writer = response.getWriter();
                  writer.write("Failed to find OpenAPI application processor");
                  response.setStatus(404);
              }
  
              String acceptHeader = "";
              acceptHeader = request.getHeader(Constants.ACCEPT_HEADER);
              String format = "yaml";
              if (acceptHeader != null && acceptHeader.equals(MediaType.APPLICATION_JSON)) {
                  format = "json";
              }
              String formatParam = request.getParameter("format");
              if (formatParam != null && formatParam.equals("json")) {
                  format = "json";
              }
  
              response.setCharacterEncoding("UTF-8");
              if (format.equals("json")) {
                  String document = applicationProcessor.getOpenAPIDocument(request, DocType.JSON);
                  if (document != null) {
                      response.setContentType(MediaType.APPLICATION_JSON);
                      Writer writer = response.getWriter();
                      writer.write(document);
                  } else {
                      if (OpenAPIUtils.isEventEnabled(tc)) {
                          Tr.event(this, tc, "Null document (json). Return 500.");
                      }
                      response.setStatus(500);
                  }
              } else {
                  String document = applicationProcessor.getOpenAPIDocument(request, DocType.YAML);
                  if (document != null) {
                      response.setContentType(MediaType.TEXT_PLAIN);
                      Writer writer = response.getWriter();
                      writer.write(document);
                  } else {
                      if (OpenAPIUtils.isEventEnabled(tc)) {
                          Tr.event(this, tc, "Null document (yaml). Return 500.");
                      }
                      response.setStatus(500);
                  }
              }
          } else {
              if (OpenAPIUtils.isEventEnabled(tc)) {
                  Tr.event(this, tc, "Invalid method. Return 405.");
              }
              response.setStatus(405);
          }
  
      }
docs: {@inheritDoc}