Mercurial > hg > orthanc
comparison Core/RestApi/RestApi.cpp @ 210:96b7918a6a18
start of the refactoring of the Orthanc REST API
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 28 Nov 2012 18:03:44 +0100 |
parents | 9960642f0f45 |
children | c07170f3f4f7 |
comparison
equal
deleted
inserted
replaced
209:9960642f0f45 | 210:96b7918a6a18 |
---|---|
30 **/ | 30 **/ |
31 | 31 |
32 | 32 |
33 #include "RestApi.h" | 33 #include "RestApi.h" |
34 | 34 |
35 #include <glog/logging.h> | |
36 | |
35 namespace Orthanc | 37 namespace Orthanc |
36 { | 38 { |
37 bool RestApi::IsGetAccepted(const UriComponents& uri) | 39 bool RestApi::IsGetAccepted(const UriComponents& uri) |
38 { | 40 { |
39 for (GetHandlers::const_iterator it = getHandlers_.begin(); | 41 for (GetHandlers::const_iterator it = getHandlers_.begin(); |
162 { | 164 { |
163 bool ok = false; | 165 bool ok = false; |
164 RestApiOutput restOutput(output); | 166 RestApiOutput restOutput(output); |
165 RestApiPath::Components components; | 167 RestApiPath::Components components; |
166 UriComponents trailing; | 168 UriComponents trailing; |
167 | 169 |
168 if (method == "GET") | 170 if (method == "GET") |
169 { | 171 { |
170 for (GetHandlers::const_iterator it = getHandlers_.begin(); | 172 for (GetHandlers::const_iterator it = getHandlers_.begin(); |
171 it != getHandlers_.end(); it++) | 173 it != getHandlers_.end(); it++) |
172 { | 174 { |
173 if (it->first->Match(components, trailing, uri)) | 175 if (it->first->Match(components, trailing, uri)) |
174 { | 176 { |
177 LOG(INFO) << "REST GET call on: " << Toolbox::FlattenUri(uri); | |
175 ok = true; | 178 ok = true; |
176 GetCall call; | 179 GetCall call; |
177 call.output_ = &restOutput; | 180 call.output_ = &restOutput; |
178 call.context_ = context_.get(); | 181 call.context_ = this; |
179 call.httpHeaders_ = &headers; | 182 call.httpHeaders_ = &headers; |
180 call.uriComponents_ = &components; | 183 call.uriComponents_ = &components; |
181 call.trailing_ = &trailing; | 184 call.trailing_ = &trailing; |
182 | 185 |
183 call.getArguments_ = &getArguments; | 186 call.getArguments_ = &getArguments; |
190 for (PutHandlers::const_iterator it = putHandlers_.begin(); | 193 for (PutHandlers::const_iterator it = putHandlers_.begin(); |
191 it != putHandlers_.end(); it++) | 194 it != putHandlers_.end(); it++) |
192 { | 195 { |
193 if (it->first->Match(components, trailing, uri)) | 196 if (it->first->Match(components, trailing, uri)) |
194 { | 197 { |
198 LOG(INFO) << "REST PUT call on: " << Toolbox::FlattenUri(uri); | |
195 ok = true; | 199 ok = true; |
196 PutCall call; | 200 PutCall call; |
197 call.output_ = &restOutput; | 201 call.output_ = &restOutput; |
198 call.context_ = context_.get(); | 202 call.context_ = this; |
199 call.httpHeaders_ = &headers; | 203 call.httpHeaders_ = &headers; |
200 call.uriComponents_ = &components; | 204 call.uriComponents_ = &components; |
201 call.trailing_ = &trailing; | 205 call.trailing_ = &trailing; |
202 | 206 |
203 call.data_ = &postData; | 207 call.data_ = &postData; |
210 for (PostHandlers::const_iterator it = postHandlers_.begin(); | 214 for (PostHandlers::const_iterator it = postHandlers_.begin(); |
211 it != postHandlers_.end(); it++) | 215 it != postHandlers_.end(); it++) |
212 { | 216 { |
213 if (it->first->Match(components, trailing, uri)) | 217 if (it->first->Match(components, trailing, uri)) |
214 { | 218 { |
219 LOG(INFO) << "REST POST call on: " << Toolbox::FlattenUri(uri); | |
215 ok = true; | 220 ok = true; |
216 PostCall call; | 221 PostCall call; |
217 call.output_ = &restOutput; | 222 call.output_ = &restOutput; |
218 call.context_ = context_.get(); | 223 call.context_ = this; |
219 call.httpHeaders_ = &headers; | 224 call.httpHeaders_ = &headers; |
220 call.uriComponents_ = &components; | 225 call.uriComponents_ = &components; |
221 call.trailing_ = &trailing; | 226 call.trailing_ = &trailing; |
222 | 227 |
223 call.data_ = &postData; | 228 call.data_ = &postData; |
230 for (DeleteHandlers::const_iterator it = deleteHandlers_.begin(); | 235 for (DeleteHandlers::const_iterator it = deleteHandlers_.begin(); |
231 it != deleteHandlers_.end(); it++) | 236 it != deleteHandlers_.end(); it++) |
232 { | 237 { |
233 if (it->first->Match(components, trailing, uri)) | 238 if (it->first->Match(components, trailing, uri)) |
234 { | 239 { |
240 LOG(INFO) << "REST DELETE call on: " << Toolbox::FlattenUri(uri); | |
235 ok = true; | 241 ok = true; |
236 DeleteCall call; | 242 DeleteCall call; |
237 call.output_ = &restOutput; | 243 call.output_ = &restOutput; |
238 call.context_ = context_.get(); | 244 call.context_ = this; |
239 call.httpHeaders_ = &headers; | 245 call.httpHeaders_ = &headers; |
240 call.uriComponents_ = &components; | 246 call.uriComponents_ = &components; |
241 call.trailing_ = &trailing; | 247 call.trailing_ = &trailing; |
242 it->second(call); | 248 it->second(call); |
243 } | 249 } |
244 } | 250 } |
245 } | 251 } |
246 | 252 |
247 if (!ok) | 253 if (!ok) |
248 { | 254 { |
255 LOG(INFO) << "REST method " << method << " not allowed on: " << Toolbox::FlattenUri(uri); | |
249 output.SendMethodNotAllowedError(GetAcceptedMethods(uri)); | 256 output.SendMethodNotAllowedError(GetAcceptedMethods(uri)); |
250 } | 257 } |
251 } | 258 } |
252 | 259 |
253 void RestApi::Register(const std::string& path, | 260 void RestApi::Register(const std::string& path, |