Esempio n. 1
0
void FakeHSSConnection::set_impu_result(const std::string& impu,
                                        const std::string& type,
                                        const std::string& state,
                                        std::string subxml,
                                        std::string extra_params)
{
  std::string url = "/impu/" + Utils::url_escape(impu) + "/reg-data" + extra_params;

  if (subxml.empty())
  {
    subxml = ("<IMSSubscription><ServiceProfile>\n"
              "<PublicIdentity><Identity>"+impu+"</Identity></PublicIdentity>"
              "  <InitialFilterCriteria>\n"
              "  </InitialFilterCriteria>\n"
              "</ServiceProfile></IMSSubscription>");
  }

  std::string chargingaddrsxml = ("<ChargingAddresses>\n"
                                  "  <CCF priority=\"1\">ccf1</CCF>\n"
                                  "  <ECF priority=\"1\">ecf1</ECF>\n"
                                  "  <ECF priority=\"2\">ecf2</ECF>\n"
                                  "</ChargingAddresses>");

  std::string result = ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
                        "<ClearwaterRegData><RegistrationState>" + state + "</RegistrationState>"
                        + subxml + chargingaddrsxml + "</ClearwaterRegData>");

  _results[UrlBody(url, (type.empty() ? "" : "{\"reqtype\": \""+type+"\"}"))] = result;
}
Esempio n. 2
0
long FakeHSSConnection::get_xml_object(const std::string& path,
                                       std::string body,
                                       rapidxml::xml_document<>*& root,
                                       SAS::TrailId trail)
{
  _calls.insert(UrlBody(path, body));
  HTTPCode http_code = HTTP_NOT_FOUND;

  std::map<UrlBody, std::string>::const_iterator i = _results.find(UrlBody(path, body));

  if (i != _results.end())
  {
    root = new rapidxml::xml_document<>;
    try
    {
      root->parse<0>(root->allocate_string(i->second.c_str()));
      http_code = HTTP_OK;
    }
    catch (rapidxml::parse_error& err)
    {
      // report to the user the failure and their locations in the document.
      printf("Failed to parse Homestead response:\n %s\n %s\n %s\n",
             path.c_str(),
             i->second.c_str(),
             err.what());
      LOG_ERROR("Failed to parse Homestead response:\n %s\n %s\n %s\n",
                path.c_str(),
                i->second.c_str(),
                err.what());
      delete root;
      root = NULL;
    }
  }
  else
  {
    LOG_ERROR("Failed to find XML result for URL %s", path.c_str());
  }

  std::map<std::string, long>::const_iterator i2 = _rcs.find(path);
  if (i2 != _rcs.end())
  {
    http_code = i2->second;
  }

  return http_code;
}
Esempio n. 3
0
long FakeHSSConnection::get_json_object(const std::string& path,
                                        Json::Value*& object,
                                        SAS::TrailId trail)
{
  _calls.insert(UrlBody(path, ""));
  HTTPCode http_code = HTTP_NOT_FOUND;

  std::map<UrlBody, std::string>::const_iterator i = _results.find(UrlBody(path, ""));

  if (i != _results.end())
  {
    object = new Json::Value;
    Json::Reader reader;
    LOG_DEBUG("Found HSS data for %s\n%s", path.c_str(), i->second.c_str());
    bool parsingSuccessful = reader.parse(i->second, *object);
    if (parsingSuccessful)
    {
      http_code = HTTP_OK;
    }
    else
    {
      // report to the user the failure and their locations in the document.
      LOG_ERROR("Failed to parse Homestead response:\n %s\n %s\n %s\n",
                path.c_str(),
                i->second.c_str(),
                reader.getFormatedErrorMessages().c_str());
      delete object;
      object = NULL;
    }
  }
  else
  {
    LOG_DEBUG("Failed to find JSON result for URL %s", path.c_str());
  }

  std::map<std::string, long>::const_iterator i2 = _rcs.find(path);
  if (i2 != _rcs.end())
  {
    http_code = i2->second;
  }

  return http_code;
}
Esempio n. 4
0
void FakeHSSConnection::delete_result(const std::string& url)
{
  _results.erase(UrlBody(url, ""));
}
Esempio n. 5
0
void FakeHSSConnection::set_result(const std::string& url,
                                   const std::string& result)
{
  _results[UrlBody(url, "")] = result;
}
Esempio n. 6
0
bool FakeHSSConnection::url_was_requested(const std::string& url, const std::string& body)
{
  return (_calls.find(UrlBody(url, body)) != _calls.end());
}