changeset 3404:e280ced38a4c

ErrorCode_UnsupportedMediaType
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 07 Jun 2019 18:43:42 +0200
parents 630fc934597f
children 408ffcb4038f
files Core/Enumerations.cpp Core/Enumerations.h Core/HttpServer/HttpServer.cpp OrthancServer/main.cpp Plugins/Engine/OrthancPlugins.cpp Plugins/Include/orthanc/OrthancCPlugin.h Plugins/Samples/Common/OrthancPluginCppWrapper.cpp Resources/ErrorCodes.json
diffstat 8 files changed, 45 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/Core/Enumerations.cpp	Fri Jun 07 17:24:26 2019 +0200
+++ b/Core/Enumerations.cpp	Fri Jun 07 18:43:42 2019 +0200
@@ -365,6 +365,9 @@
       case ErrorCode_AlreadyExistingTag:
         return "Cannot override the value of a tag that already exists";
 
+      case ErrorCode_UnsupportedMediaType:
+        return "Unsupported media type";
+
       default:
         if (error >= ErrorCode_START_PLUGINS)
         {
@@ -2130,6 +2133,9 @@
       case ErrorCode_CreateDicomParentIsInstance:
         return HttpStatus_400_BadRequest;
 
+      case ErrorCode_UnsupportedMediaType:
+        return HttpStatus_415_UnsupportedMediaType;
+
       default:
         return HttpStatus_500_InternalServerError;
     }
--- a/Core/Enumerations.h	Fri Jun 07 17:24:26 2019 +0200
+++ b/Core/Enumerations.h	Fri Jun 07 18:43:42 2019 +0200
@@ -238,6 +238,7 @@
     ErrorCode_CannotOrderSlices = 2040    /*!< Unable to order the slices of the series */,
     ErrorCode_NoWorklistHandler = 2041    /*!< No request handler factory for DICOM C-Find Modality SCP */,
     ErrorCode_AlreadyExistingTag = 2042    /*!< Cannot override the value of a tag that already exists */,
+    ErrorCode_UnsupportedMediaType = 3000    /*!< Unsupported media type */,
     ErrorCode_START_PLUGINS = 1000000
   };
 
--- a/Core/HttpServer/HttpServer.cpp	Fri Jun 07 17:24:26 2019 +0200
+++ b/Core/HttpServer/HttpServer.cpp	Fri Jun 07 18:43:42 2019 +0200
@@ -393,7 +393,6 @@
     if (contentLength != headers.end())
     {
       // "Content-Length" is available
-      
       std::string body;
       PostDataStatus status = ReadBodyWithContentLength(body, connection, contentLength->second);
 
@@ -407,7 +406,7 @@
     }
     else
     {
-      // No Content-Length. Stream the HTTP connection.
+      // No Content-Length: This is a chunked transfer. Stream the HTTP connection.
       std::string tmp(1024 * 1024, 0);
       
       for (;;)
--- a/OrthancServer/main.cpp	Fri Jun 07 17:24:26 2019 +0200
+++ b/OrthancServer/main.cpp	Fri Jun 07 18:43:42 2019 +0200
@@ -671,6 +671,7 @@
     PrintErrorCode(ErrorCode_CannotOrderSlices, "Unable to order the slices of the series");
     PrintErrorCode(ErrorCode_NoWorklistHandler, "No request handler factory for DICOM C-Find Modality SCP");
     PrintErrorCode(ErrorCode_AlreadyExistingTag, "Cannot override the value of a tag that already exists");
+    PrintErrorCode(ErrorCode_UnsupportedMediaType, "Unsupported media type");
   }
 
   std::cout << std::endl;
--- a/Plugins/Engine/OrthancPlugins.cpp	Fri Jun 07 17:24:26 2019 +0200
+++ b/Plugins/Engine/OrthancPlugins.cpp	Fri Jun 07 18:43:42 2019 +0200
@@ -4247,14 +4247,30 @@
           continue;
         }
 
