MCPcopy Create free account
hub / github.com/SeleniumHQ/selenium / DispatchCommand

Method DispatchCommand

cpp/webdriver-server/server.cc:331–428  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

329}
330
331std::string Server::DispatchCommand(const std::string& uri,
332 const std::string& http_verb,
333 const std::string& command_body) {
334 LOG(TRACE) << "Entering Server::DispatchCommand";
335
336 std::string session_id = "";
337 std::string locator_parameters = "";
338 std::string serialized_response = "";
339 std::string command = this->LookupCommand(uri,
340 http_verb,
341 &session_id,
342 &locator_parameters);
343 LOG(DEBUG) << "Command: " << http_verb << " " << uri << " " << command_body;
344
345 if (command == webdriver::CommandType::NoCommand) {
346 Response invalid_command_response;
347 if (locator_parameters.size() > 0) {
348 std::string unknown_method_body = "Invalid method requested: ";
349 unknown_method_body.append(http_verb);
350 unknown_method_body.append(" is not a valid HTTP verb for ");
351 unknown_method_body.append(uri);
352 unknown_method_body.append("; acceptable verbs are: ");
353 unknown_method_body.append(locator_parameters);
354 invalid_command_response.SetErrorResponse(ERROR_UNKNOWN_METHOD,
355 unknown_method_body);
356 invalid_command_response.AddAdditionalData("verbs", locator_parameters);
357 } else {
358 std::string unknown_command_body = "Command not found: ";
359 unknown_command_body.append(http_verb);
360 unknown_command_body.append(" ");
361 unknown_command_body.append(uri);
362 invalid_command_response.SetErrorResponse(ERROR_UNKNOWN_COMMAND,
363 unknown_command_body);
364 }
365 serialized_response = invalid_command_response.Serialize();
366 } else if (command == webdriver::CommandType::Status) {
367 // Status command must be handled by the server, not by the session.
368 serialized_response = this->GetStatus();
369 } else if (command == webdriver::CommandType::GetSessionList) {
370 // GetSessionList command must be handled by the server,
371 // not by the session.
372 serialized_response = this->ListSessions();
373 } else {
374 SessionHandle session_handle;
375 if (command != webdriver::CommandType::NewSession &&
376 !this->LookupSession(session_id, &session_handle)) {
377 if (command == webdriver::CommandType::Quit) {
378 // Calling quit on an invalid session should be a no-op.
379 // Hand-code the response for quit on an invalid (already
380 // quit) session.
381 serialized_response.append("{ \"value\" : null }");
382 } else {
383 Response invalid_session_id_response;
384 std::string invalid_session_message = "session ";
385 invalid_session_message.append(session_id);
386 invalid_session_message.append(" does not exist");
387 invalid_session_id_response.SetErrorResponse(ERROR_INVALID_SESSION_ID,
388 invalid_session_message);

Callers 1

ProcessRequestMethod · 0.95

Calls 15

LookupCommandMethod · 0.95
ListSessionsMethod · 0.95
LookupSessionMethod · 0.95
ShutDownSessionMethod · 0.95
SetErrorResponseMethod · 0.80
AddAdditionalDataMethod · 0.80
GetStatusMethod · 0.80
ExecuteCommandMethod · 0.80
GetSessionIdMethod · 0.80
LOGClass · 0.70
sizeMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected