Mercurial > hg > orthanc-stone
annotate Framework/Oracle/HttpCommand.cpp @ 1135:a0a33e5ea5bb broker
IOracleCommand::Clone()
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 06 Nov 2019 17:34:58 +0100 |
parents | 87fbeb823375 |
children | 0ca50d275b9a |
rev | line source |
---|---|
979 | 1 /** |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium | |
6 * | |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU Affero General Public License | |
9 * as published by the Free Software Foundation, either version 3 of | |
10 * the License, or (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, but | |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * Affero General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Affero General Public License | |
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 **/ | |
20 | |
21 | |
22 #include "HttpCommand.h" | |
23 | |
24 #include <Core/OrthancException.h> | |
25 | |
26 #include <json/reader.h> | |
27 #include <json/writer.h> | |
28 | |
29 namespace OrthancStone | |
30 { | |
31 void HttpCommand::SuccessMessage::ParseJsonBody(Json::Value& target) const | |
32 { | |
33 Json::Reader reader; | |
34 if (!reader.parse(answer_, target)) | |
35 { | |
36 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); | |
37 } | |
38 } | |
39 | |
40 | |
41 HttpCommand::HttpCommand() : | |
42 method_(Orthanc::HttpMethod_Get), | |
43 url_("/"), | |
44 timeout_(600) | |
45 { | |
46 } | |
47 | |
48 | |
49 void HttpCommand::SetBody(const Json::Value& json) | |
50 { | |
51 Json::FastWriter writer; | |
52 body_ = writer.write(json); | |
53 } | |
54 | |
55 | |
56 const std::string& HttpCommand::GetBody() const | |
57 { | |
58 if (method_ == Orthanc::HttpMethod_Post || | |
59 method_ == Orthanc::HttpMethod_Put) | |
60 { | |
61 return body_; | |
62 } | |
63 else | |
64 { | |
65 LOG(ERROR) << "HttpCommand::GetBody(): method_ not _Post or _Put"; | |
66 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
67 } | |
68 } | |
1079
e6d2ff8f1ab4
credentials in HttpCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
979
diff
changeset
|
69 |
e6d2ff8f1ab4
credentials in HttpCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
979
diff
changeset
|
70 |
e6d2ff8f1ab4
credentials in HttpCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
979
diff
changeset
|
71 const std::string& HttpCommand::GetUsername() const |
e6d2ff8f1ab4
credentials in HttpCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
979
diff
changeset
|
72 { |
e6d2ff8f1ab4
credentials in HttpCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
979
diff
changeset
|
73 if (HasCredentials()) |
e6d2ff8f1ab4
credentials in HttpCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
979
diff
changeset
|
74 { |
e6d2ff8f1ab4
credentials in HttpCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
979
diff
changeset
|
75 return username_; |
e6d2ff8f1ab4
credentials in HttpCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
979
diff
changeset
|
76 } |
e6d2ff8f1ab4
credentials in HttpCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
979
diff
changeset
|
77 else |
e6d2ff8f1ab4
credentials in HttpCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
979
diff
changeset
|
78 { |
e6d2ff8f1ab4
credentials in HttpCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
979
diff
changeset
|
79 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
e6d2ff8f1ab4
credentials in HttpCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
979
diff
changeset
|
80 } |
e6d2ff8f1ab4
credentials in HttpCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
979
diff
changeset
|
81 } |
e6d2ff8f1ab4
credentials in HttpCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
979
diff
changeset
|
82 |
e6d2ff8f1ab4
credentials in HttpCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
979
diff
changeset
|
83 |
e6d2ff8f1ab4
credentials in HttpCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
979
diff
changeset
|
84 const std::string& HttpCommand::GetPassword() const |
e6d2ff8f1ab4
credentials in HttpCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
979
diff
changeset
|
85 { |
e6d2ff8f1ab4
credentials in HttpCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
979
diff
changeset
|
86 if (HasCredentials()) |
e6d2ff8f1ab4
credentials in HttpCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
979
diff
changeset
|
87 { |
e6d2ff8f1ab4
credentials in HttpCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
979
diff
changeset
|
88 return password_; |
e6d2ff8f1ab4
credentials in HttpCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
979
diff
changeset
|
89 } |
e6d2ff8f1ab4
credentials in HttpCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
979
diff
changeset
|
90 else |
e6d2ff8f1ab4
credentials in HttpCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
979
diff
changeset
|
91 { |
e6d2ff8f1ab4
credentials in HttpCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
979
diff
changeset
|
92 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
e6d2ff8f1ab4
credentials in HttpCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
979
diff
changeset
|
93 } |
e6d2ff8f1ab4
credentials in HttpCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
979
diff
changeset
|
94 } |
979 | 95 } |