annotate Platforms/Generic/WebServicePostCommand.cpp @ 208:db70f6c5fa4f

sync
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 11 Apr 2018 16:27:09 +0200
parents e9c7a78a3e77
children 5412adf19980
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
80
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Stone of Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
135
e2fe9352f240 upgrade to year 2018
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 123
diff changeset
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium
80
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * the License, or (at your option) any later version.
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * Affero General Public License for more details.
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 *
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * You should have received a copy of the GNU Affero General Public License
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 **/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 #include "WebServicePostCommand.h"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
201
e9c7a78a3e77 removed absolute paths
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
24 #include "../../Resources/Orthanc/Core/HttpClient.h"
80
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 namespace OrthancStone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 WebServicePostCommand::WebServicePostCommand(IWebService::ICallback& callback,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 const Orthanc::WebServiceParameters& parameters,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 const std::string& uri,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 const std::string& body,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 Orthanc::IDynamicObject* payload /* takes ownership */) :
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 callback_(callback),
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 parameters_(parameters),
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 uri_(uri),
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 body_(body),
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 payload_(payload)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 void WebServicePostCommand::Execute()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 Orthanc::HttpClient client(parameters_, uri_);
123
ed0003f6102c dynamic loading of rt-struct renderers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
44 client.SetTimeout(60);
80
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 client.SetMethod(Orthanc::HttpMethod_Post);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 client.GetBody().swap(body_);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 success_ = client.Apply(answer_);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 void WebServicePostCommand::Commit()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 if (success_)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 callback_.NotifySuccess(uri_, answer_.c_str(), answer_.size(), payload_.release());
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 else
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 callback_.NotifyError(uri_, payload_.release());
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 }