changeset 6174:9fce9208f24f attach-custom-data

integration mainline->attach-custom-data
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 11 Jun 2025 17:52:06 +0200
parents 86a076ceaf3a (current diff) 628edb487cec (diff)
children 8bd3a683778d
files NEWS OrthancServer/Plugins/Engine/OrthancPlugins.cpp OrthancServer/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp OrthancServer/Plugins/Samples/Common/OrthancPluginCppWrapper.h
diffstat 7 files changed, 17 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Wed Jun 11 16:55:15 2025 +0200
+++ b/NEWS	Wed Jun 11 17:52:06 2025 +0200
@@ -34,6 +34,10 @@
   In Orthanc 1.12.6 and 1.12.7, "RejectSopClasses" was used instead of the expected
   "RejectedSopClasses" spelling.
 * Fix the re-encoding of DICOM files larger than 4GB
+* Improved translations of HTTP error codes when a plugin calls the core REST API.
+  e.g., a plugin could receive an error 17:OrthancPluginErrorCode_UnknownResource when the underlying
+  REST handler was actually returning an HTTP error 415.  The plugin will now receive an
+  error 3000:OrthancPluginErrorCode_UnsupportedMediaType.
 
 REST API
 --------
--- a/OrthancFramework/Sources/DicomFormat/DicomMap.cpp	Wed Jun 11 16:55:15 2025 +0200
+++ b/OrthancFramework/Sources/DicomFormat/DicomMap.cpp	Wed Jun 11 17:52:06 2025 +0200
@@ -43,6 +43,7 @@
 #if !defined(__EMSCRIPTEN__)
 // Multithreading is not supported in WebAssembly
 #  include <boost/thread/shared_mutex.hpp>
+#  include <boost/thread/lock_types.hpp>  // For boost::unique_lock<> and boost::shared_lock<>
 #endif
 
 namespace Orthanc
--- a/OrthancFramework/Sources/HttpServer/IHttpHandler.cpp	Wed Jun 11 16:55:15 2025 +0200
+++ b/OrthancFramework/Sources/HttpServer/IHttpHandler.cpp	Wed Jun 11 17:52:06 2025 +0200
@@ -51,7 +51,10 @@
     if (handler.Handle(http, origin, LOCALHOST, "", HttpMethod_Get, curi, 
                        httpHeaders, getArguments, NULL /* no body for GET */, 0))
     {
-      stream.GetBody(answerBody);
+      if (stream.GetStatus() == HttpStatus_200_Ok)
+      {
+        stream.GetBody(answerBody);
+      }
 
       if (answerHeaders != NULL)
       {
--- a/OrthancServer/Plugins/Engine/OrthancPlugins.cpp	Wed Jun 11 16:55:15 2025 +0200
+++ b/OrthancServer/Plugins/Engine/OrthancPlugins.cpp	Wed Jun 11 17:52:06 2025 +0200
@@ -3362,6 +3362,10 @@
     {
       throw OrthancException(ErrorCode_UnknownResource);
     }
+    else if (intHttpStatus == 415)
+    {
+      throw OrthancException(ErrorCode_UnsupportedMediaType);
+    }
     else
     {
       throw OrthancException(ErrorCode_BadRequest);
--- a/OrthancServer/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp	Wed Jun 11 16:55:15 2025 +0200
+++ b/OrthancServer/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp	Wed Jun 11 17:52:06 2025 +0200
@@ -1566,7 +1566,7 @@
     {
       if (!answer.IsEmpty())
       {
-        result.assign(answer.GetData(), answer.GetSize());
+        result.assign(reinterpret_cast<const char*>(answer.GetData()), answer.GetSize());
       }
       return true;
     }
--- a/OrthancServer/Plugins/Samples/Common/OrthancPluginCppWrapper.h	Wed Jun 11 16:55:15 2025 +0200
+++ b/OrthancServer/Plugins/Samples/Common/OrthancPluginCppWrapper.h	Wed Jun 11 17:52:06 2025 +0200
@@ -235,11 +235,11 @@
 
     OrthancPluginMemoryBuffer Release();
 
-    const char* GetData() const
+    const void* GetData() const
     {
       if (buffer_.size > 0)
       {
-        return reinterpret_cast<const char*>(buffer_.data);
+        return buffer_.data;
       }
       else
       {
--- a/OrthancServer/Plugins/Samples/ServeFolders/Plugin.cpp	Wed Jun 11 16:55:15 2025 +0200
+++ b/OrthancServer/Plugins/Samples/ServeFolders/Plugin.cpp	Wed Jun 11 17:52:06 2025 +0200
@@ -221,7 +221,7 @@
       OrthancPluginSetHttpHeader(OrthancPlugins::GetGlobalContext(),
                                  output, "Last-Modified", t.c_str());
 
-      Answer(output, content.GetData(), content.GetSize(), mime);
+      Answer(output, reinterpret_cast<const char*>(content.GetData()), content.GetSize(), mime);
     }
   }
 }