# HG changeset patch # User Sebastien Jodogne # Date 1559925822 -7200 # Node ID e280ced38a4c8031893252fe69a54bcdf10e914a # Parent 630fc934597f82983a4d9ae37f05586726e131a1 ErrorCode_UnsupportedMediaType diff -r 630fc934597f -r e280ced38a4c Core/Enumerations.cpp --- 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; } diff -r 630fc934597f -r e280ced38a4c Core/Enumerations.h --- 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 }; diff -r 630fc934597f -r e280ced38a4c Core/HttpServer/HttpServer.cpp --- 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 (;;) diff -r 630fc934597f -r e280ced38a4c OrthancServer/main.cpp --- 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; diff -r 630fc934597f -r e280ced38a4c Plugins/Engine/OrthancPlugins.cpp --- 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)); + } + } + else + { + return new MultipartStream(handler, (*it)->GetParameters(), boundary, GetErrorDictionary()); + } } } diff -r 630fc934597f -r e280ced38a4c Plugins/Include/orthanc/OrthancCPlugin.h --- 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, diff -r 630fc934597f -r e280ced38a4c Plugins/Samples/Common/OrthancPluginCppWrapper.cpp --- 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(e.GetErrorCode()); return NULL; } catch (...) { LogError("Native exception while creating a multipart handler"); + *errorCode = OrthancPluginErrorCode_Plugin; return NULL; } } diff -r 630fc934597f -r e280ced38a4c Resources/ErrorCodes.json --- 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" } ]