diff OrthancServer/OrthancRestApi/OrthancRestModalities.cpp @ 3592:de1665e7b341

added '/peers/{id}/system' route to test the connectivity with a remote peer
author Alain Mazy <alain@mazy.be>
date Mon, 23 Dec 2019 15:46:50 +0100
parents 962e5f00744b
children 085283445db0 94f4a18a79cc
line wrap: on
line diff
--- a/OrthancServer/OrthancRestApi/OrthancRestModalities.cpp	Mon Dec 23 10:44:09 2019 +0100
+++ b/OrthancServer/OrthancRestApi/OrthancRestModalities.cpp	Mon Dec 23 15:46:50 2019 +0100
@@ -1104,6 +1104,37 @@
     }
   }
 
+  static void PeerSystem(RestApiGetCall& call)
+  {
+    ServerContext& context = OrthancRestApi::GetContext(call);
+
+    std::string remote = call.GetUriComponent("id", "");
+
+    OrthancConfiguration::ReaderLock lock;
+
+    WebServiceParameters peer;
+    if (lock.GetConfiguration().LookupOrthancPeer(peer, remote))
+    {
+      HttpClient client(peer, "system");
+      std::string answer;
+
+      client.SetMethod(HttpMethod_Get);
+
+      if (!client.Apply(answer))
+      {
+        LOG(ERROR) << "Unable to get the system info from remote Orthanc peer: " << peer.GetUrl();
+        call.GetOutput().SignalError(client.GetLastStatus());
+        return;
+      }
+
+      call.GetOutput().AnswerBuffer(answer, MimeType_Json);
+    }
+    else
+    {
+      throw OrthancException(ErrorCode_UnknownResource,
+                             "No peer with symbolic name: " + remote);
+    }
+  }
 
   // DICOM bridge -------------------------------------------------------------
 
@@ -1309,6 +1340,7 @@
     Register("/peers/{id}", UpdatePeer);
     Register("/peers/{id}", DeletePeer);
     Register("/peers/{id}/store", PeerStore);
+    Register("/peers/{id}/system", PeerSystem);
 
     Register("/modalities/{id}/find-worklist", DicomFindWorklist);
   }