Mercurial > hg > orthanc-stone
annotate OrthancStone/Sources/Toolbox/OrthancDatasets/OrthancHttpConnection.cpp @ 1942:09de7321d3b9
TODO
author | Alain Mazy <am@osimis.io> |
---|---|
date | Mon, 16 May 2022 16:27:41 +0200 |
parents | 7053b8a0aaec |
children | 07964689cb0b |
rev | line source |
---|---|
1504 | 1 /** |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
1871
7053b8a0aaec
upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1870
diff
changeset
|
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium |
7053b8a0aaec
upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1870
diff
changeset
|
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
1504 | 7 * |
8 * This program is free software: you can redistribute it and/or | |
1598
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
9 * modify it under the terms of the GNU Lesser General Public License |
1504 | 10 * as published by the Free Software Foundation, either version 3 of |
11 * the License, or (at your option) any later version. | |
12 * | |
13 * This program is distributed in the hope that it will be useful, but | |
14 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
1598
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
16 * Lesser General Public License for more details. |
1596
4fb8fdf03314
removed annoying whitespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
17 * |
1598
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
18 * You should have received a copy of the GNU Lesser General Public |
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
19 * License along with this program. If not, see |
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
20 * <http://www.gnu.org/licenses/>. |
1504 | 21 **/ |
22 | |
23 | |
24 #include "OrthancHttpConnection.h" | |
25 | |
26 namespace OrthancStone | |
27 { | |
28 void OrthancHttpConnection::Setup() | |
29 { | |
30 url_ = client_.GetUrl(); | |
31 | |
32 // Don't follow 3xx HTTP (avoid redirections to "unsupported.png" in Orthanc) | |
33 client_.SetRedirectionFollowed(false); | |
34 } | |
35 | |
36 | |
37 OrthancHttpConnection::OrthancHttpConnection() : | |
38 client_(Orthanc::WebServiceParameters(), "") | |
39 { | |
40 Setup(); | |
41 } | |
42 | |
43 | |
44 OrthancHttpConnection::OrthancHttpConnection(const Orthanc::WebServiceParameters& parameters) : | |
45 client_(parameters, "") | |
46 { | |
47 Setup(); | |
48 } | |
49 | |
50 | |
51 void OrthancHttpConnection::RestApiGet(std::string& result, | |
52 const std::string& uri) | |
53 { | |
54 boost::mutex::scoped_lock lock(mutex_); | |
55 | |
56 client_.SetMethod(Orthanc::HttpMethod_Get); | |
57 client_.SetUrl(url_ + uri); | |
58 client_.ApplyAndThrowException(result); | |
59 } | |
60 | |
61 | |
62 void OrthancHttpConnection::RestApiPost(std::string& result, | |
63 const std::string& uri, | |
64 const std::string& body) | |
65 { | |
66 boost::mutex::scoped_lock lock(mutex_); | |
67 | |
68 client_.SetMethod(Orthanc::HttpMethod_Post); | |
69 client_.SetUrl(url_ + uri); | |
1776
d3d883c3af65
backward compatibility with Orthanc framework <= 1.9.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1760
diff
changeset
|
70 |
d3d883c3af65
backward compatibility with Orthanc framework <= 1.9.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1760
diff
changeset
|
71 #if defined(ORTHANC_FRAMEWORK_VERSION_IS_ABOVE) && ORTHANC_FRAMEWORK_VERSION_IS_ABOVE(1, 9, 3) |
1760
e38b9875a969
adaptation to change in API of Orthanc::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
72 client_.SetExternalBody(body); |
1504 | 73 client_.ApplyAndThrowException(result); |
1760
e38b9875a969
adaptation to change in API of Orthanc::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
74 client_.ClearBody(); |
1776
d3d883c3af65
backward compatibility with Orthanc framework <= 1.9.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1760
diff
changeset
|
75 #else |
d3d883c3af65
backward compatibility with Orthanc framework <= 1.9.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1760
diff
changeset
|
76 client_.SetBody(body); |
d3d883c3af65
backward compatibility with Orthanc framework <= 1.9.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1760
diff
changeset
|
77 client_.ApplyAndThrowException(result); |
d3d883c3af65
backward compatibility with Orthanc framework <= 1.9.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1760
diff
changeset
|
78 #endif |
1504 | 79 } |
80 | |
81 | |
82 void OrthancHttpConnection::RestApiPut(std::string& result, | |
83 const std::string& uri, | |
84 const std::string& body) | |
85 { | |
86 boost::mutex::scoped_lock lock(mutex_); | |
87 | |
88 client_.SetMethod(Orthanc::HttpMethod_Put); | |
89 client_.SetUrl(url_ + uri); | |
1776
d3d883c3af65
backward compatibility with Orthanc framework <= 1.9.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1760
diff
changeset
|
90 |
d3d883c3af65
backward compatibility with Orthanc framework <= 1.9.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1760
diff
changeset
|
91 #if defined(ORTHANC_FRAMEWORK_VERSION_IS_ABOVE) && ORTHANC_FRAMEWORK_VERSION_IS_ABOVE(1, 9, 3) |
1760
e38b9875a969
adaptation to change in API of Orthanc::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
92 client_.SetExternalBody(body); |
1504 | 93 client_.ApplyAndThrowException(result); |
1760
e38b9875a969
adaptation to change in API of Orthanc::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
94 client_.ClearBody(); |
1776
d3d883c3af65
backward compatibility with Orthanc framework <= 1.9.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1760
diff
changeset
|
95 #else |
d3d883c3af65
backward compatibility with Orthanc framework <= 1.9.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1760
diff
changeset
|
96 client_.SetBody(body); |
d3d883c3af65
backward compatibility with Orthanc framework <= 1.9.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1760
diff
changeset
|
97 client_.ApplyAndThrowException(result); |
d3d883c3af65
backward compatibility with Orthanc framework <= 1.9.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1760
diff
changeset
|
98 #endif |
1504 | 99 } |
100 | |
101 | |
102 void OrthancHttpConnection::RestApiDelete(const std::string& uri) | |
103 { | |
104 boost::mutex::scoped_lock lock(mutex_); | |
105 | |
106 std::string result; | |
107 | |
108 client_.SetMethod(Orthanc::HttpMethod_Delete); | |
109 client_.SetUrl(url_ + uri); | |
110 client_.ApplyAndThrowException(result); | |
111 } | |
112 } |