annotate Framework/Toolbox/OrthancApiClient.cpp @ 424:bb573a52fc63 am-vsol-upgrade

allow POST messages with success and failure handlers
author am@osimis.io
date Wed, 21 Nov 2018 17:08:03 +0100
parents 4fe42ae3653a
children b85f635f1eb5
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"
309
14ef1227120f web services: better handling of failures
am@osimis.io
parents: 301
diff changeset
24 #include "Framework/Toolbox/MessagingToolbox.h"
270
2d64f4d39610 backup (work in progress)
am@osimis.io
parents:
diff changeset
25
377
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
26 #include <Core/OrthancException.h>
270
2d64f4d39610 backup (work in progress)
am@osimis.io
parents:
diff changeset
27
377
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
28 namespace OrthancStone
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
29 {
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
30 const Orthanc::IDynamicObject& OrthancApiClient::JsonResponseReadyMessage::GetPayload() const
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
31 {
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
32 if (HasPayload())
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
33 {
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
34 return *payload_;
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
35 }
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
36 else
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
37 {
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
38 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
39 }
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
40 }
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
41
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
42
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
43 const Orthanc::IDynamicObject& OrthancApiClient::BinaryResponseReadyMessage::GetPayload() const
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
44 {
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
45 if (HasPayload())
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
46 {
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
47 return *payload_;
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
48 }
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
49 else
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
50 {
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
51 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
52 }
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
53 }
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
54
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
55
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
56 const Orthanc::IDynamicObject& OrthancApiClient::EmptyResponseReadyMessage::GetPayload() const
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
57 {
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
58 if (HasPayload())
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
59 {
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
60 return *payload_;
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
61 }
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
62 else
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
63 {
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
64 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
65 }
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
66 }
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
67
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
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 }
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
167 };
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
168
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
169
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
170 class OrthancApiClient::CachedHttpRequestSuccessMessage
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
171 {
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
172 protected:
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
173 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
174 void* answer_;
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
175 size_t answerSize_;
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
176 IWebService::HttpHeaders answerHeaders_;
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
177
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
178 public:
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
179 CachedHttpRequestSuccessMessage(const IWebService::HttpRequestSuccessMessage& message) :
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
180 uri_(message.GetUri()),
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
181 answerSize_(message.GetAnswerSize()),
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
182 answerHeaders_(message.GetAnswerHttpHeaders())
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
183 {
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
184 answer_ = malloc(answerSize_);
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
185 memcpy(answer_, message.GetAnswer(), answerSize_);
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
186 }
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
187
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
188 ~CachedHttpRequestSuccessMessage()
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
189 {
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
190 free(answer_);
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
191 }
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
192
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
193 const std::string& GetUri() const
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
194 {
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
195 return uri_;
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
196 }
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
197
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
198 const void* GetAnswer() const
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
199 {
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
200 return answer_;
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
201 }
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
202
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
203 size_t GetAnswerSize() const
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
204 {
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
205 return answerSize_;
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
206 }
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
207
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
208 const IWebService::HttpHeaders& GetAnswerHttpHeaders() const
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
209 {
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
210 return answerHeaders_;
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
211 }
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
212
383
939f626eb6d7 removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 382
diff changeset
213 };
939f626eb6d7 removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 382
diff changeset
214
939f626eb6d7 removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 382
diff changeset
215
382
dd4c7e82b4be removed class OrthancApiClient::HttpErrorMessage, redundant with IWebService::HttpRequestErrorMessage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 377
diff changeset
216 OrthancApiClient::OrthancApiClient(MessageBroker& broker,
417
aee3d7941c9b preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 383
diff changeset
217 IWebService& web,
aee3d7941c9b preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 383
diff changeset
218 const std::string& baseUrl) :
377
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 334
diff changeset
219 IObservable(broker),
383
939f626eb6d7 removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 382
diff changeset
220 IObserver(broker),
417
aee3d7941c9b preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 383
diff changeset
221 web_(web),
422
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
222 baseUrl_(baseUrl),
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
223 cacheEnabled_(true)
270
2d64f4d39610 backup (work in progress)
am@osimis.io
parents:
diff changeset
224 {
2d64f4d39610 backup (work in progress)
am@osimis.io
parents:
diff changeset
225 }
2d64f4d39610 backup (work in progress)
am@osimis.io
parents:
diff changeset
226
334
c34784e5f299 compatibility fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
227
383
939f626eb6d7 removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 382
diff changeset
228 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
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 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
231 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
232 Orthanc::IDynamicObject* payload)
300
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
233 {
422
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
234 IWebService::HttpHeaders emptyHeaders;
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
235 if (cacheEnabled_)
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
236 {
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
237 HandleFromCache(baseUrl_ + uri,
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
238 emptyHeaders,
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
239 new WebServicePayload(successCallback, failureCallback, payload));
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
240 }
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
241 else
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
242 {
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
243 web_.GetAsync(baseUrl_ + uri,
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
244 emptyHeaders,
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
245 new WebServicePayload(successCallback, failureCallback, payload),
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
246 new Callable<OrthancApiClient, IWebService::HttpRequestSuccessMessage>
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
247 (*this, &OrthancApiClient::NotifyHttpSuccess),
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
248 new Callable<OrthancApiClient, IWebService::HttpRequestErrorMessage>
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
249 (*this, &OrthancApiClient::NotifyHttpError));
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
250 }
299
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
251 }
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 271
diff changeset
252
382
dd4c7e82b4be removed class OrthancApiClient::HttpErrorMessage, redundant with IWebService::HttpRequestErrorMessage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 377
diff changeset
253
383
939f626eb6d7 removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 382
diff changeset
254 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
255 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
256 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
257 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
258 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
259 Orthanc::IDynamicObject* payload)
382
dd4c7e82b4be removed class OrthancApiClient::HttpErrorMessage, redundant with IWebService::HttpRequestErrorMessage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 377
diff changeset
260 {
417
aee3d7941c9b preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 383
diff changeset
261 IWebService::HttpHeaders headers;
382
dd4c7e82b4be removed class OrthancApiClient::HttpErrorMessage, redundant with IWebService::HttpRequestErrorMessage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 377
diff changeset
262 headers["Accept"] = contentType;
dd4c7e82b4be removed class OrthancApiClient::HttpErrorMessage, redundant with IWebService::HttpRequestErrorMessage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 377
diff changeset
263 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
264 }
dd4c7e82b4be removed class OrthancApiClient::HttpErrorMessage, redundant with IWebService::HttpRequestErrorMessage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 377
diff changeset
265
dd4c7e82b4be removed class OrthancApiClient::HttpErrorMessage, redundant with IWebService::HttpRequestErrorMessage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 377
diff changeset
266
422
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
267 void OrthancApiClient::HandleFromCache(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
268 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
269 Orthanc::IDynamicObject* payload // takes ownership
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
270 )
300
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
271 {
422
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
272 if (cache_.find(uri) == cache_.end())
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
273 {
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
274 web_.GetAsync(uri, headers,
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
275 payload, // ownership is transfered
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
276 new Callable<OrthancApiClient, IWebService::HttpRequestSuccessMessage>
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
277 (*this, &OrthancApiClient::CacheAndNotifyHttpSuccess),
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
278 new Callable<OrthancApiClient, IWebService::HttpRequestErrorMessage>
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
279 (*this, &OrthancApiClient::NotifyHttpError));
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
280 }
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
281 else
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
282 {
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
283 std::auto_ptr<Orthanc::IDynamicObject> payloadRaii(payload); // make sure payload is deleted whatever happens
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
284
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
285 const OrthancApiClient::CachedHttpRequestSuccessMessage& cachedMessage = *(cache_[uri]);
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
286 IWebService::HttpRequestSuccessMessage successMessage(cachedMessage.GetUri(),
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
287 cachedMessage.GetAnswer(),
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
288 cachedMessage.GetAnswerSize(),
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
289 cachedMessage.GetAnswerHttpHeaders(),
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
290 payloadRaii.get());
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
291 NotifyHttpSuccess(successMessage);
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
292 }
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
293
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
294 }
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
295
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
296
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
297 void OrthancApiClient::GetBinaryAsync(
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
298 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
299 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
300 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
301 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
302 Orthanc::IDynamicObject* payload)
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
303 {
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
304 // 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
305
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
306 if (cacheEnabled_)
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
307 {
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
308 HandleFromCache(baseUrl_ + uri,
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
309 headers,
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
310 new WebServicePayload(successCallback, failureCallback, payload));
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
311 }
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
312 else
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
313 {
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
314 web_.GetAsync(baseUrl_ + uri, headers,
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
315 new WebServicePayload(successCallback, failureCallback, payload),
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
316 new Callable<OrthancApiClient, IWebService::HttpRequestSuccessMessage>
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
317 (*this, &OrthancApiClient::NotifyHttpSuccess),
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
318 new Callable<OrthancApiClient, IWebService::HttpRequestErrorMessage>
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
319 (*this, &OrthancApiClient::NotifyHttpError));
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
320 }
300
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
321 }
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
322
382
dd4c7e82b4be removed class OrthancApiClient::HttpErrorMessage, redundant with IWebService::HttpRequestErrorMessage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 377
diff changeset
323
383
939f626eb6d7 removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 382
diff changeset
324 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
325 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
326 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
327 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
328 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
329 Orthanc::IDynamicObject* payload)
300
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
330 {
417
aee3d7941c9b preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 383
diff changeset
331 web_.PostAsync(baseUrl_ + uri, IWebService::HttpHeaders(), body,
aee3d7941c9b preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 383
diff changeset
332 new WebServicePayload(successCallback, failureCallback, payload),
aee3d7941c9b preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 383
diff changeset
333 new Callable<OrthancApiClient, IWebService::HttpRequestSuccessMessage>
aee3d7941c9b preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 383
diff changeset
334 (*this, &OrthancApiClient::NotifyHttpSuccess),
aee3d7941c9b preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 383
diff changeset
335 new Callable<OrthancApiClient, IWebService::HttpRequestErrorMessage>
aee3d7941c9b preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 383
diff changeset
336 (*this, &OrthancApiClient::NotifyHttpError));
300
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
337
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
338 }
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
339
424
bb573a52fc63 allow POST messages with success and failure handlers
am@osimis.io
parents: 422
diff changeset
340 void OrthancApiClient::PostBinaryAsync(
bb573a52fc63 allow POST messages with success and failure handlers
am@osimis.io
parents: 422
diff changeset
341 const std::string& uri,
bb573a52fc63 allow POST messages with success and failure handlers
am@osimis.io
parents: 422
diff changeset
342 const std::string& body)
bb573a52fc63 allow POST messages with success and failure handlers
am@osimis.io
parents: 422
diff changeset
343 {
bb573a52fc63 allow POST messages with success and failure handlers
am@osimis.io
parents: 422
diff changeset
344 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
345 }
bb573a52fc63 allow POST messages with success and failure handlers
am@osimis.io
parents: 422
diff changeset
346
383
939f626eb6d7 removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 382
diff changeset
347 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
348 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
349 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
350 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
351 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
352 Orthanc::IDynamicObject* payload)
309
14ef1227120f web services: better handling of failures
am@osimis.io
parents: 301
diff changeset
353 {
14ef1227120f web services: better handling of failures
am@osimis.io
parents: 301
diff changeset
354 std::string body;
14ef1227120f web services: better handling of failures
am@osimis.io
parents: 301
diff changeset
355 MessagingToolbox::JsonToString(body, data);
14ef1227120f web services: better handling of failures
am@osimis.io
parents: 301
diff changeset
356 return PostBinaryAsyncExpectJson(uri, body, successCallback, failureCallback, payload);
14ef1227120f web services: better handling of failures
am@osimis.io
parents: 301
diff changeset
357 }
14ef1227120f web services: better handling of failures
am@osimis.io
parents: 301
diff changeset
358
424
bb573a52fc63 allow POST messages with success and failure handlers
am@osimis.io
parents: 422
diff changeset
359 void OrthancApiClient::PostJsonAsync(
bb573a52fc63 allow POST messages with success and failure handlers
am@osimis.io
parents: 422
diff changeset
360 const std::string& uri,
bb573a52fc63 allow POST messages with success and failure handlers
am@osimis.io
parents: 422
diff changeset
361 const Json::Value& data)
bb573a52fc63 allow POST messages with success and failure handlers
am@osimis.io
parents: 422
diff changeset
362 {
bb573a52fc63 allow POST messages with success and failure handlers
am@osimis.io
parents: 422
diff changeset
363 std::string body;
bb573a52fc63 allow POST messages with success and failure handlers
am@osimis.io
parents: 422
diff changeset
364 MessagingToolbox::JsonToString(body, data);
bb573a52fc63 allow POST messages with success and failure handlers
am@osimis.io
parents: 422
diff changeset
365 return PostBinaryAsync(uri, body);
bb573a52fc63 allow POST messages with success and failure handlers
am@osimis.io
parents: 422
diff changeset
366 }
bb573a52fc63 allow POST messages with success and failure handlers
am@osimis.io
parents: 422
diff changeset
367
383
939f626eb6d7 removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 382
diff changeset
368 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
369 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
370 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
371 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
372 Orthanc::IDynamicObject* payload)
315
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
373 {
417
aee3d7941c9b preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 383
diff changeset
374 web_.DeleteAsync(baseUrl_ + uri, IWebService::HttpHeaders(),
aee3d7941c9b preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 383
diff changeset
375 new WebServicePayload(successCallback, failureCallback, payload),
aee3d7941c9b preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 383
diff changeset
376 new Callable<OrthancApiClient, IWebService::HttpRequestSuccessMessage>
aee3d7941c9b preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 383
diff changeset
377 (*this, &OrthancApiClient::NotifyHttpSuccess),
aee3d7941c9b preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 383
diff changeset
378 new Callable<OrthancApiClient, IWebService::HttpRequestErrorMessage>
aee3d7941c9b preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 383
diff changeset
379 (*this, &OrthancApiClient::NotifyHttpError));
315
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
380 }
aad37d0b6407 Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents: 309
diff changeset
381
300
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
382
383
939f626eb6d7 removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 382
diff changeset
383 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
384 {
383
939f626eb6d7 removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 382
diff changeset
385 if (message.HasPayload())
939f626eb6d7 removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 382
diff changeset
386 {
939f626eb6d7 removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 382
diff changeset
387 dynamic_cast<const WebServicePayload&>(message.GetPayload()).HandleSuccess(message);
939f626eb6d7 removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 382
diff changeset
388 }
939f626eb6d7 removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 382
diff changeset
389 else
939f626eb6d7 removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 382
diff changeset
390 {
939f626eb6d7 removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 382
diff changeset
391 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
939f626eb6d7 removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 382
diff changeset
392 }
939f626eb6d7 removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 382
diff changeset
393 }
939f626eb6d7 removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 382
diff changeset
394
422
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
395 void OrthancApiClient::CacheAndNotifyHttpSuccess(const IWebService::HttpRequestSuccessMessage& message)
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
396 {
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
397 cache_[message.GetUri()] = boost::shared_ptr<CachedHttpRequestSuccessMessage>(new CachedHttpRequestSuccessMessage(message));
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
398 NotifyHttpSuccess(message);
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
399 }
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
400
383
939f626eb6d7 removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 382
diff changeset
401 void OrthancApiClient::NotifyHttpError(const IWebService::HttpRequestErrorMessage& message)
939f626eb6d7 removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 382
diff changeset
402 {
939f626eb6d7 removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 382
diff changeset
403 if (message.HasPayload())
939f626eb6d7 removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 382
diff changeset
404 {
939f626eb6d7 removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 382
diff changeset
405 dynamic_cast<const WebServicePayload&>(message.GetPayload()).HandleFailure(message);
939f626eb6d7 removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 382
diff changeset
406 }
939f626eb6d7 removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 382
diff changeset
407 else
939f626eb6d7 removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 382
diff changeset
408 {
939f626eb6d7 removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 382
diff changeset
409 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
939f626eb6d7 removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 382
diff changeset
410 }
422
4fe42ae3653a introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents: 418
diff changeset
411 }
270
2d64f4d39610 backup (work in progress)
am@osimis.io
parents:
diff changeset
412 }