Remove dynamic exceptions
[anna.git] / source / http / wims20 / ClientSide.cpp
1 // ANNA - Anna is Not Nothingness Anymore                                                         //
2 //                                                                                                //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo                         //
4 //                                                                                                //
5 // See project site at http://redmine.teslayout.com/projects/anna-suite                           //
6 // See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
7
8
9 #include <anna/core/tracing/Logger.hpp>
10
11 #include <anna/http/wims20/ClientSide.hpp>
12
13 #include <anna/http/Request.hpp>
14
15 using namespace std;
16 using namespace anna;
17
18 /*
19  * Los niveles parece que serán bastante estables, así que nos ahorramos calcular toda su ruta
20  * cada vez que tengamos que calcular la URI.
21  */
22 void http::wims20::ClientSide::addOtherLevel(const std::string& otherLevel)
23 noexcept(false) {
24   if(a_strOtherLevels == NULL)
25     a_strOtherLevels = Abstract::createString(otherLevel);
26   else {
27     *a_strOtherLevels += '/';
28     *a_strOtherLevels += otherLevel;
29   }
30
31   Abstract::other_level_add(otherLevel);
32 }
33
34 /*
35    http://domain-openapis/path-openapis/serviceID/guid/other_possible_levels?query_parameters
36
37    Dónde los campos tienen siguen la siguiente especificación:
38    \li http://domain-openapis: Identifica el recurso del Open API.
39    \li path-openapis: Recurso opcional que ajusta la ruta hacia los recursos de éste API.
40    \li serviceID: Identificador de recurso.
41    \li guid: Identificador del usuario que solicita la petición.
42    \li other_possible_level: Opcionalmente se pueden indicar tantos niveles jerárquicos como fuera
43    necesario para el servicio.
44    \li query_parameters: Lista de parámetros. Si hay más de un parámetro se separará con '&'.
45  */
46 void http::wims20::ClientSide::codeOn(http::Request& request)
47 noexcept(false) {
48   a_uri = Abstract::calculeFixedPart();
49
50   if(Abstract::hasOtherLevels())
51     Abstract::appendWithSlash(a_uri, *a_strOtherLevels);
52
53   if(Abstract::hasParameters()) {
54     a_uri += '?';
55     bool first = true;
56
57     for(parameter_iterator ii = parameter_begin(), maxii = parameter_end(); ii != maxii; ii ++) {
58       if(first == false)
59         a_uri += '&';
60
61       a_uri += *Abstract::parameter_name(ii);
62       a_uri += '=';
63       a_uri += *Abstract::parameter_value(ii);
64       first = false;
65     }
66   }
67
68   LOGDEBUG(
69     string msg("http::wims20::ServerSide::codeOn | ");
70     msg += asString();
71     msg += " | Result (URI): ";
72     msg += a_uri;
73     Logger::debug(msg, ANNA_FILE_LOCATION);
74   );
75   request.setURI(a_uri);
76 }