annotate Resources/Orthanc/Stone/OrthancHttpConnection.cpp @ 237:c2863f5204a8

fix build because of update in Orthanc framework
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 05 May 2021 14:34:07 +0200
parents 1e864138f0da
children 476d5204d08b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
214
1e864138f0da upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium
196
b0bd22077cd8 sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
b0bd22077cd8 sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
212
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 196
diff changeset
8 * 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
9 * 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
10 * the License, or (at your option) any later version.
b0bd22077cd8 sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
b0bd22077cd8 sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * 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
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
212
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 196
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 196
diff changeset
15 * Lesser General Public License for more details.
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 196
diff changeset
16 *
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 196
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 196
diff changeset
18 * License along with this program. If not, see
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 196
diff changeset
19 * <http://www.gnu.org/licenses/>.
196
b0bd22077cd8 sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 **/
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 #include "OrthancHttpConnection.h"
b0bd22077cd8 sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24
b0bd22077cd8 sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 namespace OrthancStone
b0bd22077cd8 sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 {
b0bd22077cd8 sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 void OrthancHttpConnection::Setup()
b0bd22077cd8 sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 {
b0bd22077cd8 sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 url_ = client_.GetUrl();
b0bd22077cd8 sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30
b0bd22077cd8 sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 // 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
32 client_.SetRedirectionFollowed(false);
b0bd22077cd8 sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 }
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 OrthancHttpConnection::OrthancHttpConnection() :
b0bd22077cd8 sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 client_(Orthanc::WebServiceParameters(), "")
b0bd22077cd8 sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 {
b0bd22077cd8 sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 Setup();
b0bd22077cd8 sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 }
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 OrthancHttpConnection::OrthancHttpConnection(const Orthanc::WebServiceParameters& parameters) :
b0bd22077cd8 sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 client_(parameters, "")
b0bd22077cd8 sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 {
b0bd22077cd8 sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 Setup();
b0bd22077cd8 sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 }
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 void OrthancHttpConnection::RestApiGet(std::string& result,
b0bd22077cd8 sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 const std::string& uri)
b0bd22077cd8 sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 {
b0bd22077cd8 sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 boost::mutex::scoped_lock lock(mutex_);
b0bd22077cd8 sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54
b0bd22077cd8 sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 client_.SetMethod(Orthanc::HttpMethod_Get);
b0bd22077cd8 sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 client_.SetUrl(url_ + uri);
b0bd22077cd8 sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 client_.ApplyAndThrowException(result);
b0bd22077cd8 sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 }
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 void OrthancHttpConnection::RestApiPost(std::string& result,
b0bd22077cd8 sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 const std::string& uri,
b0bd22077cd8 sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 const std::string& body)
b0bd22077cd8 sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 {
b0bd22077cd8 sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 boost::mutex::scoped_lock lock(mutex_);
b0bd22077cd8 sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66
b0bd22077cd8 sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 client_.SetMethod(Orthanc::HttpMethod_Post);
b0bd22077cd8 sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 client_.SetUrl(url_ + uri);
237
c2863f5204a8 fix build because of update in Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 214
diff changeset
69 client_.SetExternalBody(body);
196
b0bd22077cd8 sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 client_.ApplyAndThrowException(result);
237
c2863f5204a8 fix build because of update in Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 214
diff changeset
71 client_.ClearBody();
196
b0bd22077cd8 sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 }
b0bd22077cd8 sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73
b0bd22077cd8 sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74
b0bd22077cd8 sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 void OrthancHttpConnection::RestApiPut(std::string& result,
b0bd22077cd8 sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 const std::string& uri,
b0bd22077cd8 sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 const std::string& body)
b0bd22077cd8 sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 {
b0bd22077cd8 sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 boost::mutex::scoped_lock lock(mutex_);
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 client_.SetMethod(Orthanc::HttpMethod_Put);
b0bd22077cd8 sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 client_.SetUrl(url_ + uri);
237
c2863f5204a8 fix build because of update in Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 214
diff changeset
83 client_.SetExternalBody(body);
196
b0bd22077cd8 sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 client_.ApplyAndThrowException(result);
237
c2863f5204a8 fix build because of update in Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 214
diff changeset
85 client_.ClearBody();
196
b0bd22077cd8 sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 }
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
b0bd22077cd8 sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 void OrthancHttpConnection::RestApiDelete(const std::string& uri)
b0bd22077cd8 sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 {
b0bd22077cd8 sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 boost::mutex::scoped_lock lock(mutex_);
b0bd22077cd8 sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92
b0bd22077cd8 sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 std::string result;
b0bd22077cd8 sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94
b0bd22077cd8 sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 client_.SetMethod(Orthanc::HttpMethod_Delete);
b0bd22077cd8 sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 client_.SetUrl(url_ + uri);
b0bd22077cd8 sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 client_.ApplyAndThrowException(result);
b0bd22077cd8 sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 }
b0bd22077cd8 sharing code with orthanc-stone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 }