1 // ANNA - Anna is Not 'N' Anymore
3 // (c) Copyright 2005-2014 Eduardo Ramos Testillano & Francisco Ruiz Rayo
5 // https://bitbucket.org/testillano/anna
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions
11 // * Redistributions of source code must retain the above copyright
12 // notice, this list of conditions and the following disclaimer.
13 // * Redistributions in binary form must reproduce the above
14 // copyright notice, this list of conditions and the following disclaimer
15 // in the documentation and/or other materials provided with the
17 // * Neither the name of Google Inc. nor the names of its
18 // contributors may be used to endorse or promote products derived from
19 // this software without specific prior written permission.
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 // Authors: eduardo.ramos.testillano@gmail.com
34 // cisco.tierra@gmail.com
37 #ifndef anna_http_wims20_ClientSide_hpp
38 #define anna_http_wims20_ClientSide_hpp
40 #include <anna/core/functions.hpp>
42 #include <anna/http/wims20/Abstract.hpp>
53 Permite interpretar una URI según las recomendaciones de WIMS 2.0, lo que facilita
54 el desarrollo de aplicaciones integradas en Web 2.0; estas recomendaciones indican
55 cómo debe formarse la petición ClientSide (REpresentational State Transfer) para permitir
56 el desarrollo de cualquier servicio.
58 Implementa el interfaz WIMS 2.0 desde el punto de vista del proceso que genera la petición.
60 El formato general de una URI según la recomendación de WIMS 2.0 es:
63 http://domain-openapis/path-openapis/serviceID/guid/other_possible_levels?query_parameters
66 Dónde los campos tienen siguen la siguiente especificación:
67 \li http://domain-openapis: Identifica el recurso del Open API.
68 \li path-openapis: Recurso opcional que ajusta la ruta hacia los recursos de éste API.
69 \li serviceID: Identificador de recurso.
70 \li guid: Identificador del usuario que solicita la petición.
71 \li other_possible_level: Opcionalmente se pueden indicar tantos niveles jerárquicos como fuera
72 necesario para el servicio.
73 \li query_parameters: Lista de parámetros. Si hay más de un parámetro se separará con '&'.
75 class ClientSide : public Abstract {
78 * Contructor indicando el parámetro opcional \em path-openapis. Estos dos parámetros se obtendrá como
79 * parte de la configuración de nuestro sistema.
80 * \param domain: Identifica el recurso del OpenAPI.
81 * \param path: Parámetro opcional que ajusta la ruta hacia los recusos de éste API.
83 ClientSide(const std::string& domain, const std::string& path) :
84 Abstract("ClientSide", domain, path) {
85 a_strOtherLevels = NULL;
89 * Constructor que no usará el parámetro opcional \em path-openapis. Este parámetro se obtendrá como
90 * parte de la configuración de nuestro sistema.
91 * \param domain: Identifica el recurso del OpenAPI.
93 explicit ClientSide(const std::string& domain) :
94 Abstract("ClientSide", domain) {
95 a_strOtherLevels = NULL;
101 ~ClientSide() { Abstract::destroyString(a_strOtherLevels); }
104 * Amplía el campo \em other_possible_level con el valor recibido.
105 * \param otherLevel Valor con el que ampliar la ruta.
107 void addOtherLevel(const std::string& otherLevel) throw(RuntimeException);
110 * Amplía el campo \em other_possible_level con el valor recibido.
111 * \param otherLevel Valor con el que ampliar la ruta.
113 void addOtherLevel(const char* otherLevel) throw(RuntimeException) {
114 std::string aux(otherLevel);
119 * Establece el valor del parámetro indicado como parámetro. Si el parámetro indicado ya
120 * existe en la lista de parámetros registrados su valor se sobreescribe.
121 * \param parameter Nombre del parámetro a establecer.
122 * \param value Valor asociado al parámetro.
124 void setParameter(const char* parameter, const char* value) throw(RuntimeException) {
125 std::string p(parameter);
126 std::string v(value);
127 Abstract::parameter_set(p, v);
131 * Establece el valor del parámetro indicado como parámetro. Si el parámetro indicado ya
132 * existe en la lista de parámetros registrados su valor se sobreescribe.
133 * \param parameter Nombre del parámetro a establecer.
134 * \param value Valor asociado al parámetro.
136 void setParameter(const char* parameter, const int value) throw(RuntimeException) {
137 std::string p(parameter);
138 Abstract::parameter_set(p, anna::functions::asString(value));
142 * Establece el valor del parámetro indicado como parámetro. Si el parámetro indicado ya
143 * existe en la lista de parámetros registrados su valor se sobreescribe.
144 * \param parameter Nombre del parámetro a establecer.
145 * \param value Valor asociado al parámetro.
147 void setParameter(const std::string& parameter, const std::string& value) throw(RuntimeException) {
148 Abstract::parameter_set(parameter, value);
152 * Establece el valor del parámetro indicado como parámetro. Si el parámetro indicado ya
153 * existe en la lista de parámetros registrados su valor se sobreescribe.
154 * \param parameter Nombre del parámetro a establecer.
155 * \param value Valor asociado al parámetro.
157 void setParameter(const std::string& parameter, const int value) throw(RuntimeException) {
158 Abstract::parameter_set(parameter, anna::functions::asString(value));
162 * Limpia el contenido asociado al parámetro \em other_possible_level. Sólo debería
163 * invocarse a este método en caso de que el servicio destino de la petición haya cambiado.
165 void clearOtherLevels() throw() {
166 Abstract::clearOtherLevels();
167 Abstract::destroyString(a_strOtherLevels);
168 a_strOtherLevels = NULL;
172 * Recopila la información contenida en la petición REST de WIMS2.0 y la
173 * codifica sobre la URI de la petición HTTP recibida como parámetro.
174 * \param message Mensaje HTTP sobre el que se establecerá la URI necesaria para
175 * realizar la peticion WIMS 2.0.
177 void codeOn(http::Request& message) throw(RuntimeException);
180 std::string* a_strOtherLevels;