Mercurial > hg > orthanc-stone
annotate Framework/Deprecated/Toolbox/BaseWebService.cpp @ 921:81d30cd93b65 toa2019072201
Ability to ask the loader for the geometry in PULL mode (when subscribing to the messages is not possible) + small changes (removed const/ref qualifiers for boost::shared_ptr param, added traces, doc change)
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Mon, 22 Jul 2019 11:21:09 +0200 |
parents | 200b4e0dddfc |
children | 861c080ef47b |
rev | line source |
---|---|
434
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
1 /** |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
2 * Stone of Orthanc |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
6 * |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
7 * This program is free software: you can redistribute it and/or |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
8 * modify it under the terms of the GNU Affero General Public License |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
9 * as published by the Free Software Foundation, either version 3 of |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
10 * the License, or (at your option) any later version. |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
11 * |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
12 * This program is distributed in the hope that it will be useful, but |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
13 * WITHOUT ANY WARRANTY; without even the implied warranty of |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
15 * Affero General Public License for more details. |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
16 * |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
17 * You should have received a copy of the GNU Affero General Public License |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
19 **/ |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
20 |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
21 |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
22 #include "BaseWebService.h" |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
23 |
736
c0fcb2757b0a
enforce relative includes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
24 #include "../../Messages/IObservable.h" |
c0fcb2757b0a
enforce relative includes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
25 #include "../../../Platforms/Generic/IOracleCommand.h" |
c0fcb2757b0a
enforce relative includes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
26 |
434
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
27 #include <Core/OrthancException.h> |
736
c0fcb2757b0a
enforce relative includes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
28 |
435
e641d3978856
WasmWebService now using BaseWebService and supporting cache
am@osimis.io
parents:
434
diff
changeset
|
29 #include <boost/shared_ptr.hpp> |
872 | 30 #include <algorithm> |
875
200b4e0dddfc
BaseWebService: disable cache + correct handling of cache
Alain Mazy <alain@mazy.be>
parents:
872
diff
changeset
|
31 #include <Core/Logging.h> |
434
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
32 |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
435
diff
changeset
|
33 namespace Deprecated |
434
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
34 { |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
35 |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
36 |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
37 class BaseWebService::BaseWebServicePayload : public Orthanc::IDynamicObject |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
38 { |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
39 private: |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
435
diff
changeset
|
40 std::auto_ptr< OrthancStone::MessageHandler<IWebService::HttpRequestSuccessMessage> > userSuccessHandler_; |
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
435
diff
changeset
|
41 std::auto_ptr< OrthancStone::MessageHandler<IWebService::HttpRequestErrorMessage> > userFailureHandler_; |
434
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
42 std::auto_ptr< Orthanc::IDynamicObject> userPayload_; |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
43 |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
44 public: |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
435
diff
changeset
|
45 BaseWebServicePayload(OrthancStone::MessageHandler<IWebService::HttpRequestSuccessMessage>* userSuccessHandler, |
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
435
diff
changeset
|
46 OrthancStone::MessageHandler<IWebService::HttpRequestErrorMessage>* userFailureHandler, |
434
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
47 Orthanc::IDynamicObject* userPayload) : |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
48 userSuccessHandler_(userSuccessHandler), |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
49 userFailureHandler_(userFailureHandler), |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
50 userPayload_(userPayload) |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
51 { |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
52 } |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
53 |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
54 void HandleSuccess(const IWebService::HttpRequestSuccessMessage& message) const |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
55 { |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
56 if (userSuccessHandler_.get() != NULL) |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
57 { |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
58 // recreate a success message with the user payload |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
59 IWebService::HttpRequestSuccessMessage successMessage(message.GetUri(), |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
60 message.GetAnswer(), |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
61 message.GetAnswerSize(), |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
62 message.GetAnswerHttpHeaders(), |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
63 userPayload_.get()); |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
64 userSuccessHandler_->Apply(successMessage); |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
65 } |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
66 else |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
67 { |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
68 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
69 } |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
70 } |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
71 |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
72 void HandleFailure(const IWebService::HttpRequestErrorMessage& message) const |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
73 { |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
74 if (userFailureHandler_.get() != NULL) |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
75 { |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
76 // recreate a failure message with the user payload |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
77 IWebService::HttpRequestErrorMessage failureMessage(message.GetUri(), |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
78 userPayload_.get()); |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
79 |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
80 userFailureHandler_->Apply(failureMessage); |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
81 } |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
82 } |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
83 |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
84 }; |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
85 |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
86 |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
87 void BaseWebService::GetAsync(const std::string& uri, |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
88 const HttpHeaders& headers, |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
89 Orthanc::IDynamicObject* payload /* takes ownership */, |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
435
diff
changeset
|
90 OrthancStone::MessageHandler<IWebService::HttpRequestSuccessMessage>* successCallback, |
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
435
diff
changeset
|
91 OrthancStone::MessageHandler<IWebService::HttpRequestErrorMessage>* failureCallback, |
434
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
92 unsigned int timeoutInSeconds) |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
93 { |
875
200b4e0dddfc
BaseWebService: disable cache + correct handling of cache
Alain Mazy <alain@mazy.be>
parents:
872
diff
changeset
|
94 if (!cacheEnabled_ || cache_.find(uri) == cache_.end()) |
434
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
95 { |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
96 GetAsyncInternal(uri, headers, |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
97 new BaseWebService::BaseWebServicePayload(successCallback, failureCallback, payload), // ownership is transfered |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
435
diff
changeset
|
98 new OrthancStone::Callable<BaseWebService, IWebService::HttpRequestSuccessMessage> |
434
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
99 (*this, &BaseWebService::CacheAndNotifyHttpSuccess), |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
435
diff
changeset
|
100 new OrthancStone::Callable<BaseWebService, IWebService::HttpRequestErrorMessage> |
434
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
101 (*this, &BaseWebService::NotifyHttpError), |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
102 timeoutInSeconds); |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
103 } |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
104 else |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
105 { |
872 | 106 // put the uri on top of the most recently accessed list |
107 std::deque<std::string>::iterator it = std::find(orderedCacheKeys_.begin(), orderedCacheKeys_.end(), uri); | |
108 if (it != orderedCacheKeys_.end()) | |
109 { | |
110 std::string uri = *it; | |
111 orderedCacheKeys_.erase(it); | |
112 orderedCacheKeys_.push_front(uri); | |
113 } | |
114 | |
434
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
115 // create a command and "post" it to the Oracle so it is executed and commited "later" |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
116 NotifyHttpSuccessLater(cache_[uri], payload, successCallback); |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
117 } |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
118 |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
119 } |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
120 |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
121 |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
122 |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
123 void BaseWebService::NotifyHttpSuccess(const IWebService::HttpRequestSuccessMessage& message) |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
124 { |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
125 if (message.HasPayload()) |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
126 { |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
127 dynamic_cast<const BaseWebServicePayload&>(message.GetPayload()).HandleSuccess(message); |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
128 } |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
129 else |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
130 { |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
131 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
132 } |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
133 } |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
134 |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
135 void BaseWebService::CacheAndNotifyHttpSuccess(const IWebService::HttpRequestSuccessMessage& message) |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
136 { |
875
200b4e0dddfc
BaseWebService: disable cache + correct handling of cache
Alain Mazy <alain@mazy.be>
parents:
872
diff
changeset
|
137 if (cacheEnabled_) |
872 | 138 { |
875
200b4e0dddfc
BaseWebService: disable cache + correct handling of cache
Alain Mazy <alain@mazy.be>
parents:
872
diff
changeset
|
139 while (cacheCurrentSize_ + message.GetAnswerSize() > cacheMaxSize_ && orderedCacheKeys_.size() > 0) |
872 | 140 { |
875
200b4e0dddfc
BaseWebService: disable cache + correct handling of cache
Alain Mazy <alain@mazy.be>
parents:
872
diff
changeset
|
141 VLOG(1) << "BaseWebService: clearing cache: " << cacheCurrentSize_ << "/" << cacheMaxSize_ << "(" << message.GetAnswerSize() << ")"; |
200b4e0dddfc
BaseWebService: disable cache + correct handling of cache
Alain Mazy <alain@mazy.be>
parents:
872
diff
changeset
|
142 const std::string& oldestUri = orderedCacheKeys_.back(); |
200b4e0dddfc
BaseWebService: disable cache + correct handling of cache
Alain Mazy <alain@mazy.be>
parents:
872
diff
changeset
|
143 HttpCache::iterator it = cache_.find(oldestUri); |
200b4e0dddfc
BaseWebService: disable cache + correct handling of cache
Alain Mazy <alain@mazy.be>
parents:
872
diff
changeset
|
144 if (it != cache_.end()) |
200b4e0dddfc
BaseWebService: disable cache + correct handling of cache
Alain Mazy <alain@mazy.be>
parents:
872
diff
changeset
|
145 { |
200b4e0dddfc
BaseWebService: disable cache + correct handling of cache
Alain Mazy <alain@mazy.be>
parents:
872
diff
changeset
|
146 cacheCurrentSize_ -= it->second->GetAnswerSize(); |
200b4e0dddfc
BaseWebService: disable cache + correct handling of cache
Alain Mazy <alain@mazy.be>
parents:
872
diff
changeset
|
147 cache_.erase(it); |
200b4e0dddfc
BaseWebService: disable cache + correct handling of cache
Alain Mazy <alain@mazy.be>
parents:
872
diff
changeset
|
148 } |
200b4e0dddfc
BaseWebService: disable cache + correct handling of cache
Alain Mazy <alain@mazy.be>
parents:
872
diff
changeset
|
149 orderedCacheKeys_.pop_back(); |
872 | 150 |
875
200b4e0dddfc
BaseWebService: disable cache + correct handling of cache
Alain Mazy <alain@mazy.be>
parents:
872
diff
changeset
|
151 } |
872 | 152 |
875
200b4e0dddfc
BaseWebService: disable cache + correct handling of cache
Alain Mazy <alain@mazy.be>
parents:
872
diff
changeset
|
153 boost::shared_ptr<CachedHttpRequestSuccessMessage> cachedMessage(new CachedHttpRequestSuccessMessage(message)); |
200b4e0dddfc
BaseWebService: disable cache + correct handling of cache
Alain Mazy <alain@mazy.be>
parents:
872
diff
changeset
|
154 cache_[message.GetUri()] = cachedMessage; |
200b4e0dddfc
BaseWebService: disable cache + correct handling of cache
Alain Mazy <alain@mazy.be>
parents:
872
diff
changeset
|
155 orderedCacheKeys_.push_front(message.GetUri()); |
200b4e0dddfc
BaseWebService: disable cache + correct handling of cache
Alain Mazy <alain@mazy.be>
parents:
872
diff
changeset
|
156 cacheCurrentSize_ += message.GetAnswerSize(); |
200b4e0dddfc
BaseWebService: disable cache + correct handling of cache
Alain Mazy <alain@mazy.be>
parents:
872
diff
changeset
|
157 } |
872 | 158 |
434
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
159 NotifyHttpSuccess(message); |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
160 } |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
161 |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
162 void BaseWebService::NotifyHttpError(const IWebService::HttpRequestErrorMessage& message) |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
163 { |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
164 if (message.HasPayload()) |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
165 { |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
166 dynamic_cast<const BaseWebServicePayload&>(message.GetPayload()).HandleFailure(message); |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
167 } |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
168 else |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
169 { |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
170 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
171 } |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
172 } |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
173 |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
174 |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
175 |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
176 |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
177 } |