changeset 209:28d017f770a3

Defaults to JSON answers, replace application/json by application/dicom+json
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 11 Jan 2018 16:57:23 +0100
parents 73cb8ada6078
children f2b5773fecf3
files NEWS Plugin/Dicom.cpp Plugin/DicomResults.cpp Plugin/DicomWebClient.cpp Plugin/StowRs.cpp Plugin/WadoRs.cpp
diffstat 6 files changed, 36 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Fri Jan 05 09:54:31 2018 +0100
+++ b/NEWS	Thu Jan 11 16:57:23 2018 +0100
@@ -1,6 +1,8 @@
 Pending changes in the mainline
 ===============================
 
+* Defaults to JSON answers instead of XML
+* Use of "application/dicom+json" MIME type instead of "application/json"
 * Added "?expand" argument to "/servers" route
 * Fix generation of numeric tags part of sequences for ".../metadata" routes
 * Support for OpenBSD
--- a/Plugin/Dicom.cpp	Fri Jan 05 09:54:31 2018 +0100
+++ b/Plugin/Dicom.cpp	Thu Jan 11 16:57:23 2018 +0100
@@ -701,7 +701,7 @@
     std::string answer;
     GenerateSingleDicomAnswer(answer, wadoBase, dictionary, dicom, isXml, isBulkAccessible);
     OrthancPluginAnswerBuffer(context, output, answer.c_str(), answer.size(), 
-                              isXml ? "application/dicom+xml" : "application/json");
+                              isXml ? "application/dicom+xml" : "application/dicom+json");
   }
 
 
--- a/Plugin/DicomResults.cpp	Fri Jan 05 09:54:31 2018 +0100
+++ b/Plugin/DicomResults.cpp	Thu Jan 11 16:57:23 2018 +0100
@@ -419,7 +419,7 @@
 
       std::string answer;
       jsonWriter_.Flatten(answer);
-      OrthancPluginAnswerBuffer(context_, output_, answer.c_str(), answer.size(), "application/json");
+      OrthancPluginAnswerBuffer(context_, output_, answer.c_str(), answer.size(), "application/dicom+json");
     }
   }
 }
--- a/Plugin/DicomWebClient.cpp	Fri Jan 05 09:54:31 2018 +0100
+++ b/Plugin/DicomWebClient.cpp	Thu Jan 11 16:57:23 2018 +0100
@@ -285,7 +285,7 @@
 
   std::map<std::string, std::string> queryArguments;
   std::map<std::string, std::string> httpHeaders;
-  httpHeaders["Accept"] = "application/json";
+  httpHeaders["Accept"] = "application/dicom+json";
   httpHeaders["Expect"] = "";
   httpHeaders["Content-Type"] = mime;
 
--- a/Plugin/StowRs.cpp	Fri Jan 05 09:54:31 2018 +0100
+++ b/Plugin/StowRs.cpp	Thu Jan 11 16:57:23 2018 +0100
@@ -61,24 +61,28 @@
 
   if (!OrthancPlugins::LookupHttpHeader(accept, request, "accept"))
   {
-    return true;   // By default, return XML Native DICOM Model
+    return false;   // By default, return DICOM+JSON
   }
 
   Orthanc::Toolbox::ToLowerCase(accept);
-  if (accept == "application/json")
+  if (accept == "application/dicom+json" ||
+      accept == "application/json" ||
+      accept == "*/*")
   {
     return false;
   }
-
-  if (accept != "application/dicom+xml" &&
-      accept != "application/xml" &&
-      accept != "text/xml" &&
-      accept != "*/*")
+  else if (accept == "application/dicom+xml" ||
+           accept == "application/xml" ||
+           accept == "text/xml")
   {
-    OrthancPlugins::Configuration::LogError("Unsupported return MIME type: " + accept + ", will return XML");
+    return true;
   }
-
-  return true;
+  else
+  {
+    OrthancPlugins::Configuration::LogError("Unsupported return MIME type: " + accept +
+                                            ", will return DICOM+JSON");
+    return false;
+  }
 }
 
 
--- a/Plugin/WadoRs.cpp	Fri Jan 05 09:54:31 2018 +0100
+++ b/Plugin/WadoRs.cpp	Thu Jan 11 16:57:23 2018 +0100
@@ -75,13 +75,11 @@
 static bool AcceptMetadata(const OrthancPluginHttpRequest* request,
                            bool& isXml)
 {
-  isXml = true;
+  isXml = false;    // By default, return application/dicom+json
 
   std::string accept;
-
   if (!OrthancPlugins::LookupHttpHeader(accept, request, "accept"))
   {
-    // By default, return "multipart/related; type=application/dicom+xml;"
     return true;
   }
 
@@ -89,14 +87,14 @@
   std::map<std::string, std::string> attributes;
   OrthancPlugins::ParseContentType(application, attributes, accept);
 
-  if (application == "application/json")
+  if (application == "application/json" ||
+      application == "application/dicom+json" ||
+      application == "*/*")
   {
-    isXml = false;
     return true;
   }
 
-  if (application != "multipart/related" &&
-      application != "*/*")
+  if (application != "multipart/related")
   {
     OrthancPlugins::Configuration::LogError("This WADO-RS plugin cannot generate the following content type: " + accept);
     return false;
@@ -106,13 +104,22 @@
   {
     std::string s = attributes["type"];
     Orthanc::Toolbox::ToLowerCase(s);
-    if (s != "application/dicom+xml")
+    if (s == "application/dicom+xml")
     {
-      OrthancPlugins::Configuration::LogError("This WADO-RS plugin only supports application/json or "
-                                              "application/dicom+xml return types for metadata (" + accept + ")");
+      isXml = true;
+    }
+    else
+    {
+      OrthancPlugins::Configuration::LogError("This WADO-RS plugin only supports application/dicom+xml "
+                                              "type for multipart/related accept (" + accept + ")");
       return false;
     }
   }
+  else
+  {
+    OrthancPlugins::Configuration::LogError("Missing \"type\" in multipart/related accept type (" + accept + ")");
+    return false;
+  }
 
   if (attributes.find("transfer-syntax") != attributes.end())
   {