+        OrthancPluginErrorCode errorCode = OrthancPluginErrorCode_Plugin;
+
         OrthancPluginMultipartRestHandler* handler = (*it)->GetParameters().createHandler(
-          (*it)->GetParameters().factory,
+          (*it)->GetParameters().factory, &errorCode,
           convertedMethod, matcher.GetFlatUri().c_str(), contentType.c_str(), subType.c_str(),
           matcher.GetGroupsCount(), matcher.GetGroups(), headers.size(),
           headers.empty() ? NULL : &headersKeys[0],
           headers.empty() ? NULL : &headersValues[0]);
 
-        return new MultipartStream(handler, (*it)->GetParameters(), boundary, GetErrorDictionary());
+        if (handler == NULL)
+        {
+          if (errorCode == OrthancPluginErrorCode_Success)
+          {
+            // Ignore: The factory cannot create a handler for this request
+          }
+          else
+          {
+            throw OrthancException(static_cast<ErrorCode>(errorCode));
+          }          
+        }
+        else
+        {
+          return new MultipartStream(handler, (*it)->GetParameters(), boundary, GetErrorDictionary());
+        }
       }
     }
 
--- a/Plugins/Include/orthanc/OrthancCPlugin.h	Fri Jun 07 17:24:26 2019 +0200
+++ b/Plugins/Include/orthanc/OrthancCPlugin.h	Fri Jun 07 18:43:42 2019 +0200
@@ -298,6 +298,7 @@
     OrthancPluginErrorCode_CannotOrderSlices = 2040    /*!< Unable to order the slices of the series */,
     OrthancPluginErrorCode_NoWorklistHandler = 2041    /*!< No request handler factory for DICOM C-Find Modality SCP */,
     OrthancPluginErrorCode_AlreadyExistingTag = 2042    /*!< Cannot override the value of a tag that already exists */,
+    OrthancPluginErrorCode_UnsupportedMediaType = 3000    /*!< Unsupported media type */,
 
     _OrthancPluginErrorCode_INTERNAL = 0x7fffffff
   } OrthancPluginErrorCode;
@@ -6915,6 +6916,7 @@
 
   typedef OrthancPluginMultipartRestHandler* (*OrthancPluginMultipartRestCreateHandler) (
     OrthancPluginMultipartRestFactory* factory,
+    OrthancPluginErrorCode*            errorCode,   /* out: to report an exception on handler creation */
     OrthancPluginHttpMethod            method,
     const char*                        url,
     const char*                        contentType,
--- a/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp	Fri Jun 07 17:24:26 2019 +0200
+++ b/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp	Fri Jun 07 18:43:42 2019 +0200
@@ -2610,6 +2610,7 @@
 #if HAS_ORTHANC_PLUGIN_HTTP_MULTIPART_SERVER == 1
   static OrthancPluginMultipartRestHandler* MultipartRestFactory(
     OrthancPluginMultipartRestFactory* factory,
+    OrthancPluginErrorCode*            errorCode,
     OrthancPluginHttpMethod            method,
     const char*                        url,
     const char*                        contentType,
@@ -2620,6 +2621,8 @@
     const char* const*                 headersKeys,
     const char* const*                 headersValues)
   {
+    *errorCode = OrthancPluginErrorCode_Success;
+
     try
     {
       assert(factory != NULL);
@@ -2646,11 +2649,13 @@
     catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e)
     {
       LogError("Exception while creating a multipart handler");
+      *errorCode = static_cast<OrthancPluginErrorCode>(e.GetErrorCode());
       return NULL;
     }
     catch (...)
     {
       LogError("Native exception while creating a multipart handler");
+      *errorCode = OrthancPluginErrorCode_Plugin;
       return NULL;
     }
   }
--- a/Resources/ErrorCodes.json	Fri Jun 07 17:24:26 2019 +0200
+++ b/Resources/ErrorCodes.json	Fri Jun 07 18:43:42 2019 +0200
@@ -322,11 +322,6 @@
 
 
 
-
-
-
-
-
   /** Specific error codes **/
 
   
@@ -551,5 +546,16 @@
     "Code": 2042,
     "Name": "AlreadyExistingTag",
     "Description": "Cannot override the value of a tag that already exists"
+  },
+
+
+
+  /** HTTP-related error codes **/
+
+  {
+    "Code": 3000,
+    "HttpStatus": 415, 
+    "Name": "UnsupportedMediaType",
+    "Description": "Unsupported media type"
   }
 ]