annotate OrthancServer/Sources/ServerJobs/Operations/StorePeerOperation.cpp @ 5853:4d932683049d get-scu tip

very first implementation of C-Get SCU
author Alain Mazy <am@orthanc.team>
date Tue, 29 Oct 2024 17:25:49 +0100
parents f7adfb22e20e
children
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
5640
f7adfb22e20e updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium
f7adfb22e20e updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
6 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium
5485
48b8dae6dc77 upgrade to year 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
7 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
2605
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 *
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * This program is free software: you can redistribute it and/or
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * modify it under the terms of the GNU General Public License as
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * published by the Free Software Foundation, either version 3 of the
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * License, or (at your option) any later version.
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 *
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * This program is distributed in the hope that it will be useful, but
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * General Public License for more details.
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 *
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * You should have received a copy of the GNU General Public License
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 **/
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
2641
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2616
diff changeset
24 #include "../../PrecompiledHeadersServer.h"
2605
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 #include "StorePeerOperation.h"
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 #include "DicomInstanceOperationValue.h"
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28
4045
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
29 #include "../../../../OrthancFramework/Sources/Logging.h"
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
30 #include "../../../../OrthancFramework/Sources/OrthancException.h"
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
31 #include "../../../../OrthancFramework/Sources/HttpClient.h"
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
32 #include "../../../../OrthancFramework/Sources/SerializationToolbox.h"
2605
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 namespace Orthanc
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 {
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 void StorePeerOperation::Apply(JobOperationValues& outputs,
4310
2ae905070221 renaming pure interface JobOperationValue as IJobOperationValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
37 const IJobOperationValue& input)
2605
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 {
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 // Configure the HTTP client
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 HttpClient client(peer_, "instances");
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 client.SetMethod(HttpMethod_Post);
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42
4310
2ae905070221 renaming pure interface JobOperationValue as IJobOperationValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
43 if (input.GetType() != IJobOperationValue::Type_DicomInstance)
2605
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 {
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 throw OrthancException(ErrorCode_BadParameterType);
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 }
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47
2608
25225f0b4f33 simplification wrt. dicom connection manager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2606
diff changeset
48 const DicomInstanceOperationValue& instance =
25225f0b4f33 simplification wrt. dicom connection manager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2606
diff changeset
49 dynamic_cast<const DicomInstanceOperationValue&>(input);
2605
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 LOG(INFO) << "Lua: Sending instance " << instance.GetId() << " to Orthanc peer \""
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 << peer_.GetUrl() << "\"";
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 try
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 {
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
56 // 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
57 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
58 instance.ReadDicom(body);
2605
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59
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
60 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
61
2605
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 std::string answer;
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 if (!client.Apply(answer))
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 {
2608
25225f0b4f33 simplification wrt. dicom connection manager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2606
diff changeset
65 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
66 << " to Orthanc peer \"" << peer_.GetUrl();
2605
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 }
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 }
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 catch (OrthancException& e)
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 {
2608
25225f0b4f33 simplification wrt. dicom connection manager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2606
diff changeset
71 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
72 << " to Orthanc peer \"" << peer_.GetUrl() << "\": " << e.What();
2605
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 }
2609
f7a84b551ee4 switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2608
diff changeset
74
f7a84b551ee4 switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2608
diff changeset
75 outputs.Append(input.Clone());
2605
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 }
2616
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
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
79 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
80 {
2654
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2651
diff changeset
81 result = Json::objectValue;
2616
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
82 result["Type"] = "StorePeer";
2800
dc7330089736 "OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2657
diff changeset
83 peer_.Serialize(result["Peer"],
dc7330089736 "OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2657
diff changeset
84 true /* force advanced format */,
dc7330089736 "OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2657
diff changeset
85 true /* include passwords */);
2655
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
c196d76cb8fa serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2654
diff changeset
89 StorePeerOperation::StorePeerOperation(const Json::Value& serialized)
c196d76cb8fa serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2654
diff changeset
90 {
2656
a6d3e45eeff5 SerializationToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
91 if (SerializationToolbox::ReadString(serialized, "Type") != "StorePeer" ||
2655
c196d76cb8fa serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2654
diff changeset
92 !serialized.isMember("Peer"))
c196d76cb8fa serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2654
diff changeset
93 {
c196d76cb8fa serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2654
diff changeset
94 throw OrthancException(ErrorCode_BadFileFormat);
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
c196d76cb8fa serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2654
diff changeset
97 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
98 }
2605
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 }