annotate OrthancServer/Sources/ServerJobs/Operations/StorePeerOperation.cpp @ 5449:29858f424fc7

fix framework md5
author Alain Mazy <am@osimis.io>
date Wed, 29 Nov 2023 09:28:21 +0100
parents 0ea402b4d901
children 48b8dae6dc77
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2605
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
5185
0ea402b4d901 upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium
0ea402b4d901 upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
6 * Copyright (C) 2021-2023 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
2605
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 *
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * This program is free software: you can redistribute it and/or
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * modify it under the terms of the GNU General Public License as
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * published by the Free Software Foundation, either version 3 of the
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * License, or (at your option) any later version.
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 *
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful, but
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * General Public License for more details.
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 *
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 **/
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
2641
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2616
diff changeset
23 #include "../../PrecompiledHeadersServer.h"
2605
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #include "StorePeerOperation.h"
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 #include "DicomInstanceOperationValue.h"
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27
4045
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
28 #include "../../../../OrthancFramework/Sources/Logging.h"
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
29 #include "../../../../OrthancFramework/Sources/OrthancException.h"
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
30 #include "../../../../OrthancFramework/Sources/HttpClient.h"
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
31 #include "../../../../OrthancFramework/Sources/SerializationToolbox.h"
2605
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 namespace Orthanc
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 {
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 void StorePeerOperation::Apply(JobOperationValues& outputs,
4310
2ae905070221 renaming pure interface JobOperationValue as IJobOperationValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
36 const IJobOperationValue& input)
2605
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 {
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 // Configure the HTTP client
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 HttpClient client(peer_, "instances");
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 client.SetMethod(HttpMethod_Post);
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41
4310
2ae905070221 renaming pure interface JobOperationValue as IJobOperationValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
42 if (input.GetType() != IJobOperationValue::Type_DicomInstance)
2605
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 {
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 throw OrthancException(ErrorCode_BadParameterType);
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 }
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46
2608
25225f0b4f33 simplification wrt. dicom connection manager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2606
diff changeset
47 const DicomInstanceOperationValue& instance =
25225f0b4f33 simplification wrt. dicom connection manager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2606
diff changeset
48 dynamic_cast<const DicomInstanceOperationValue&>(input);
2605
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 LOG(INFO) << "Lua: Sending instance " << instance.GetId() << " to Orthanc peer \""
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 << peer_.GetUrl() << "\"";
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 try
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 {
4650
9804d6490872 Reduced memory consumption of HTTP/REST plugins calls on POST/PUT if chunked transfer is disabled
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
55 // Lifetime of "body" must exceed the call to "client.Apply()" because of "SetExternalBody()"
9804d6490872 Reduced memory consumption of HTTP/REST plugins calls on POST/PUT if chunked transfer is disabled
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
56 std::string body;
9804d6490872 Reduced memory consumption of HTTP/REST plugins calls on POST/PUT if chunked transfer is disabled
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
57 instance.ReadDicom(body);
2605
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58
4650
9804d6490872 Reduced memory consumption of HTTP/REST plugins calls on POST/PUT if chunked transfer is disabled
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
59 client.SetExternalBody(body); // Avoids a memcpy()
9804d6490872 Reduced memory consumption of HTTP/REST plugins calls on POST/PUT if chunked transfer is disabled
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
60
2605
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 std::string answer;
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 if (!client.Apply(answer))
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 {
2608
25225f0b4f33 simplification wrt. dicom connection manager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2606
diff changeset
64 LOG(ERROR) << "Lua: Unable to send instance " << instance.GetId()
25225f0b4f33 simplification wrt. dicom connection manager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2606
diff changeset
65 << " to Orthanc peer \"" << peer_.GetUrl();
2605
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 }
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 }
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 catch (OrthancException& e)
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 {
2608
25225f0b4f33 simplification wrt. dicom connection manager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2606
diff changeset
70 LOG(ERROR) << "Lua: Unable to send instance " << instance.GetId()
25225f0b4f33 simplification wrt. dicom connection manager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2606
diff changeset
71 << " to Orthanc peer \"" << peer_.GetUrl() << "\": " << e.What();
2605
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 }
2609
f7a84b551ee4 switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2608
diff changeset
73
f7a84b551ee4 switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2608
diff changeset
74 outputs.Append(input.Clone());
2605
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 }
2616
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
76
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
77
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
78 void StorePeerOperation::Serialize(Json::Value& result) const
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
79 {
2654
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
80 result = Json::objectValue;
2616
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
81 result["Type"] = "StorePeer";
2800
dc7330089736 "OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2657
diff changeset
82 peer_.Serialize(result["Peer"],
dc7330089736 "OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2657
diff changeset
83 true /* force advanced format */,
dc7330089736 "OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2657
diff changeset
84 true /* include passwords */);
2655
c196d76cb8fa serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2654
diff changeset
85 }
c196d76cb8fa serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2654
diff changeset
86
c196d76cb8fa serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2654
diff changeset
87
c196d76cb8fa serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2654
diff changeset
88 StorePeerOperation::StorePeerOperation(const Json::Value& serialized)
c196d76cb8fa serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2654
diff changeset
89 {
2656
a6d3e45eeff5 SerializationToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
90 if (SerializationToolbox::ReadString(serialized, "Type") != "StorePeer" ||
2655
c196d76cb8fa serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2654
diff changeset
91 !serialized.isMember("Peer"))
c196d76cb8fa serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2654
diff changeset
92 {
c196d76cb8fa serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2654
diff changeset
93 throw OrthancException(ErrorCode_BadFileFormat);
c196d76cb8fa serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2654
diff changeset
94 }
c196d76cb8fa serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2654
diff changeset
95
c196d76cb8fa serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2654
diff changeset
96 peer_ = WebServiceParameters(serialized["Peer"]);
2616
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
97 }
2605
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 }