Mercurial > hg > orthanc-stone
annotate Framework/Deprecated/Toolbox/BaseWebService.cpp @ 1510:1005c1cbe4dd
fix
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 07 Jul 2020 09:45:27 +0200 |
parents | 30deba7bc8e2 |
children |
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 |
1280
1c7ae79c426d
fix copyright years
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
940
diff
changeset
|
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium |
434
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 |
1455
30deba7bc8e2
simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1300
diff
changeset
|
27 #include <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> |
1455
30deba7bc8e2
simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1300
diff
changeset
|
31 #include <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: |
1299
c38c89684d83
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1281
diff
changeset
|
40 std::unique_ptr< MessageHandler<IWebService::HttpRequestSuccessMessage> > userSuccessHandler_; |
c38c89684d83
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1281
diff
changeset
|
41 std::unique_ptr< MessageHandler<IWebService::HttpRequestErrorMessage> > userFailureHandler_; |
1298
8a0a62189f46
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1280
diff
changeset
|
42 std::unique_ptr< Orthanc::IDynamicObject> userPayload_; |
434
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: |
1222
21c2b0eee53c
deprecating MessageHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1068
diff
changeset
|
45 BaseWebServicePayload(MessageHandler<IWebService::HttpRequestSuccessMessage>* userSuccessHandler, |
21c2b0eee53c
deprecating MessageHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1068
diff
changeset
|
46 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(), |
940
861c080ef47b
handling httpStatus in WebService error messages
Alain Mazy <alain@mazy.be>
parents:
875
diff
changeset
|
78 message.GetHttpStatus(), |
434
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
79 userPayload_.get()); |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
80 |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
81 userFailureHandler_->Apply(failureMessage); |
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 |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
88 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
|
89 const HttpHeaders& headers, |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
90 Orthanc::IDynamicObject* payload /* takes ownership */, |
1222
21c2b0eee53c
deprecating MessageHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1068
diff
changeset
|
91 MessageHandler<IWebService::HttpRequestSuccessMessage>* successCallback, |
21c2b0eee53c
deprecating MessageHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1068
diff
changeset
|
92 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
|
93 unsigned int timeoutInSeconds) |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
94 { |
875
200b4e0dddfc
BaseWebService: disable cache + correct handling of cache
Alain Mazy <alain@mazy.be>
parents:
872
diff
changeset
|
95 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
|
96 { |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
97 GetAsyncInternal(uri, headers, |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
98 new BaseWebService::BaseWebServicePayload(successCallback, failureCallback, payload), // ownership is transfered |
1222
21c2b0eee53c
deprecating MessageHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1068
diff
changeset
|
99 new DeprecatedCallable<BaseWebService, IWebService::HttpRequestSuccessMessage> |
1068
04a95ee91327
recovery of OrthancStoneSingleFrame
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1059
diff
changeset
|
100 (GetSharedObserver(), &BaseWebService::CacheAndNotifyHttpSuccess), |
1222
21c2b0eee53c
deprecating MessageHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1068
diff
changeset
|
101 new DeprecatedCallable<BaseWebService, IWebService::HttpRequestErrorMessage> |
1068
04a95ee91327
recovery of OrthancStoneSingleFrame
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1059
diff
changeset
|
102 (GetSharedObserver(), &BaseWebService::NotifyHttpError), |
434
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
103 timeoutInSeconds); |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
104 } |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
105 else |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
106 { |
872 | 107 // put the uri on top of the most recently accessed list |
108 std::deque<std::string>::iterator it = std::find(orderedCacheKeys_.begin(), orderedCacheKeys_.end(), uri); | |
109 if (it != orderedCacheKeys_.end()) | |
110 { | |
111 std::string uri = *it; | |
112 orderedCacheKeys_.erase(it); | |
113 orderedCacheKeys_.push_front(uri); | |
114 } | |
115 | |
434
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
116 // 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
|
117 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
|
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 |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
124 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
|
125 { |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
126 if (message.HasPayload()) |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
127 { |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
128 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
|
129 } |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
130 else |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
131 { |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
132 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
|
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 |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
136 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
|
137 { |
875
200b4e0dddfc
BaseWebService: disable cache + correct handling of cache
Alain Mazy <alain@mazy.be>
parents:
872
diff
changeset
|
138 if (cacheEnabled_) |
872 | 139 { |
875
200b4e0dddfc
BaseWebService: disable cache + correct handling of cache
Alain Mazy <alain@mazy.be>
parents:
872
diff
changeset
|
140 while (cacheCurrentSize_ + message.GetAnswerSize() > cacheMaxSize_ && orderedCacheKeys_.size() > 0) |
872 | 141 { |
875
200b4e0dddfc
BaseWebService: disable cache + correct handling of cache
Alain Mazy <alain@mazy.be>
parents:
872
diff
changeset
|
142 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
|
143 const std::string& oldestUri = orderedCacheKeys_.back(); |
200b4e0dddfc
BaseWebService: disable cache + correct handling of cache
Alain Mazy <alain@mazy.be>
parents:
872
diff
changeset
|
144 HttpCache::iterator it = cache_.find(oldestUri); |
200b4e0dddfc
BaseWebService: disable cache + correct handling of cache
Alain Mazy <alain@mazy.be>
parents:
872
diff
changeset
|
145 if (it != cache_.end()) |
200b4e0dddfc
BaseWebService: disable cache + correct handling of cache
Alain Mazy <alain@mazy.be>
parents:
872
diff
changeset
|
146 { |
200b4e0dddfc
BaseWebService: disable cache + correct handling of cache
Alain Mazy <alain@mazy.be>
parents:
872
diff
changeset
|
147 cacheCurrentSize_ -= it->second->GetAnswerSize(); |
200b4e0dddfc
BaseWebService: disable cache + correct handling of cache
Alain Mazy <alain@mazy.be>
parents:
872
diff
changeset
|
148 cache_.erase(it); |
200b4e0dddfc
BaseWebService: disable cache + correct handling of cache
Alain Mazy <alain@mazy.be>
parents:
872
diff
changeset
|
149 } |
200b4e0dddfc
BaseWebService: disable cache + correct handling of cache
Alain Mazy <alain@mazy.be>
parents:
872
diff
changeset
|
150 orderedCacheKeys_.pop_back(); |
872 | 151 |
875
200b4e0dddfc
BaseWebService: disable cache + correct handling of cache
Alain Mazy <alain@mazy.be>
parents:
872
diff
changeset
|
152 } |
872 | 153 |
875
200b4e0dddfc
BaseWebService: disable cache + correct handling of cache
Alain Mazy <alain@mazy.be>
parents:
872
diff
changeset
|
154 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
|
155 cache_[message.GetUri()] = cachedMessage; |
200b4e0dddfc
BaseWebService: disable cache + correct handling of cache
Alain Mazy <alain@mazy.be>
parents:
872
diff
changeset
|
156 orderedCacheKeys_.push_front(message.GetUri()); |
200b4e0dddfc
BaseWebService: disable cache + correct handling of cache
Alain Mazy <alain@mazy.be>
parents:
872
diff
changeset
|
157 cacheCurrentSize_ += message.GetAnswerSize(); |
200b4e0dddfc
BaseWebService: disable cache + correct handling of cache
Alain Mazy <alain@mazy.be>
parents:
872
diff
changeset
|
158 } |
872 | 159 |
434
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
160 NotifyHttpSuccess(message); |
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 |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
163 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
|
164 { |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
165 if (message.HasPayload()) |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
166 { |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
167 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
|
168 } |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
169 else |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
170 { |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
171 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
|
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 |
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
diff
changeset
|
178 } |