code: private synchronized void registerVirtualSauceNodeToGrid(HttpServletRequest req, HttpServletResponse resp)
              throws ServletException, IOException {
  
          // Redirecting to login page if session is not found
          if (req.getSession(false) == null) {
              resp.sendRedirect(LoginServlet.class.getSimpleName());
              return;
          }
  
          String respMsg = "Sauce node already registered.";
          if (registered) {
              ServletHelper.respondAsHtmlWithMessage(resp, formatForHtmlTemplate(respMsg));
              LOGGER.info(respMsg);
              return;
          }
  
          HttpClientFactory httpClientFactory = new HttpClientFactory();
          respMsg = "Sauce node registration failed. Please refer to the log file for failure details.";
          try {
              final int port = getRegistry().getHub().getConfiguration().port;
              final URL registration = new URL("http://localhost:" + port + "/grid/register");
  
              BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("POST",
                      registration.toExternalForm());
              request.setEntity(new StringEntity(getRegistrationRequestEntity()));
              HttpHost host = new HttpHost(registration.getHost(), registration.getPort());
              HttpClient client = httpClientFactory.getHttpClient();
              HttpResponse response = client.execute(host, request);
  
              if (response.getStatusLine().getStatusCode() == HttpServletResponse.SC_OK) {
                  respMsg = "Sauce node registered successfully.";
                  registered = true;
              }
          } catch (IOException | GridConfigurationException e) { // We catch the GridConfigurationException here to fail
                                                                 // gracefully
              // TODO Consider retrying on failure
              LOGGER.log(Level.WARNING, "Unable to register sauce node: ", e);
          } finally {
              httpClientFactory.close();
          }
          LOGGER.info(respMsg);
          ServletHelper.respondAsHtmlWithMessage(resp, formatForHtmlTemplate(respMsg));
      }
docs: /*
  A helper method that takes care of registering a virtual node to the hub.