protected void doGet()

in runtime/testapps/src/main/java/com/google/apphosting/loadtesting/allinone/MainServlet.java [214:422]


  protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException,
      IOException {
    validateParameters(req);
    // In silent mode, regular response output is suppressed and a single "OK"
    // string is printed if all actions ran successfully.
    boolean silent = req.getParameter("silent") != null;
    resp.setContentType("text/plain");
    PrintWriter responseWriter = resp.getWriter();
    PrintWriter w = (silent ? new PrintWriter(new StringWriter()) : responseWriter);
    // These options are also present in the python allinone application, sometimes
    // with slightly different names, e.g. "queries" vs "datastore_queries".
    Integer mathMsParam = getIntParameter("math_ms", req);
    if (mathMsParam != null) {
      performMathMs(mathMsParam, w);
    }
    Integer mathLoopsParam = getIntParameter("math_loops", req);
    if (mathLoopsParam != null) {
      performMathLoops(mathLoopsParam, w);
    }
    Integer memcacheLoopsParam = getIntParameter("memcache_loops", req);
    if (memcacheLoopsParam != null) {
      Integer size = getIntParameter("memcache_size", req);
      performMemcacheLoops(memcacheLoopsParam, size, w);
    }
    Integer logLinesParam = getIntParameter("log_lines", req);
    if (logLinesParam != null) {
      performLogging(logLinesParam, w);
    }
    if (req.getParameter("log_flush") != null) {
      performLogFlush(w);
    }
    Integer responseSizeParam = getIntParameter("response_size", req);
    if (responseSizeParam != null) {
      performResponseSize(responseSizeParam, w);
    }
    Integer queriesParam = getIntParameter("datastore_queries", req);
    if (queriesParam != null) {
      performQueries(queriesParam, w);
    }
    Integer entitiesParam = getIntParameter("datastore_entities", req);
    if (entitiesParam != null) {
      HttpSession s = req.getSession(true);
      s.setAttribute("storedsession", "sessiondata");
      performAddEntities(entitiesParam, w);
    }
    if (req.getParameter("datastore_count") != null) {
      HttpSession s = req.getSession(true);
      if (!"sessiondata".equals(s.getAttribute("storedsession"))) {
        emitf(w, "Java session NOT working");
      } else {
        performCount(w);
      }
    }
    if (req.getParameter("datastore_cron") != null) {
      performCron(req.getRequestURI(), w);
    }
    if (req.getParameter("user") != null) {
      performUserLogin(w, req.getRequestURI(), req.getUserPrincipal());
    }
    String urlParam = req.getParameter("fetch_url");
    if (urlParam != null) {
      performUrlFetch(w, urlParam);
    }
    String urlParam2 = req.getParameter("fetch_url_using_httpurlconnection");
    if (urlParam2 != null) {
      performUrlFetchUsingHttpURLConnection(w, urlParam2);
    }
    // These options are Java-specific.
    Integer randomResponseSizeParam = getIntParameter("random_response_size", req);
    if (randomResponseSizeParam != null) {
      performRandomResponseSize(randomResponseSizeParam, w);
    }
    boolean pinByteBuffers = (req.getParameter("pin_byte_buffer") != null);
    Integer byteBufferSizeParam = getIntParameter("byte_buffer_size", req);
    if (byteBufferSizeParam != null) {
      ByteBuffer b = performByteBufferAllocation(byteBufferSizeParam, false, w);
      if (pinByteBuffers) {
        emit(w, "Pinned buffer");
        PINNED_BUFFERS.add(b);
      }
    }
    Integer directByteBufferSizeParam = getIntParameter("direct_byte_buffer_size", req);
    if (directByteBufferSizeParam != null) {
      ByteBuffer b = performByteBufferAllocation(directByteBufferSizeParam, true, w);
      if (pinByteBuffers) {
        emit(w, "Pinned buffer");
        PINNED_BUFFERS.add(b);
      }
    }
    if (req.getParameter("clear_pinned_buffers") != null) {
      emit(w, "Cleared pinner buffers");
      PINNED_BUFFERS.clear();
    }
    if (req.getParameter("list_system_properties") != null) {
      performListSystemProperties(w);
    }
    String sysPropName = req.getParameter("get_system_property");
    if (sysPropName != null) {
      emit(w, System.getProperty(sysPropName));
    }
    if (req.getParameter("list_environment") != null) {
      performListEnvironment(w);
    }
    String envVarName = req.getParameter("get_environment");
    if (envVarName != null) {
      emit(w, System.getenv(envVarName));
    }
    String headerName = req.getParameter("get_header");
    if (headerName != null) {
      emit(w, req.getHeader(headerName));
    }
    if (req.getParameter("list_attributes") != null) {
      performListAttributes(w);
    }
    String attrName = req.getParameter("get_attribute");
    if (attrName != null) {
      emit(w, String.valueOf(ApiProxy.getCurrentEnvironment().getAttributes().get(attrName)));
    }
    String servletAttributeString = req.getParameter("set_servlet_attributes");
    if (servletAttributeString != null) {
      performSetServletAttributes(req, servletAttributeString, w);
    }
    String dispatcherName = req.getParameter("get_named_dispatcher");
    if (dispatcherName != null) {
       emitf(w, "%s", context.getNamedDispatcher(dispatcherName));
    }
    if (req.getParameter("fetch_project_id_from_metadata") != null) {
      performFetchProjectIdFromMetadata(w);
    }
    if (req.getParameter("fetch_service_account_token_from_metadata") != null) {
      performFetchServiceAccountTokenFromMetadata(w);
    }
    if (req.getParameter("fetch_service_account_scopes_from_metadata") != null) {
      performFetchServiceAccountScopesFromMetadata(w);
    }
    if (req.getParameter("log_remaining_time") != null) {
      performLogRemainingTime(w);
    }
    if (req.getParameter("deferred_task") != null) {
      performAddDeferredTask(w);
    }
    if (req.getParameter("deferred_task_verify") != null) {
      performVerifyDeferredTask(w);
    }
    Integer tasksParam = getIntParameter("add_tasks", req);
    if (tasksParam != null) {
      String taskUrl = req.getParameter("task_url");
      performAddTasks(tasksParam, taskUrl, w);
    }
    String dbParam = req.getParameter("sql_db");
    if (dbParam != null) {
      Integer timeout = getIntParameter("sql_timeout", req);
      Integer rows = getIntParameter("sql_rows", req);
      Integer columns = getIntParameter("sql_columns", req);
      Integer len = getIntParameter("sql_len", req);
      boolean replace = req.getParameter("sql_replace") != null;
      performCloudSqlAccess(dbParam, (rows != null ? rows : 10),
          (columns != null ? columns : 1), (len != null ? len : 10),
          (timeout != null ? timeout : 0), replace, w);
    }
    /*
    // The spanner functionality is commented out because it results
    // in one version violations.
    String spannerId = req.getParameter("spanner_id");
    if (spannerId != null) {
      String spannerDb = req.getParameter("spanner_db");
      performSpannerAccess(spannerId, spannerDb, w);
    }
    */
    String awtText = req.getParameter("awt_text");
    if (awtText != null) {
      performAwtTextRendering(awtText, w);
    }
    if (req.getParameter("oom") != null) {
      throw new OutOfMemoryError("intentional termination");
    }
    if (req.getParameter("jmx_info") != null) {
      performJmxInfo(w);
    }
    if (req.getParameter("jmx_list_vm_options") != null) {
      performJmxListVmOptions(w);
    }
    if (req.getParameter("jmx_thread_dump") != null) {
      performJmxThreadDump(w);
    }
    String metadataURL = req.getParameter("get_metadata");
    if (metadataURL != null) {
      emit(w, fetchMetadata(new URL(metadataURL)));
    }
    if (req.getParameter("list_headers") != null) {
      performListHeaders(req, w);
    }
    if (req.getParameter("list_processes") != null) {
      performListProcesses(w);
    }
    if (req.getParameter("validate_fs") != null) {
      performReadOnlyFSCheck(w);
    }
    String forward = req.getParameter("forward");
    if (forward != null && req.getAttribute("forwarded") == null) {
      req.setAttribute("forwarded", true);
      RequestDispatcher dispatcher = req.getRequestDispatcher("/?" + forward);
      dispatcher.forward(req, resp);
    }
    w.flush();
    if (silent) {
      responseWriter.println("OK");
    }
  }