Mercurial > hg > orthanc-wsi
annotate Resources/Orthanc/Stone/OrthancHttpConnection.cpp @ 294:b28c815a625f OrthancWSI-2.0
OrthancWSI-2.0
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 13 Jul 2023 18:16:04 +0200 |
parents | 04ea47a422d1 |
children | 7020852a8fa9 |
rev | line source |
---|---|
196
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1 /** |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2 * Stone of Orthanc |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
283 | 5 * Copyright (C) 2017-2023 Osimis S.A., Belgium |
6 * Copyright (C) 2021-2023 Sebastien Jodogne, ICTEAM UCLouvain, Belgium | |
196
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
7 * |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 * This program is free software: you can redistribute it and/or |
212 | 9 * modify it under the terms of the GNU Lesser General Public License |
196
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
10 * as published by the Free Software Foundation, either version 3 of |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
11 * the License, or (at your option) any later version. |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 * |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 * This program is distributed in the hope that it will be useful, but |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 * WITHOUT ANY WARRANTY; without even the implied warranty of |
212 | 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
16 * Lesser General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU Lesser General Public | |
19 * License along with this program. If not, see | |
20 * <http://www.gnu.org/licenses/>. | |
196
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
21 **/ |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
23 |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 #include "OrthancHttpConnection.h" |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
25 |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 namespace OrthancStone |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 { |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
28 void OrthancHttpConnection::Setup() |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
29 { |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
30 url_ = client_.GetUrl(); |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
31 |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
32 // Don't follow 3xx HTTP (avoid redirections to "unsupported.png" in Orthanc) |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
33 client_.SetRedirectionFollowed(false); |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
34 } |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
35 |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
36 |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
37 OrthancHttpConnection::OrthancHttpConnection() : |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
38 client_(Orthanc::WebServiceParameters(), "") |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
39 { |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
40 Setup(); |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
41 } |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
42 |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
43 |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
44 OrthancHttpConnection::OrthancHttpConnection(const Orthanc::WebServiceParameters& parameters) : |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
45 client_(parameters, "") |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
46 { |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
47 Setup(); |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
48 } |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
49 |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
50 |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
51 void OrthancHttpConnection::RestApiGet(std::string& result, |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
52 const std::string& uri) |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
53 { |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
54 boost::mutex::scoped_lock lock(mutex_); |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
55 |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
56 client_.SetMethod(Orthanc::HttpMethod_Get); |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
57 client_.SetUrl(url_ + uri); |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
58 client_.ApplyAndThrowException(result); |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
59 } |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
60 |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
61 |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
62 void OrthancHttpConnection::RestApiPost(std::string& result, |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
63 const std::string& uri, |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
64 const std::string& body) |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
65 { |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
66 boost::mutex::scoped_lock lock(mutex_); |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
67 |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
68 client_.SetMethod(Orthanc::HttpMethod_Post); |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
69 client_.SetUrl(url_ + uri); |
238 | 70 |
71 #if defined(ORTHANC_FRAMEWORK_VERSION_IS_ABOVE) && ORTHANC_FRAMEWORK_VERSION_IS_ABOVE(1, 9, 3) | |
237
c2863f5204a8
fix build because of update in Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
214
diff
changeset
|
72 client_.SetExternalBody(body); |
196
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
73 client_.ApplyAndThrowException(result); |
237
c2863f5204a8
fix build because of update in Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
214
diff
changeset
|
74 client_.ClearBody(); |
238 | 75 #else |
76 client_.SetBody(body); | |
77 client_.ApplyAndThrowException(result); | |
78 #endif | |
196
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
79 } |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
80 |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
81 |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
82 void OrthancHttpConnection::RestApiPut(std::string& result, |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
83 const std::string& uri, |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
84 const std::string& body) |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
85 { |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
86 boost::mutex::scoped_lock lock(mutex_); |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
87 |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
88 client_.SetMethod(Orthanc::HttpMethod_Put); |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
89 client_.SetUrl(url_ + uri); |
238 | 90 |
91 #if defined(ORTHANC_FRAMEWORK_VERSION_IS_ABOVE) && ORTHANC_FRAMEWORK_VERSION_IS_ABOVE(1, 9, 3) | |
237
c2863f5204a8
fix build because of update in Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
214
diff
changeset
|
92 client_.SetExternalBody(body); |
196
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
93 client_.ApplyAndThrowException(result); |
237
c2863f5204a8
fix build because of update in Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
214
diff
changeset
|
94 client_.ClearBody(); |
238 | 95 #else |
96 client_.SetBody(body); | |
97 client_.ApplyAndThrowException(result); | |
98 #endif | |
196
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
99 } |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
100 |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
101 |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
102 void OrthancHttpConnection::RestApiDelete(const std::string& uri) |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
103 { |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
104 boost::mutex::scoped_lock lock(mutex_); |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
105 |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
106 std::string result; |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
107 |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
108 client_.SetMethod(Orthanc::HttpMethod_Delete); |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
109 client_.SetUrl(url_ + uri); |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
110 client_.ApplyAndThrowException(result); |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
111 } |
b0bd22077cd8
sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
112 } |