Mercurial > hg > orthanc-stone
annotate Framework/Toolbox/OrthancApiClient.cpp @ 498:6d62fc8a6988 bgo-commands-codegen
Web demonstrator for codegen ongoing work
author | bgo-osimis |
---|---|
date | Sun, 24 Feb 2019 13:23:14 +0100 |
parents | a750f11892ec |
children | 3ae7563b4fe1 |
rev | line source |
---|---|
270 | 1 /** |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
439 | 5 * Copyright (C) 2017-2019 Osimis S.A., Belgium |
270 | 6 * |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU Affero General Public License | |
9 * as published by the Free Software Foundation, either version 3 of | |
10 * the License, or (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, but | |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * Affero General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Affero General Public License | |
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 **/ | |
20 | |
21 #include "OrthancApiClient.h" | |
22 | |
23 #include "MessagingToolbox.h" | |
309 | 24 #include "Framework/Toolbox/MessagingToolbox.h" |
270 | 25 |
377 | 26 #include <Core/OrthancException.h> |
270 | 27 |
377 | 28 namespace OrthancStone |
29 { | |
30 const Orthanc::IDynamicObject& OrthancApiClient::JsonResponseReadyMessage::GetPayload() const | |
31 { | |
32 if (HasPayload()) | |
33 { | |
34 return *payload_; | |
35 } | |
36 else | |
37 { | |
38 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
39 } | |
40 } | |
41 | |
42 | |
43 const Orthanc::IDynamicObject& OrthancApiClient::BinaryResponseReadyMessage::GetPayload() const | |
44 { | |
45 if (HasPayload()) | |
46 { | |
47 return *payload_; | |
48 } | |
49 else | |
50 { | |
51 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
52 } | |
53 } | |
54 | |
55 | |
56 const Orthanc::IDynamicObject& OrthancApiClient::EmptyResponseReadyMessage::GetPayload() const | |
57 { | |
58 if (HasPayload()) | |
59 { | |
60 return *payload_; | |
61 } | |
62 else | |
63 { | |
64 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
65 } | |
66 } | |
67 | |
68 | |
383
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
69 class OrthancApiClient::WebServicePayload : public Orthanc::IDynamicObject |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
70 { |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
71 private: |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
72 std::auto_ptr< MessageHandler<EmptyResponseReadyMessage> > emptyHandler_; |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
73 std::auto_ptr< MessageHandler<JsonResponseReadyMessage> > jsonHandler_; |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
74 std::auto_ptr< MessageHandler<BinaryResponseReadyMessage> > binaryHandler_; |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
75 std::auto_ptr< MessageHandler<IWebService::HttpRequestErrorMessage> > failureHandler_; |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
76 std::auto_ptr< Orthanc::IDynamicObject > userPayload_; |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
77 |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
78 void NotifyConversionError(const IWebService::HttpRequestSuccessMessage& message) const |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
79 { |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
80 if (failureHandler_.get() != NULL) |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
81 { |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
82 failureHandler_->Apply(IWebService::HttpRequestErrorMessage |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
83 (message.GetUri(), userPayload_.get())); |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
84 } |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
85 } |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
86 |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
87 public: |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
88 WebServicePayload(MessageHandler<EmptyResponseReadyMessage>* handler, |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
89 MessageHandler<IWebService::HttpRequestErrorMessage>* failureHandler, |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
90 Orthanc::IDynamicObject* userPayload) : |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
91 emptyHandler_(handler), |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
92 failureHandler_(failureHandler), |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
93 userPayload_(userPayload) |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
94 { |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
95 if (handler == NULL) |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
96 { |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
97 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
98 } |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
99 } |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
100 |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
101 WebServicePayload(MessageHandler<BinaryResponseReadyMessage>* handler, |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
102 MessageHandler<IWebService::HttpRequestErrorMessage>* failureHandler, |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
103 Orthanc::IDynamicObject* userPayload) : |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
104 binaryHandler_(handler), |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
105 failureHandler_(failureHandler), |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
106 userPayload_(userPayload) |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
107 { |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
108 if (handler == NULL) |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
109 { |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
110 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
111 } |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
112 } |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
113 |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
114 WebServicePayload(MessageHandler<JsonResponseReadyMessage>* handler, |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
115 MessageHandler<IWebService::HttpRequestErrorMessage>* failureHandler, |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
116 Orthanc::IDynamicObject* userPayload) : |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
117 jsonHandler_(handler), |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
118 failureHandler_(failureHandler), |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
119 userPayload_(userPayload) |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
120 { |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
121 if (handler == NULL) |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
122 { |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
123 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
124 } |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
125 } |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
126 |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
127 void HandleSuccess(const IWebService::HttpRequestSuccessMessage& message) const |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
128 { |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
129 if (emptyHandler_.get() != NULL) |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
130 { |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
131 emptyHandler_->Apply(OrthancApiClient::EmptyResponseReadyMessage |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
132 (message.GetUri(), userPayload_.get())); |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
133 } |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
134 else if (binaryHandler_.get() != NULL) |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
135 { |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
136 binaryHandler_->Apply(OrthancApiClient::BinaryResponseReadyMessage |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
137 (message.GetUri(), message.GetAnswer(), |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
138 message.GetAnswerSize(), userPayload_.get())); |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
139 } |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
140 else if (jsonHandler_.get() != NULL) |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
141 { |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
142 Json::Value response; |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
143 if (MessagingToolbox::ParseJson(response, message.GetAnswer(), message.GetAnswerSize())) |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
144 { |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
145 jsonHandler_->Apply(OrthancApiClient::JsonResponseReadyMessage |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
146 (message.GetUri(), response, userPayload_.get())); |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
147 } |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
148 else |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
149 { |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
150 NotifyConversionError(message); |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
151 } |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
152 } |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
153 else |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
154 { |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
155 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
156 } |
422
4fe42ae3653a
introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents:
418
diff
changeset
|
157 } |
383
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
158 |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
159 void HandleFailure(const IWebService::HttpRequestErrorMessage& message) const |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
160 { |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
161 if (failureHandler_.get() != NULL) |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
162 { |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
163 failureHandler_->Apply(IWebService::HttpRequestErrorMessage |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
164 (message.GetUri(), userPayload_.get())); |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
165 } |
422
4fe42ae3653a
introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents:
418
diff
changeset
|
166 } |
383
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
167 }; |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
168 |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
169 |
382
dd4c7e82b4be
removed class OrthancApiClient::HttpErrorMessage, redundant with IWebService::HttpRequestErrorMessage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
170 OrthancApiClient::OrthancApiClient(MessageBroker& broker, |
417
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
383
diff
changeset
|
171 IWebService& web, |
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
383
diff
changeset
|
172 const std::string& baseUrl) : |
377 | 173 IObservable(broker), |
383
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
174 IObserver(broker), |
417
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
383
diff
changeset
|
175 web_(web), |
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
383
diff
changeset
|
176 baseUrl_(baseUrl) |
270 | 177 { |
178 } | |
179 | |
334
c34784e5f299
compatibility fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
315
diff
changeset
|
180 |
383
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
181 void OrthancApiClient::GetJsonAsync( |
422
4fe42ae3653a
introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents:
418
diff
changeset
|
182 const std::string& uri, |
4fe42ae3653a
introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents:
418
diff
changeset
|
183 MessageHandler<JsonResponseReadyMessage>* successCallback, |
4fe42ae3653a
introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents:
418
diff
changeset
|
184 MessageHandler<IWebService::HttpRequestErrorMessage>* failureCallback, |
4fe42ae3653a
introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents:
418
diff
changeset
|
185 Orthanc::IDynamicObject* payload) |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
186 { |
422
4fe42ae3653a
introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents:
418
diff
changeset
|
187 IWebService::HttpHeaders emptyHeaders; |
417
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
383
diff
changeset
|
188 web_.GetAsync(baseUrl_ + uri, |
434
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
430
diff
changeset
|
189 emptyHeaders, |
417
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
383
diff
changeset
|
190 new WebServicePayload(successCallback, failureCallback, payload), |
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
383
diff
changeset
|
191 new Callable<OrthancApiClient, IWebService::HttpRequestSuccessMessage> |
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
383
diff
changeset
|
192 (*this, &OrthancApiClient::NotifyHttpSuccess), |
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
383
diff
changeset
|
193 new Callable<OrthancApiClient, IWebService::HttpRequestErrorMessage> |
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
383
diff
changeset
|
194 (*this, &OrthancApiClient::NotifyHttpError)); |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
271
diff
changeset
|
195 } |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
271
diff
changeset
|
196 |
382
dd4c7e82b4be
removed class OrthancApiClient::HttpErrorMessage, redundant with IWebService::HttpRequestErrorMessage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
197 |
383
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
198 void OrthancApiClient::GetBinaryAsync( |
422
4fe42ae3653a
introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents:
418
diff
changeset
|
199 const std::string& uri, |
4fe42ae3653a
introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents:
418
diff
changeset
|
200 const std::string& contentType, |
4fe42ae3653a
introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents:
418
diff
changeset
|
201 MessageHandler<BinaryResponseReadyMessage>* successCallback, |
4fe42ae3653a
introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents:
418
diff
changeset
|
202 MessageHandler<IWebService::HttpRequestErrorMessage>* failureCallback, |
4fe42ae3653a
introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents:
418
diff
changeset
|
203 Orthanc::IDynamicObject* payload) |
382
dd4c7e82b4be
removed class OrthancApiClient::HttpErrorMessage, redundant with IWebService::HttpRequestErrorMessage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
204 { |
417
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
383
diff
changeset
|
205 IWebService::HttpHeaders headers; |
382
dd4c7e82b4be
removed class OrthancApiClient::HttpErrorMessage, redundant with IWebService::HttpRequestErrorMessage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
206 headers["Accept"] = contentType; |
dd4c7e82b4be
removed class OrthancApiClient::HttpErrorMessage, redundant with IWebService::HttpRequestErrorMessage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
207 GetBinaryAsync(uri, headers, successCallback, failureCallback, payload); |
dd4c7e82b4be
removed class OrthancApiClient::HttpErrorMessage, redundant with IWebService::HttpRequestErrorMessage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
208 } |
dd4c7e82b4be
removed class OrthancApiClient::HttpErrorMessage, redundant with IWebService::HttpRequestErrorMessage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
209 |
383
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
210 void OrthancApiClient::GetBinaryAsync( |
422
4fe42ae3653a
introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents:
418
diff
changeset
|
211 const std::string& uri, |
4fe42ae3653a
introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents:
418
diff
changeset
|
212 const IWebService::HttpHeaders& headers, |
4fe42ae3653a
introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents:
418
diff
changeset
|
213 MessageHandler<BinaryResponseReadyMessage>* successCallback, |
4fe42ae3653a
introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents:
418
diff
changeset
|
214 MessageHandler<IWebService::HttpRequestErrorMessage>* failureCallback, |
4fe42ae3653a
introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents:
418
diff
changeset
|
215 Orthanc::IDynamicObject* payload) |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
216 { |
422
4fe42ae3653a
introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents:
418
diff
changeset
|
217 // printf("GET [%s] [%s]\n", baseUrl_.c_str(), uri.c_str()); |
4fe42ae3653a
introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents:
418
diff
changeset
|
218 |
417
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
383
diff
changeset
|
219 web_.GetAsync(baseUrl_ + uri, headers, |
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
383
diff
changeset
|
220 new WebServicePayload(successCallback, failureCallback, payload), |
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
383
diff
changeset
|
221 new Callable<OrthancApiClient, IWebService::HttpRequestSuccessMessage> |
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
383
diff
changeset
|
222 (*this, &OrthancApiClient::NotifyHttpSuccess), |
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
383
diff
changeset
|
223 new Callable<OrthancApiClient, IWebService::HttpRequestErrorMessage> |
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
383
diff
changeset
|
224 (*this, &OrthancApiClient::NotifyHttpError)); |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
225 } |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
226 |
382
dd4c7e82b4be
removed class OrthancApiClient::HttpErrorMessage, redundant with IWebService::HttpRequestErrorMessage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
227 |
383
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
228 void OrthancApiClient::PostBinaryAsyncExpectJson( |
422
4fe42ae3653a
introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents:
418
diff
changeset
|
229 const std::string& uri, |
4fe42ae3653a
introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents:
418
diff
changeset
|
230 const std::string& body, |
4fe42ae3653a
introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents:
418
diff
changeset
|
231 MessageHandler<JsonResponseReadyMessage>* successCallback, |
4fe42ae3653a
introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents:
418
diff
changeset
|
232 MessageHandler<IWebService::HttpRequestErrorMessage>* failureCallback, |
4fe42ae3653a
introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents:
418
diff
changeset
|
233 Orthanc::IDynamicObject* payload) |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
234 { |
417
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
383
diff
changeset
|
235 web_.PostAsync(baseUrl_ + uri, IWebService::HttpHeaders(), body, |
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
383
diff
changeset
|
236 new WebServicePayload(successCallback, failureCallback, payload), |
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
383
diff
changeset
|
237 new Callable<OrthancApiClient, IWebService::HttpRequestSuccessMessage> |
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
383
diff
changeset
|
238 (*this, &OrthancApiClient::NotifyHttpSuccess), |
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
383
diff
changeset
|
239 new Callable<OrthancApiClient, IWebService::HttpRequestErrorMessage> |
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
383
diff
changeset
|
240 (*this, &OrthancApiClient::NotifyHttpError)); |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
241 |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
242 } |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
243 |
424
bb573a52fc63
allow POST messages with success and failure handlers
am@osimis.io
parents:
422
diff
changeset
|
244 void OrthancApiClient::PostBinaryAsync( |
bb573a52fc63
allow POST messages with success and failure handlers
am@osimis.io
parents:
422
diff
changeset
|
245 const std::string& uri, |
bb573a52fc63
allow POST messages with success and failure handlers
am@osimis.io
parents:
422
diff
changeset
|
246 const std::string& body) |
bb573a52fc63
allow POST messages with success and failure handlers
am@osimis.io
parents:
422
diff
changeset
|
247 { |
bb573a52fc63
allow POST messages with success and failure handlers
am@osimis.io
parents:
422
diff
changeset
|
248 web_.PostAsync(baseUrl_ + uri, IWebService::HttpHeaders(), body, NULL, NULL, NULL); |
bb573a52fc63
allow POST messages with success and failure handlers
am@osimis.io
parents:
422
diff
changeset
|
249 } |
bb573a52fc63
allow POST messages with success and failure handlers
am@osimis.io
parents:
422
diff
changeset
|
250 |
383
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
251 void OrthancApiClient::PostJsonAsyncExpectJson( |
422
4fe42ae3653a
introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents:
418
diff
changeset
|
252 const std::string& uri, |
4fe42ae3653a
introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents:
418
diff
changeset
|
253 const Json::Value& data, |
4fe42ae3653a
introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents:
418
diff
changeset
|
254 MessageHandler<JsonResponseReadyMessage>* successCallback, |
4fe42ae3653a
introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents:
418
diff
changeset
|
255 MessageHandler<IWebService::HttpRequestErrorMessage>* failureCallback, |
4fe42ae3653a
introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents:
418
diff
changeset
|
256 Orthanc::IDynamicObject* payload) |
309 | 257 { |
258 std::string body; | |
259 MessagingToolbox::JsonToString(body, data); | |
260 return PostBinaryAsyncExpectJson(uri, body, successCallback, failureCallback, payload); | |
261 } | |
262 | |
424
bb573a52fc63
allow POST messages with success and failure handlers
am@osimis.io
parents:
422
diff
changeset
|
263 void OrthancApiClient::PostJsonAsync( |
bb573a52fc63
allow POST messages with success and failure handlers
am@osimis.io
parents:
422
diff
changeset
|
264 const std::string& uri, |
bb573a52fc63
allow POST messages with success and failure handlers
am@osimis.io
parents:
422
diff
changeset
|
265 const Json::Value& data) |
bb573a52fc63
allow POST messages with success and failure handlers
am@osimis.io
parents:
422
diff
changeset
|
266 { |
bb573a52fc63
allow POST messages with success and failure handlers
am@osimis.io
parents:
422
diff
changeset
|
267 std::string body; |
bb573a52fc63
allow POST messages with success and failure handlers
am@osimis.io
parents:
422
diff
changeset
|
268 MessagingToolbox::JsonToString(body, data); |
bb573a52fc63
allow POST messages with success and failure handlers
am@osimis.io
parents:
422
diff
changeset
|
269 return PostBinaryAsync(uri, body); |
bb573a52fc63
allow POST messages with success and failure handlers
am@osimis.io
parents:
422
diff
changeset
|
270 } |
bb573a52fc63
allow POST messages with success and failure handlers
am@osimis.io
parents:
422
diff
changeset
|
271 |
383
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
272 void OrthancApiClient::DeleteAsync( |
422
4fe42ae3653a
introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents:
418
diff
changeset
|
273 const std::string& uri, |
4fe42ae3653a
introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents:
418
diff
changeset
|
274 MessageHandler<EmptyResponseReadyMessage>* successCallback, |
4fe42ae3653a
introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents:
418
diff
changeset
|
275 MessageHandler<IWebService::HttpRequestErrorMessage>* failureCallback, |
4fe42ae3653a
introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents:
418
diff
changeset
|
276 Orthanc::IDynamicObject* payload) |
315
aad37d0b6407
Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents:
309
diff
changeset
|
277 { |
417
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
383
diff
changeset
|
278 web_.DeleteAsync(baseUrl_ + uri, IWebService::HttpHeaders(), |
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
383
diff
changeset
|
279 new WebServicePayload(successCallback, failureCallback, payload), |
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
383
diff
changeset
|
280 new Callable<OrthancApiClient, IWebService::HttpRequestSuccessMessage> |
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
383
diff
changeset
|
281 (*this, &OrthancApiClient::NotifyHttpSuccess), |
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
383
diff
changeset
|
282 new Callable<OrthancApiClient, IWebService::HttpRequestErrorMessage> |
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
383
diff
changeset
|
283 (*this, &OrthancApiClient::NotifyHttpError)); |
315
aad37d0b6407
Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents:
309
diff
changeset
|
284 } |
aad37d0b6407
Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents:
309
diff
changeset
|
285 |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
286 |
383
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
287 void OrthancApiClient::NotifyHttpSuccess(const IWebService::HttpRequestSuccessMessage& message) |
382
dd4c7e82b4be
removed class OrthancApiClient::HttpErrorMessage, redundant with IWebService::HttpRequestErrorMessage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
288 { |
383
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
289 if (message.HasPayload()) |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
290 { |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
291 dynamic_cast<const WebServicePayload&>(message.GetPayload()).HandleSuccess(message); |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
292 } |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
293 else |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
294 { |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
295 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
296 } |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
297 } |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
298 |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
299 void OrthancApiClient::NotifyHttpError(const IWebService::HttpRequestErrorMessage& message) |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
300 { |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
301 if (message.HasPayload()) |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
302 { |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
303 dynamic_cast<const WebServicePayload&>(message.GetPayload()).HandleFailure(message); |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
304 } |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
305 else |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
306 { |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
307 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
308 } |
422
4fe42ae3653a
introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents:
418
diff
changeset
|
309 } |
270 | 310 } |