Mercurial > hg > orthanc
comparison Core/RestApi/RestApi.cpp @ 974:83622b0f544c
refactoring
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 30 Jun 2014 14:44:05 +0200 |
parents | a811bdf8b8eb |
children | c550e99c452b |
comparison
equal
deleted
inserted
replaced
972:2047e6f033bd | 974:83622b0f544c |
---|---|
36 #include <stdlib.h> // To define "_exit()" under Windows | 36 #include <stdlib.h> // To define "_exit()" under Windows |
37 #include <glog/logging.h> | 37 #include <glog/logging.h> |
38 | 38 |
39 namespace Orthanc | 39 namespace Orthanc |
40 { | 40 { |
41 bool RestApi::Call::ParseJsonRequestInternal(Json::Value& result, | |
42 const char* request) | |
43 { | |
44 result.clear(); | |
45 Json::Reader reader; | |
46 return reader.parse(request, result); | |
47 } | |
48 | |
49 | |
50 bool RestApi::GetCall::ParseJsonRequest(Json::Value& result) const | |
51 { | |
52 result.clear(); | |
53 | |
54 for (HttpHandler::Arguments::const_iterator | |
55 it = getArguments_.begin(); it != getArguments_.end(); ++it) | |
56 { | |
57 result[it->first] = it->second; | |
58 } | |
59 | |
60 return true; | |
61 } | |
62 | |
63 | |
64 bool RestApi::IsGetAccepted(const UriComponents& uri) | 41 bool RestApi::IsGetAccepted(const UriComponents& uri) |
65 { | 42 { |
66 for (GetHandlers::const_iterator it = getHandlers_.begin(); | 43 for (GetHandlers::const_iterator it = getHandlers_.begin(); |
67 it != getHandlers_.end(); ++it) | 44 it != getHandlers_.end(); ++it) |
68 { | 45 { |
199 { | 176 { |
200 if (it->first->Match(components, trailing, uri)) | 177 if (it->first->Match(components, trailing, uri)) |
201 { | 178 { |
202 //LOG(INFO) << "REST GET call on: " << Toolbox::FlattenUri(uri); | 179 //LOG(INFO) << "REST GET call on: " << Toolbox::FlattenUri(uri); |
203 ok = true; | 180 ok = true; |
204 GetCall call(restOutput, *this, headers, components, trailing, uri, getArguments); | 181 RestApiGetCall call(restOutput, *this, headers, components, trailing, uri, getArguments); |
205 it->second(call); | 182 it->second(call); |
206 } | 183 } |
207 } | 184 } |
208 } | 185 } |
209 else if (method == HttpMethod_Put) | 186 else if (method == HttpMethod_Put) |
213 { | 190 { |
214 if (it->first->Match(components, trailing, uri)) | 191 if (it->first->Match(components, trailing, uri)) |
215 { | 192 { |
216 //LOG(INFO) << "REST PUT call on: " << Toolbox::FlattenUri(uri); | 193 //LOG(INFO) << "REST PUT call on: " << Toolbox::FlattenUri(uri); |
217 ok = true; | 194 ok = true; |
218 PutCall call(restOutput, *this, headers, components, trailing, uri, postData); | 195 RestApiPutCall call(restOutput, *this, headers, components, trailing, uri, postData); |
219 it->second(call); | 196 it->second(call); |
220 } | 197 } |
221 } | 198 } |
222 } | 199 } |
223 else if (method == HttpMethod_Post) | 200 else if (method == HttpMethod_Post) |
227 { | 204 { |
228 if (it->first->Match(components, trailing, uri)) | 205 if (it->first->Match(components, trailing, uri)) |
229 { | 206 { |
230 //LOG(INFO) << "REST POST call on: " << Toolbox::FlattenUri(uri); | 207 //LOG(INFO) << "REST POST call on: " << Toolbox::FlattenUri(uri); |
231 ok = true; | 208 ok = true; |
232 PostCall call(restOutput, *this, headers, components, trailing, uri, postData); | 209 RestApiPostCall call(restOutput, *this, headers, components, trailing, uri, postData); |
233 it->second(call); | 210 it->second(call); |
234 } | 211 } |
235 } | 212 } |
236 } | 213 } |
237 else if (method == HttpMethod_Delete) | 214 else if (method == HttpMethod_Delete) |
241 { | 218 { |
242 if (it->first->Match(components, trailing, uri)) | 219 if (it->first->Match(components, trailing, uri)) |
243 { | 220 { |
244 //LOG(INFO) << "REST DELETE call on: " << Toolbox::FlattenUri(uri); | 221 //LOG(INFO) << "REST DELETE call on: " << Toolbox::FlattenUri(uri); |
245 ok = true; | 222 ok = true; |
246 DeleteCall call(restOutput, *this, headers, components, trailing, uri); | 223 RestApiDeleteCall call(restOutput, *this, headers, components, trailing, uri); |
247 it->second(call); | 224 it->second(call); |
248 } | 225 } |
249 } | 226 } |
250 } | 227 } |
251 | 228 |
256 output.SendMethodNotAllowedError(GetAcceptedMethods(uri)); | 233 output.SendMethodNotAllowedError(GetAcceptedMethods(uri)); |
257 } | 234 } |
258 } | 235 } |
259 | 236 |
260 void RestApi::Register(const std::string& path, | 237 void RestApi::Register(const std::string& path, |
261 GetHandler handler) | 238 RestApiGetCall::Handler handler) |
262 { | 239 { |
263 getHandlers_.push_back(std::make_pair(new RestApiPath(path), handler)); | 240 getHandlers_.push_back(std::make_pair(new RestApiPath(path), handler)); |
264 } | 241 } |
265 | 242 |
266 void RestApi::Register(const std::string& path, | 243 void RestApi::Register(const std::string& path, |
267 PutHandler handler) | 244 RestApiPutCall::Handler handler) |
268 { | 245 { |
269 putHandlers_.push_back(std::make_pair(new RestApiPath(path), handler)); | 246 putHandlers_.push_back(std::make_pair(new RestApiPath(path), handler)); |
270 } | 247 } |
271 | 248 |
272 void RestApi::Register(const std::string& path, | 249 void RestApi::Register(const std::string& path, |
273 PostHandler handler) | 250 RestApiPostCall::Handler handler) |
274 { | 251 { |
275 postHandlers_.push_back(std::make_pair(new RestApiPath(path), handler)); | 252 postHandlers_.push_back(std::make_pair(new RestApiPath(path), handler)); |
276 } | 253 } |
277 | 254 |
278 void RestApi::Register(const std::string& path, | 255 void RestApi::Register(const std::string& path, |
279 DeleteHandler handler) | 256 RestApiDeleteCall::Handler handler) |
280 { | 257 { |
281 deleteHandlers_.push_back(std::make_pair(new RestApiPath(path), handler)); | 258 deleteHandlers_.push_back(std::make_pair(new RestApiPath(path), handler)); |
282 } | 259 } |
283 } | 260 } |