extern "C" boolean_t am_policy_get_url_resource_root(const char *resourceName, char *resourceRoot, size_t length) { boolean_t status = B_FALSE; const char *func = "am_policy_get_url_resource_root()"; if (resourceRoot != NULL) { try { URL urlObject(resourceName, strlen(resourceName)); std::string root; urlObject.getRootURL(root); // If there is enough room for the URL and the terminating // NUL, then everything is okay. if (root.size() < length) { std::strcpy(resourceRoot, root.c_str()); status = B_TRUE; } } catch(const std::exception &ex) { Log::log(Log::ALL_MODULES, Log::LOG_ERROR, "%s: Exception %s thrown.", func, ex.what()); } catch(...) { Log::log(Log::ALL_MODULES, Log::LOG_ERROR, "%s: Unknown exception thrown.", func); } } return status; }
QJsonObject SeleniumServerHub::exec(QString url, QByteArray rawBody, int method) { m_result = ""; QJsonObject result; QUrl urlObject(m_urlHub + url); QNetworkRequest request(urlObject); QString contentType = "application/json"; QNetworkAccessManager* manager = new QNetworkAccessManager(this); if(method == GET) { m_reply = manager->get(request); } else if(method == POST) { if(rawBody.isEmpty()) { request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); m_reply = manager->post(request, ""); } else { QByteArray postDataSize = QByteArray::number(rawBody.size()); request.setRawHeader("Content-Type", contentType.toLatin1()); request.setRawHeader("Content-Length", postDataSize); m_reply = manager->post(request, rawBody); } } else if(method == DELETE) { m_reply = manager->deleteResource(request); } else { throw (new QueleniumException("Unsupported method", 99)); } connect(m_reply, SIGNAL(readyRead()), SLOT(slotReplyResponse())); connect(m_reply, SIGNAL(error(QNetworkReply::NetworkError)), SLOT(slotReplyError())); connect(m_reply, SIGNAL(finished()), SLOT(slotFinishRequest())); //this loop for synchronize requests QEventLoop loop; connect(m_reply, SIGNAL(error(QNetworkReply::NetworkError)), &loop, SLOT(quit())); connect(m_reply, SIGNAL(error(QNetworkReply::NetworkError)), &loop, SLOT(deleteLater())); connect(m_reply, SIGNAL(finished()), &loop, SLOT(quit())); loop.exec(); if(m_result.trimmed().isEmpty()) { WebDriverException::throwException("Empty reply from server"); } result = QJsonDocument::fromJson(m_result.toUtf8()).object(); if(result["status"].toInt() != ResponseStatusCodes::SUCCESS) { QString message = result["state"].toString(); if(result["value"].isObject() && result["value"].toObject()["message"].isString()) { message = result["value"].toObject()["message"].toString(); } WebDriverException::throwException(message, result["status"].toInt()); } return result; }