annotate Framework/Toolbox/OrthancApiClient.cpp @ 309:14ef1227120f am-callable-and-promise

web services: better handling of failures
author am@osimis.io
date Fri, 28 Sep 2018 15:02:43 +0200
parents 547e1cf7aa7b
children aad37d0b6407
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
270
2d64f4d39610 backup (work in progress)
am@osimis.io
parents:
diff changeset
1 /**
2d64f4d39610 backup (work in progress)
am@osimis.io
parents:
diff changeset
2 * Stone of Orthanc
2d64f4d39610 backup (work in progress)
am@osimis.io
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
2d64f4d39610 backup (work in progress)
am@osimis.io
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
2d64f4d39610 backup (work in progress)
am@osimis.io
parents:
diff changeset
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium
2d64f4d39610 backup (work in progress)
am@osimis.io
parents:
diff changeset
6 *
2d64f4d39610 backup (work in progress)
am@osimis.io
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
2d64f4d39610 backup (work in progress)
am@osimis.io
parents:
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
2d64f4d39610 backup (work in progress)
am@osimis.io
parents:
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
2d64f4d39610 backup (work in progress)
am@osimis.io
parents:
diff changeset
10 * the License, or (at your option) any later version.
2d64f4d39610 backup (work in progress)
am@osimis.io
parents:
diff changeset
11 *
2d64f4d39610 backup (work in progress)
am@osimis.io
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
2d64f4d39610 backup (work in progress)
am@osimis.io
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
2d64f4d39610 backup (work in progress)
am@osimis.io
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2d64f4d39610 backup (work in progress)
am@osimis.io
parents:
diff changeset
15 * Affero General Public License for more details.
2d64f4d39610 backup (work in progress)
am@osimis.io
parents:
diff changeset
16 *
2d64f4d39610 backup (work in progress)
am@osimis.io
parents:
diff changeset
17 * You should have received a copy of the GNU Affero General Public License
2d64f4d39610 backup (work in progress)
am@osimis.io
parents:
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
2d64f4d39610 backup (work in progress)
am@osimis.io
parents:
diff changeset
19 **/
2d64f4d39610 backup (work in progress)
am@osimis.io
parents:
diff changeset
20
2d64f4d39610 backup (work in progress)
am@osimis.io
parents:
diff changeset
21 #include "OrthancApiClient.h"
2d64f4d39610 backup (work in progress)
am@osimis.io
parents:
diff changeset
22
2d64f4d39610 backup (work in progress)
am@osimis.io
parents:
diff changeset
23 #include "MessagingToolbox.h"
2d64f4d39610 backup (work in progress)
am@osimis.io
parents:
diff changeset
24 #include <Core/OrthancException.h>
309
14ef1227120f web services: better handling of failures
am@osimis.io
parents: 301
diff changeset
25 #include "Framework/Toolbox/MessagingToolbox.h"
270
2d64f4d39610 backup (work in progress)
am@osimis.io
parents:
diff changeset
26
2d64f4d39610 backup (work in progress)
am@osimis.io
parents:
diff changeset
27 namespace OrthancStone {
2d64f4d39610 backup (work in progress)
am@osimis.io
parents:
diff changeset
28
2d64f4d39610 backup (work in progress)
am@osimis.io
parents:
diff changeset
29 OrthancApiClient::OrthancApiClient(MessageBroker &broker, IWebService &orthanc)
2d64f4d39610 backup (work in progress)
am@osimis.io
parents:
diff changeset
30 : IObservable(broker),
300
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
31 orthanc_(orthanc)
270
2d64f4d39610 backup (work in progress)
am@osimis.io
parents:
diff changeset
32 {
2d64f4d39610 backup (work in progress)
am@osimis.io
parents:
diff changeset
33 }
2d64f4d39610 backup (work in progress)
am@osimis.io
parents:
diff changeset
34
299
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
35 // performs the translation between IWebService messages and OrthancApiClient messages
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
36 // TODO: handle destruction of this object (with shared_ptr ?::delete_later ???)
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
37 class HttpResponseToJsonConverter : public IObserver, IObservable
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
38 {
300
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
39 std::auto_ptr<MessageHandler<OrthancApiClient::JsonResponseReadyMessage>> orthancApiSuccessCallback_;
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
40 std::auto_ptr<MessageHandler<OrthancApiClient::HttpErrorMessage>> orthancApiFailureCallback_;
299
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
41 public:
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
42 HttpResponseToJsonConverter(MessageBroker& broker,
300
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
43 MessageHandler<OrthancApiClient::JsonResponseReadyMessage>* orthancApiSuccessCallback,
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
44 MessageHandler<OrthancApiClient::HttpErrorMessage>* orthancApiFailureCallback)
299
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
45 : IObserver(broker),
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
46 IObservable(broker),
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
47 orthancApiSuccessCallback_(orthancApiSuccessCallback),
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
48 orthancApiFailureCallback_(orthancApiFailureCallback)
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
49 {
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
50 }
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
51
301
547e1cf7aa7b cleanup
am@osimis.io
parents: 300
diff changeset
52 void ConvertResponseToJson(const IWebService::HttpRequestSuccessMessage& message)
299
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
53 {
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
54 Json::Value response;
301
547e1cf7aa7b cleanup
am@osimis.io
parents: 300
diff changeset
55 if (MessagingToolbox::ParseJson(response, message.answer_, message.answerSize_))
299
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
56 {
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
57 if (orthancApiSuccessCallback_.get() != NULL)
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
58 {
301
547e1cf7aa7b cleanup
am@osimis.io
parents: 300
diff changeset
59 orthancApiSuccessCallback_->Apply(OrthancApiClient::JsonResponseReadyMessage(message.uri_, response, message.payload_));
299
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
60 }
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
61 }
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
62 else if (orthancApiFailureCallback_.get() != NULL)
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
63 {
301
547e1cf7aa7b cleanup
am@osimis.io
parents: 300
diff changeset
64 orthancApiFailureCallback_->Apply(OrthancApiClient::HttpErrorMessage(message.uri_, message.payload_));
299
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
65 }
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
66
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
67 delete this; // hack untill we find someone to take ownership of this object (https://isocpp.org/wiki/faq/freestore-mgmt#delete-this)
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
68 }
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
69
301
547e1cf7aa7b cleanup
am@osimis.io
parents: 300
diff changeset
70 void ConvertError(const IWebService::HttpRequestErrorMessage& message)
299
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
71 {
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
72 if (orthancApiFailureCallback_.get() != NULL)
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
73 {
301
547e1cf7aa7b cleanup
am@osimis.io
parents: 300
diff changeset
74 orthancApiFailureCallback_->Apply(OrthancApiClient::HttpErrorMessage(message.uri_));
300
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
75 }
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
76
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
77 delete this; // hack untill we find someone to take ownership of this object (https://isocpp.org/wiki/faq/freestore-mgmt#delete-this)
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
78 }
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
79 };
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
80
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
81 // performs the translation between IWebService messages and OrthancApiClient messages
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
82 // TODO: handle destruction of this object (with shared_ptr ?::delete_later ???)
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
83 class HttpResponseToBinaryConverter : public IObserver, IObservable
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
84 {
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
85 std::auto_ptr<MessageHandler<OrthancApiClient::BinaryResponseReadyMessage>> orthancApiSuccessCallback_;
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
86 std::auto_ptr<MessageHandler<OrthancApiClient::HttpErrorMessage>> orthancApiFailureCallback_;
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
87 public:
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
88 HttpResponseToBinaryConverter(MessageBroker& broker,
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
89 MessageHandler<OrthancApiClient::BinaryResponseReadyMessage>* orthancApiSuccessCallback,
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
90 MessageHandler<OrthancApiClient::HttpErrorMessage>* orthancApiFailureCallback)
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
91 : IObserver(broker),
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
92 IObservable(broker),
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
93 orthancApiSuccessCallback_(orthancApiSuccessCallback),
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
94 orthancApiFailureCallback_(orthancApiFailureCallback)
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
95 {
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
96 }
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
97
301
547e1cf7aa7b cleanup
am@osimis.io
parents: 300
diff changeset
98 void ConvertResponseToBinary(const IWebService::HttpRequestSuccessMessage& message)
300
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
99 {
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
100 if (orthancApiSuccessCallback_.get() != NULL)
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
101 {
301
547e1cf7aa7b cleanup
am@osimis.io
parents: 300
diff changeset
102 orthancApiSuccessCallback_->Apply(OrthancApiClient::BinaryResponseReadyMessage(message.uri_, message.answer_, message.answerSize_, message.payload_));
300
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
103 }
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
104 else if (orthancApiFailureCallback_.get() != NULL)
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
105 {
301
547e1cf7aa7b cleanup
am@osimis.io
parents: 300
diff changeset
106 orthancApiFailureCallback_->Apply(OrthancApiClient::HttpErrorMessage(message.uri_, message.payload_));
300
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
107 }
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
108
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
109 delete this; // hack untill we find someone to take ownership of this object (https://isocpp.org/wiki/faq/freestore-mgmt#delete-this)
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
110 }
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
111
301
547e1cf7aa7b cleanup
am@osimis.io
parents: 300
diff changeset
112 void ConvertError(const IWebService::HttpRequestErrorMessage& message)
300
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
113 {
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
114 if (orthancApiFailureCallback_.get() != NULL)
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
115 {
301
547e1cf7aa7b cleanup
am@osimis.io
parents: 300
diff changeset
116 orthancApiFailureCallback_->Apply(OrthancApiClient::HttpErrorMessage(message.uri_));
299
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
117 }
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
118
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
119 delete this; // hack untill we find someone to take ownership of this object (https://isocpp.org/wiki/faq/freestore-mgmt#delete-this)
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
120 }
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
121 };
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
122
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
123 void OrthancApiClient::GetJsonAsync(const std::string& uri,
300
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
124 MessageHandler<JsonResponseReadyMessage>* successCallback,
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
125 MessageHandler<HttpErrorMessage>* failureCallback,
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
126 Orthanc::IDynamicObject* payload)
299
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
127 {
300
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
128 HttpResponseToJsonConverter* converter = new HttpResponseToJsonConverter(broker_, successCallback, failureCallback); // it is currently deleting itself after being used
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
129 orthanc_.GetAsync(uri, IWebService::Headers(), payload,
301
547e1cf7aa7b cleanup
am@osimis.io
parents: 300
diff changeset
130 new Callable<HttpResponseToJsonConverter, IWebService::HttpRequestSuccessMessage>(*converter, &HttpResponseToJsonConverter::ConvertResponseToJson),
547e1cf7aa7b cleanup
am@osimis.io
parents: 300
diff changeset
131 new Callable<HttpResponseToJsonConverter, IWebService::HttpRequestErrorMessage>(*converter, &HttpResponseToJsonConverter::ConvertError));
299
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
132
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
133 }
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
134
300
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
135 void OrthancApiClient::GetBinaryAsync(const std::string& uri,
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
136 const IWebService::Headers& headers,
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
137 MessageHandler<BinaryResponseReadyMessage>* successCallback,
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
138 MessageHandler<HttpErrorMessage>* failureCallback,
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
139 Orthanc::IDynamicObject* payload)
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
140 {
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
141 HttpResponseToBinaryConverter* converter = new HttpResponseToBinaryConverter(broker_, successCallback, failureCallback); // it is currently deleting itself after being used
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
142 orthanc_.GetAsync(uri, headers, payload,
301
547e1cf7aa7b cleanup
am@osimis.io
parents: 300
diff changeset
143 new Callable<HttpResponseToBinaryConverter, IWebService::HttpRequestSuccessMessage>(*converter, &HttpResponseToBinaryConverter::ConvertResponseToBinary),
547e1cf7aa7b cleanup
am@osimis.io
parents: 300
diff changeset
144 new Callable<HttpResponseToBinaryConverter, IWebService::HttpRequestErrorMessage>(*converter, &HttpResponseToBinaryConverter::ConvertError));
300
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
145 }
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
146
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
147 void OrthancApiClient::PostBinaryAsyncExpectJson(const std::string& uri,
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
148 const std::string& body,
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
149 MessageHandler<JsonResponseReadyMessage>* successCallback,
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
150 MessageHandler<HttpErrorMessage>* failureCallback,
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
151 Orthanc::IDynamicObject* payload)
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
152 {
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
153 HttpResponseToJsonConverter* converter = new HttpResponseToJsonConverter(broker_, successCallback, failureCallback); // it is currently deleting itself after being used
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
154 orthanc_.PostAsync(uri, IWebService::Headers(), body, payload,
301
547e1cf7aa7b cleanup
am@osimis.io
parents: 300
diff changeset
155 new Callable<HttpResponseToJsonConverter, IWebService::HttpRequestSuccessMessage>(*converter, &HttpResponseToJsonConverter::ConvertResponseToJson),
547e1cf7aa7b cleanup
am@osimis.io
parents: 300
diff changeset
156 new Callable<HttpResponseToJsonConverter, IWebService::HttpRequestErrorMessage>(*converter, &HttpResponseToJsonConverter::ConvertError));
300
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
157
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
158 }
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
159
309
14ef1227120f web services: better handling of failures
am@osimis.io
parents: 301
diff changeset
160 void OrthancApiClient::PostJsonAsyncExpectJson(const std::string& uri,
14ef1227120f web services: better handling of failures
am@osimis.io
parents: 301
diff changeset
161 const Json::Value& data,
14ef1227120f web services: better handling of failures
am@osimis.io
parents: 301
diff changeset
162 MessageHandler<JsonResponseReadyMessage>* successCallback,
14ef1227120f web services: better handling of failures
am@osimis.io
parents: 301
diff changeset
163 MessageHandler<HttpErrorMessage>* failureCallback,
14ef1227120f web services: better handling of failures
am@osimis.io
parents: 301
diff changeset
164 Orthanc::IDynamicObject* payload)
14ef1227120f web services: better handling of failures
am@osimis.io
parents: 301
diff changeset
165 {
14ef1227120f web services: better handling of failures
am@osimis.io
parents: 301
diff changeset
166 std::string body;
14ef1227120f web services: better handling of failures
am@osimis.io
parents: 301
diff changeset
167 MessagingToolbox::JsonToString(body, data);
14ef1227120f web services: better handling of failures
am@osimis.io
parents: 301
diff changeset
168 return PostBinaryAsyncExpectJson(uri, body, successCallback, failureCallback, payload);
14ef1227120f web services: better handling of failures
am@osimis.io
parents: 301
diff changeset
169 }
14ef1227120f web services: better handling of failures
am@osimis.io
parents: 301
diff changeset
170
300
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
171
270
2d64f4d39610 backup (work in progress)
am@osimis.io
parents:
diff changeset
172 }