Esempio n. 1
0
void
tws::wtss::time_series_functor::operator()(const tws::core::http_request& request,
                                           tws::core::http_response& response)
{
// get client query string
  const char* qstring = request.query_string();

  if(qstring == nullptr)
    throw tws::core::http_request_error() << tws::error_description("time_series operation requires the following parameters: \"coverage\", \"attributes\", \"latitude\", \"longitude\", \"start\", \"end\".");

// parse plain text query string to a std::map
  tws::core::query_string_t qstr = tws::core::expand(qstring);

// parse parameters to a struct
  timeseries_request_parameters parameters = tws::wtss::decode_timeseries_request(qstr);

// valid parameters
  timeseries_validated_parameters vparameters = valid(parameters);

// prepare the JSON root document
  rapidjson::Document::AllocatorType allocator;

  rapidjson::Value jattributes(rapidjson::kArrayType);

// compute timeseries for queried coverage attributes
  compute_time_series(parameters, vparameters, allocator, jattributes);

// prepare the return document
  rapidjson::Document doc;

  doc.SetObject();

  prepare_timeseries_response(parameters, vparameters, doc, jattributes, allocator);

// send response
  rapidjson::StringBuffer str_buff;

  rapidjson::Writer<rapidjson::StringBuffer> writer(str_buff);

  doc.Accept(writer);

  const char* p_str_buff = str_buff.GetString();

  //response.add_header("Content-Length", boost::lexical_cast<std::string>(content.size()).c_str());
  response.add_header("Content-Type", "application/json");
  response.add_header("Access-Control-Allow-Origin", "*");
  response.set_content(p_str_buff, str_buff.Size());
}
Esempio n. 2
0
void
tws::wtss::describe_coverage_functor::operator()(const tws::core::http_request& request,
                                                 tws::core::http_response& response)
{
  const char* qstring = request.query_string();

  if(qstring == nullptr)
    throw tws::core::http_request_error() << tws::error_description("describe_coverage operation requires the parameter: \"name\".");

  tws::core::query_string_t qstr = tws::core::expand(qstring);

// which coverage?
  tws::core::query_string_t::const_iterator it = qstr.find("name");
  tws::core::query_string_t::const_iterator it_end = qstr.end();

  if(it == it_end)
    throw tws::core::http_request_error() << tws::error_description("check describe_coverage operation: \"name\" parameter is missing!");

// retrieve the coverage
  const tws::geoarray::geoarray_t& cv = tws::geoarray::geoarray_manager::instance().get(it->second);

// output result: JSON document
  rapidjson::Document::AllocatorType allocator;

  rapidjson::Document doc;

  doc.SetObject();

  write(cv, doc, allocator);

  rapidjson::StringBuffer str_buff;

  rapidjson::Writer<rapidjson::StringBuffer> writer(str_buff);

  doc.Accept(writer);

  const char* p_str_buff = str_buff.GetString();

  response.add_header("Content-Type", "application/json");
  response.add_header("Access-Control-Allow-Origin", "*");
  response.set_content(p_str_buff, str_buff.Size());
}
Esempio n. 3
0
bool tws::wcs::validate_request_parameters(const tws::core::http_request &request, const tws::core::http_response &response, const std::string &operation)
{
  const char* query_string = request.query_string().c_str();
  if (query_string == nullptr)
  {
    // TODO: wcs xml exception
    throw tws::missing_argument_error() << tws::error_description("Arguments missing. OGC services requires at least three arguments: \"service\", \"version\" e \"request\"");
  }

  tws::core::query_string_t arguments = tws::core::expand(query_string);

  // Service Validation
  const auto& coverage_id = arguments.find("service");
  if (coverage_id == arguments.end())
    throw tws::missing_argument_error() << tws::error_description("Missing \"coverageID\" argument");

  if (coverage_id->second != "WCS")
    throw tws::invalid_argument_error() << tws::error_description("Invalid parameter \"service\" value. It should be \"WCS\"");

  // Version Validation
  const auto& version = arguments.find("version");
  if (version == arguments.end())
    throw tws::missing_argument_error() << tws::error_description("Missing \"version\" argument");

  if (version->second != "2.0.1" && version->second != "2.0")
    throw tws::invalid_argument_error() << tws::error_description("Invalid parameter \"version\" value. It should be \"2.0\"");

  // Request Validation
  const auto& request_param = arguments.find("request");
  if (request_param == arguments.end())
    throw tws::missing_argument_error() << tws::error_description("Missing \"request\" argument");

  if (request_param->second != operation)
    throw tws::invalid_argument_error() << tws::error_description("Invalid parameter \"request\" value.");

  return false;
}