Mercurial > hg > orthanc
changeset 2183:1d0838b8e9c5
RestApiDelete and RestApiPut
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 25 Nov 2016 21:33:35 +0100 |
parents | 085a41c66133 |
children | 71e8a70e9e99 |
files | Plugins/Samples/Common/IOrthancConnection.cpp Plugins/Samples/Common/IOrthancConnection.h Plugins/Samples/Common/OrthancHttpConnection.cpp Plugins/Samples/Common/OrthancHttpConnection.h Plugins/Samples/Common/OrthancPluginConnection.cpp Plugins/Samples/Common/OrthancPluginConnection.h Plugins/Samples/Common/OrthancPluginCppWrapper.h |
diffstat | 7 files changed, 88 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/Plugins/Samples/Common/IOrthancConnection.cpp Fri Nov 25 19:08:10 2016 +0100 +++ b/Plugins/Samples/Common/IOrthancConnection.cpp Fri Nov 25 21:33:35 2016 +0100 @@ -69,4 +69,15 @@ orthanc.RestApiPost(content, uri, body); ParseJson(result, content); } + + + void IOrthancConnection::RestApiPut(Json::Value& result, + IOrthancConnection& orthanc, + const std::string& uri, + const std::string& body) + { + std::string content; + orthanc.RestApiPut(content, uri, body); + ParseJson(result, content); + } }
--- a/Plugins/Samples/Common/IOrthancConnection.h Fri Nov 25 19:08:10 2016 +0100 +++ b/Plugins/Samples/Common/IOrthancConnection.h Fri Nov 25 21:33:35 2016 +0100 @@ -54,6 +54,12 @@ const std::string& uri, const std::string& body) = 0; + virtual void RestApiPut(std::string& result, + const std::string& uri, + const std::string& body) = 0; + + virtual void RestApiDelete(const std::string& uri) = 0; + static void ParseJson(Json::Value& result, const std::string& content); @@ -65,5 +71,10 @@ IOrthancConnection& orthanc, const std::string& uri, const std::string& body); + + static void RestApiPut(Json::Value& result, + IOrthancConnection& orthanc, + const std::string& uri, + const std::string& body); }; }
--- a/Plugins/Samples/Common/OrthancHttpConnection.cpp Fri Nov 25 19:08:10 2016 +0100 +++ b/Plugins/Samples/Common/OrthancHttpConnection.cpp Fri Nov 25 21:33:35 2016 +0100 @@ -79,4 +79,29 @@ client_.SetBody(body); client_.ApplyAndThrowException(result); } + + + void OrthancHttpConnection::RestApiPut(std::string& result, + const std::string& uri, + const std::string& body) + { + boost::mutex::scoped_lock lock(mutex_); + + client_.SetMethod(Orthanc::HttpMethod_Put); + client_.SetUrl(url_ + uri); + client_.SetBody(body); + client_.ApplyAndThrowException(result); + } + + + void OrthancHttpConnection::RestApiDelete(const std::string& uri) + { + boost::mutex::scoped_lock lock(mutex_); + + std::string result; + + client_.SetMethod(Orthanc::HttpMethod_Delete); + client_.SetUrl(url_ + uri); + client_.ApplyAndThrowException(result); + } }
--- a/Plugins/Samples/Common/OrthancHttpConnection.h Fri Nov 25 19:08:10 2016 +0100 +++ b/Plugins/Samples/Common/OrthancHttpConnection.h Fri Nov 25 21:33:35 2016 +0100 @@ -65,5 +65,11 @@ virtual void RestApiPost(std::string& result, const std::string& uri, const std::string& body); + + virtual void RestApiPut(std::string& result, + const std::string& uri, + const std::string& body); + + virtual void RestApiDelete(const std::string& uri); }; }
--- a/Plugins/Samples/Common/OrthancPluginConnection.cpp Fri Nov 25 19:08:10 2016 +0100 +++ b/Plugins/Samples/Common/OrthancPluginConnection.cpp Fri Nov 25 21:33:35 2016 +0100 @@ -58,7 +58,7 @@ { OrthancPlugins::MemoryBuffer buffer(context_); - if (!buffer.RestApiPost(uri, body.c_str(), body.size(), false)) + if (buffer.RestApiPost(uri, body.c_str(), body.size(), false)) { buffer.ToString(result); } @@ -67,4 +67,32 @@ ORTHANC_PLUGINS_THROW_EXCEPTION(OrthancPluginErrorCode_UnknownResource); } } + + + void OrthancPluginConnection::RestApiPut(std::string& result, + const std::string& uri, + const std::string& body) + { + OrthancPlugins::MemoryBuffer buffer(context_); + + if (buffer.RestApiPut(uri, body.c_str(), body.size(), false)) + { + buffer.ToString(result); + } + else + { + ORTHANC_PLUGINS_THROW_EXCEPTION(OrthancPluginErrorCode_UnknownResource); + } + } + + + void OrthancPluginConnection::RestApiDelete(const std::string& uri) + { + OrthancPlugins::MemoryBuffer buffer(context_); + + if (!::OrthancPlugins::RestApiDelete(context_, uri, false)) + { + ORTHANC_PLUGINS_THROW_EXCEPTION(OrthancPluginErrorCode_UnknownResource); + } + } }
--- a/Plugins/Samples/Common/OrthancPluginConnection.h Fri Nov 25 19:08:10 2016 +0100 +++ b/Plugins/Samples/Common/OrthancPluginConnection.h Fri Nov 25 21:33:35 2016 +0100 @@ -56,5 +56,11 @@ virtual void RestApiPost(std::string& result, const std::string& uri, const std::string& body); + + virtual void RestApiPut(std::string& result, + const std::string& uri, + const std::string& body); + + virtual void RestApiDelete(const std::string& uri); }; }
--- a/Plugins/Samples/Common/OrthancPluginCppWrapper.h Fri Nov 25 19:08:10 2016 +0100 +++ b/Plugins/Samples/Common/OrthancPluginCppWrapper.h Fri Nov 25 21:33:35 2016 +0100 @@ -375,10 +375,6 @@ const std::string& uri, bool applyPlugins); - bool RestApiDelete(OrthancPluginContext* context, - const std::string& uri, - bool applyPlugins); - inline void LogError(OrthancPluginContext* context, const std::string& message) {