Mercurial > hg > orthanc-stone
changeset 382:dd4c7e82b4be
removed class OrthancApiClient::HttpErrorMessage, redundant with IWebService::HttpRequestErrorMessage
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 06 Nov 2018 19:36:32 +0100 |
parents | 19bd222283ae |
children | 939f626eb6d7 |
files | Framework/Toolbox/OrthancApiClient.cpp Framework/Toolbox/OrthancApiClient.h Framework/Toolbox/OrthancSlicesLoader.cpp Framework/Toolbox/OrthancSlicesLoader.h |
diffstat | 4 files changed, 66 insertions(+), 83 deletions(-) [+] |
line wrap: on
line diff
--- a/Framework/Toolbox/OrthancApiClient.cpp Tue Nov 06 15:36:06 2018 +0100 +++ b/Framework/Toolbox/OrthancApiClient.cpp Tue Nov 06 19:36:32 2018 +0100 @@ -66,20 +66,8 @@ } - const Orthanc::IDynamicObject& OrthancApiClient::HttpErrorMessage::GetPayload() const - { - if (HasPayload()) - { - return *payload_; - } - else - { - throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); - } - } - - - OrthancApiClient::OrthancApiClient(MessageBroker &broker, IWebService &orthanc) : + OrthancApiClient::OrthancApiClient(MessageBroker& broker, + IWebService& orthanc) : IObservable(broker), orthanc_(orthanc) { @@ -91,12 +79,12 @@ { private: std::auto_ptr<MessageHandler<OrthancApiClient::JsonResponseReadyMessage> > orthancApiSuccessCallback_; - std::auto_ptr<MessageHandler<OrthancApiClient::HttpErrorMessage> > orthancApiFailureCallback_; + std::auto_ptr<MessageHandler<IWebService::HttpRequestErrorMessage> > orthancApiFailureCallback_; public: HttpResponseToJsonConverter(MessageBroker& broker, MessageHandler<OrthancApiClient::JsonResponseReadyMessage>* orthancApiSuccessCallback, - MessageHandler<OrthancApiClient::HttpErrorMessage>* orthancApiFailureCallback) + MessageHandler<IWebService::HttpRequestErrorMessage>* orthancApiFailureCallback) : IObserver(broker), IObservable(broker), orthancApiSuccessCallback_(orthancApiSuccessCallback), @@ -117,7 +105,7 @@ } else if (orthancApiFailureCallback_.get() != NULL) { - orthancApiFailureCallback_->Apply(OrthancApiClient::HttpErrorMessage + orthancApiFailureCallback_->Apply(IWebService::HttpRequestErrorMessage (message.GetUri(), message.GetPayloadPointer())); } @@ -128,7 +116,7 @@ { if (orthancApiFailureCallback_.get() != NULL) { - orthancApiFailureCallback_->Apply(OrthancApiClient::HttpErrorMessage(message.GetUri(), message.GetPayloadPointer())); + orthancApiFailureCallback_->Apply(IWebService::HttpRequestErrorMessage(message.GetUri(), message.GetPayloadPointer())); } delete this; // hack untill we find someone to take ownership of this object (https://isocpp.org/wiki/faq/freestore-mgmt#delete-this) @@ -141,12 +129,12 @@ { private: std::auto_ptr<MessageHandler<OrthancApiClient::BinaryResponseReadyMessage> > orthancApiSuccessCallback_; - std::auto_ptr<MessageHandler<OrthancApiClient::HttpErrorMessage> > orthancApiFailureCallback_; + std::auto_ptr<MessageHandler<IWebService::HttpRequestErrorMessage> > orthancApiFailureCallback_; public: HttpResponseToBinaryConverter(MessageBroker& broker, MessageHandler<OrthancApiClient::BinaryResponseReadyMessage>* orthancApiSuccessCallback, - MessageHandler<OrthancApiClient::HttpErrorMessage>* orthancApiFailureCallback) + MessageHandler<IWebService::HttpRequestErrorMessage>* orthancApiFailureCallback) : IObserver(broker), IObservable(broker), orthancApiSuccessCallback_(orthancApiSuccessCallback), @@ -164,7 +152,7 @@ } else if (orthancApiFailureCallback_.get() != NULL) { - orthancApiFailureCallback_->Apply(OrthancApiClient::HttpErrorMessage + orthancApiFailureCallback_->Apply(IWebService::HttpRequestErrorMessage (message.GetUri(), message.GetPayloadPointer())); } @@ -175,7 +163,7 @@ { if (orthancApiFailureCallback_.get() != NULL) { - orthancApiFailureCallback_->Apply(OrthancApiClient::HttpErrorMessage(message.GetUri(), message.GetPayloadPointer())); + orthancApiFailureCallback_->Apply(IWebService::HttpRequestErrorMessage(message.GetUri(), message.GetPayloadPointer())); } delete this; // hack untill we find someone to take ownership of this object (https://isocpp.org/wiki/faq/freestore-mgmt#delete-this) @@ -188,12 +176,12 @@ { private: std::auto_ptr<MessageHandler<OrthancApiClient::EmptyResponseReadyMessage> > orthancApiSuccessCallback_; - std::auto_ptr<MessageHandler<OrthancApiClient::HttpErrorMessage> > orthancApiFailureCallback_; + std::auto_ptr<MessageHandler<IWebService::HttpRequestErrorMessage> > orthancApiFailureCallback_; public: HttpResponseToEmptyConverter(MessageBroker& broker, MessageHandler<OrthancApiClient::EmptyResponseReadyMessage>* orthancApiSuccessCallback, - MessageHandler<OrthancApiClient::HttpErrorMessage>* orthancApiFailureCallback) + MessageHandler<IWebService::HttpRequestErrorMessage>* orthancApiFailureCallback) : IObserver(broker), IObservable(broker), orthancApiSuccessCallback_(orthancApiSuccessCallback), @@ -210,7 +198,7 @@ } else if (orthancApiFailureCallback_.get() != NULL) { - orthancApiFailureCallback_->Apply(OrthancApiClient::HttpErrorMessage + orthancApiFailureCallback_->Apply(IWebService::HttpRequestErrorMessage (message.GetUri(), message.GetPayloadPointer())); } @@ -221,7 +209,7 @@ { if (orthancApiFailureCallback_.get() != NULL) { - orthancApiFailureCallback_->Apply(OrthancApiClient::HttpErrorMessage(message.GetUri(), message.GetPayloadPointer())); + orthancApiFailureCallback_->Apply(IWebService::HttpRequestErrorMessage(message.GetUri(), message.GetPayloadPointer())); } delete this; // hack untill we find someone to take ownership of this object (https://isocpp.org/wiki/faq/freestore-mgmt#delete-this) @@ -231,7 +219,7 @@ void OrthancApiClient::GetJsonAsync(const std::string& uri, MessageHandler<JsonResponseReadyMessage>* successCallback, - MessageHandler<HttpErrorMessage>* failureCallback, + MessageHandler<IWebService::HttpRequestErrorMessage>* failureCallback, Orthanc::IDynamicObject* payload) { HttpResponseToJsonConverter* converter = new HttpResponseToJsonConverter(broker_, successCallback, failureCallback); // it is currently deleting itself after being used @@ -241,10 +229,23 @@ } + + void OrthancApiClient::GetBinaryAsync(const std::string& uri, + const std::string& contentType, + MessageHandler<BinaryResponseReadyMessage>* successCallback, + MessageHandler<IWebService::HttpRequestErrorMessage>* failureCallback, + Orthanc::IDynamicObject* payload) + { + IWebService::Headers headers; + headers["Accept"] = contentType; + GetBinaryAsync(uri, headers, successCallback, failureCallback, payload); + } + + void OrthancApiClient::GetBinaryAsync(const std::string& uri, const IWebService::Headers& headers, MessageHandler<BinaryResponseReadyMessage>* successCallback, - MessageHandler<HttpErrorMessage>* failureCallback, + MessageHandler<IWebService::HttpRequestErrorMessage>* failureCallback, Orthanc::IDynamicObject* payload) { HttpResponseToBinaryConverter* converter = new HttpResponseToBinaryConverter(broker_, successCallback, failureCallback); // it is currently deleting itself after being used @@ -253,10 +254,11 @@ new Callable<HttpResponseToBinaryConverter, IWebService::HttpRequestErrorMessage>(*converter, &HttpResponseToBinaryConverter::ConvertError)); } + void OrthancApiClient::PostBinaryAsyncExpectJson(const std::string& uri, const std::string& body, MessageHandler<JsonResponseReadyMessage>* successCallback, - MessageHandler<HttpErrorMessage>* failureCallback, + MessageHandler<IWebService::HttpRequestErrorMessage>* failureCallback, Orthanc::IDynamicObject* payload) { HttpResponseToJsonConverter* converter = new HttpResponseToJsonConverter(broker_, successCallback, failureCallback); // it is currently deleting itself after being used @@ -266,10 +268,11 @@ } + void OrthancApiClient::PostJsonAsyncExpectJson(const std::string& uri, const Json::Value& data, MessageHandler<JsonResponseReadyMessage>* successCallback, - MessageHandler<HttpErrorMessage>* failureCallback, + MessageHandler<IWebService::HttpRequestErrorMessage>* failureCallback, Orthanc::IDynamicObject* payload) { std::string body; @@ -277,9 +280,10 @@ return PostBinaryAsyncExpectJson(uri, body, successCallback, failureCallback, payload); } + void OrthancApiClient::DeleteAsync(const std::string& uri, MessageHandler<EmptyResponseReadyMessage>* successCallback, - MessageHandler<HttpErrorMessage>* failureCallback, + MessageHandler<IWebService::HttpRequestErrorMessage>* failureCallback, Orthanc::IDynamicObject* payload) { HttpResponseToEmptyConverter* converter = new HttpResponseToEmptyConverter(broker_, successCallback, failureCallback); // it is currently deleting itself after being used @@ -289,4 +293,12 @@ } + class OrthancApiClient::WebServicePayload : public boost::noncopyable + { + private: + std::auto_ptr< MessageHandler<EmptyResponseReadyMessage> > emptyHandler_; + std::auto_ptr< MessageHandler<JsonResponseReadyMessage> > jsonHandler_; + std::auto_ptr< MessageHandler<BinaryResponseReadyMessage> > binaryHandler_; + std::auto_ptr< Orthanc::IDynamicObject > userPayload; + }; }
--- a/Framework/Toolbox/OrthancApiClient.h Tue Nov 06 15:36:06 2018 +0100 +++ b/Framework/Toolbox/OrthancApiClient.h Tue Nov 06 19:36:32 2018 +0100 @@ -141,33 +141,10 @@ }; - class HttpErrorMessage : public BaseMessage<MessageType_OrthancApi_GenericHttpError_Ready> - { - private: - const std::string& uri_; - const Orthanc::IDynamicObject* payload_; - public: - HttpErrorMessage(const std::string& uri, - const Orthanc::IDynamicObject* payload) : - uri_(uri), - payload_(payload) - { - } - - const std::string& GetUri() const - { - return uri_; - } - - bool HasPayload() const - { - return payload_ != NULL; - } - - const Orthanc::IDynamicObject& GetPayload() const; - }; - + private: + class WebServicePayload; + protected: IWebService& orthanc_; @@ -183,48 +160,43 @@ // schedule a GET request expecting a JSON response. void GetJsonAsync(const std::string& uri, MessageHandler<JsonResponseReadyMessage>* successCallback, - MessageHandler<HttpErrorMessage>* failureCallback = NULL, + MessageHandler<IWebService::HttpRequestErrorMessage>* failureCallback = NULL, Orthanc::IDynamicObject* payload = NULL /* takes ownership */); // schedule a GET request expecting a binary response. void GetBinaryAsync(const std::string& uri, const std::string& contentType, MessageHandler<BinaryResponseReadyMessage>* successCallback, - MessageHandler<HttpErrorMessage>* failureCallback = NULL, - Orthanc::IDynamicObject* payload = NULL /* takes ownership */) - { - IWebService::Headers headers; - headers["Accept"] = contentType; - GetBinaryAsync(uri, headers, successCallback, failureCallback, payload); - } + MessageHandler<IWebService::HttpRequestErrorMessage>* failureCallback = NULL, + Orthanc::IDynamicObject* payload = NULL /* takes ownership */); // schedule a GET request expecting a binary response. void GetBinaryAsync(const std::string& uri, const IWebService::Headers& headers, MessageHandler<BinaryResponseReadyMessage>* successCallback, - MessageHandler<HttpErrorMessage>* failureCallback = NULL, + MessageHandler<IWebService::HttpRequestErrorMessage>* failureCallback = NULL, Orthanc::IDynamicObject* payload = NULL /* takes ownership */); // schedule a POST request expecting a JSON response. void PostBinaryAsyncExpectJson(const std::string& uri, const std::string& body, MessageHandler<JsonResponseReadyMessage>* successCallback, - MessageHandler<HttpErrorMessage>* failureCallback = NULL, + MessageHandler<IWebService::HttpRequestErrorMessage>* failureCallback = NULL, Orthanc::IDynamicObject* payload = NULL /* takes ownership */); // schedule a POST request expecting a JSON response. void PostJsonAsyncExpectJson(const std::string& uri, const Json::Value& data, MessageHandler<JsonResponseReadyMessage>* successCallback, - MessageHandler<HttpErrorMessage>* failureCallback = NULL, + MessageHandler<IWebService::HttpRequestErrorMessage>* failureCallback = NULL, Orthanc::IDynamicObject* payload = NULL /* takes ownership */); // schedule a DELETE request expecting an empty response. void DeleteAsync(const std::string& uri, MessageHandler<EmptyResponseReadyMessage>* successCallback, - MessageHandler<HttpErrorMessage>* failureCallback = NULL, + MessageHandler<IWebService::HttpRequestErrorMessage>* failureCallback = NULL, Orthanc::IDynamicObject* payload = NULL /* takes ownership */); - + void NotifyHttpSuccess(const IWebService::HttpRequestSuccessMessage& message); }; }
--- a/Framework/Toolbox/OrthancSlicesLoader.cpp Tue Nov 06 15:36:06 2018 +0100 +++ b/Framework/Toolbox/OrthancSlicesLoader.cpp Tue Nov 06 19:36:32 2018 +0100 @@ -217,13 +217,13 @@ } } - void OrthancSlicesLoader::OnGeometryError(const OrthancApiClient::HttpErrorMessage& message) + void OrthancSlicesLoader::OnGeometryError(const IWebService::HttpRequestErrorMessage& message) { EmitMessage(SliceGeometryErrorMessage(*this)); state_ = State_Error; } - void OrthancSlicesLoader::OnSliceImageError(const OrthancApiClient::HttpErrorMessage& message) + void OrthancSlicesLoader::OnSliceImageError(const IWebService::HttpRequestErrorMessage& message) { NotifySliceImageError(dynamic_cast<const Operation&>(message.GetPayload())); state_ = State_Error; @@ -665,7 +665,7 @@ state_ = State_LoadingGeometry; orthanc_.GetJsonAsync("/series/" + seriesId + "/instances-tags", new Callable<OrthancSlicesLoader, OrthancApiClient::JsonResponseReadyMessage>(*this, &OrthancSlicesLoader::ParseSeriesGeometry), - new Callable<OrthancSlicesLoader, OrthancApiClient::HttpErrorMessage>(*this, &OrthancSlicesLoader::OnGeometryError), + new Callable<OrthancSlicesLoader, IWebService::HttpRequestErrorMessage>(*this, &OrthancSlicesLoader::OnGeometryError), NULL); } } @@ -684,7 +684,7 @@ // mandatory to read RT DOSE, but is too long to be returned by default orthanc_.GetJsonAsync("/instances/" + instanceId + "/tags?ignore-length=3004-000c", new Callable<OrthancSlicesLoader, OrthancApiClient::JsonResponseReadyMessage>(*this, &OrthancSlicesLoader::ParseInstanceGeometry), - new Callable<OrthancSlicesLoader, OrthancApiClient::HttpErrorMessage>(*this, &OrthancSlicesLoader::OnGeometryError), + new Callable<OrthancSlicesLoader, IWebService::HttpRequestErrorMessage>(*this, &OrthancSlicesLoader::OnGeometryError), Operation::DownloadInstanceGeometry(instanceId)); } } @@ -703,7 +703,7 @@ orthanc_.GetJsonAsync("/instances/" + instanceId + "/tags", new Callable<OrthancSlicesLoader, OrthancApiClient::JsonResponseReadyMessage>(*this, &OrthancSlicesLoader::ParseFrameGeometry), - new Callable<OrthancSlicesLoader, OrthancApiClient::HttpErrorMessage>(*this, &OrthancSlicesLoader::OnGeometryError), + new Callable<OrthancSlicesLoader, IWebService::HttpRequestErrorMessage>(*this, &OrthancSlicesLoader::OnGeometryError), Operation::DownloadFrameGeometry(instanceId, frame)); } } @@ -775,7 +775,7 @@ orthanc_.GetBinaryAsync(uri, "image/png", new Callable<OrthancSlicesLoader, OrthancApiClient::BinaryResponseReadyMessage>(*this, &OrthancSlicesLoader::ParseSliceImagePng), - new Callable<OrthancSlicesLoader, OrthancApiClient::HttpErrorMessage>(*this, &OrthancSlicesLoader::OnSliceImageError), + new Callable<OrthancSlicesLoader, IWebService::HttpRequestErrorMessage>(*this, &OrthancSlicesLoader::OnSliceImageError), Operation::DownloadSliceImage(index, slice, SliceImageQuality_FullPng)); } @@ -805,7 +805,7 @@ orthanc_.GetBinaryAsync(uri, "image/x-portable-arbitrarymap", new Callable<OrthancSlicesLoader, OrthancApiClient::BinaryResponseReadyMessage>(*this, &OrthancSlicesLoader::ParseSliceImagePam), - new Callable<OrthancSlicesLoader, OrthancApiClient::HttpErrorMessage>(*this, &OrthancSlicesLoader::OnSliceImageError), + new Callable<OrthancSlicesLoader, IWebService::HttpRequestErrorMessage>(*this, &OrthancSlicesLoader::OnSliceImageError), Operation::DownloadSliceImage(index, slice, SliceImageQuality_FullPam)); } @@ -843,7 +843,7 @@ orthanc_.GetJsonAsync(uri, new Callable<OrthancSlicesLoader, OrthancApiClient::JsonResponseReadyMessage>(*this, &OrthancSlicesLoader::ParseSliceImageJpeg), - new Callable<OrthancSlicesLoader, OrthancApiClient::HttpErrorMessage>(*this, &OrthancSlicesLoader::OnSliceImageError), + new Callable<OrthancSlicesLoader, IWebService::HttpRequestErrorMessage>(*this, &OrthancSlicesLoader::OnSliceImageError), Operation::DownloadSliceImage(index, slice, quality)); } @@ -879,7 +879,7 @@ boost::lexical_cast<std::string>(slice.GetFrame()) + "/raw.gz"); orthanc_.GetBinaryAsync(uri, IWebService::Headers(), new Callable<OrthancSlicesLoader, OrthancApiClient::BinaryResponseReadyMessage>(*this, &OrthancSlicesLoader::ParseSliceRawImage), - new Callable<OrthancSlicesLoader, OrthancApiClient::HttpErrorMessage>(*this, &OrthancSlicesLoader::OnSliceImageError), + new Callable<OrthancSlicesLoader, IWebService::HttpRequestErrorMessage>(*this, &OrthancSlicesLoader::OnSliceImageError), Operation::DownloadSliceRawImage(index, slice)); } }
--- a/Framework/Toolbox/OrthancSlicesLoader.h Tue Nov 06 15:36:06 2018 +0100 +++ b/Framework/Toolbox/OrthancSlicesLoader.h Tue Nov 06 19:36:32 2018 +0100 @@ -143,8 +143,9 @@ void NotifySliceImageError(const Operation& operation); - void OnGeometryError(const OrthancApiClient::HttpErrorMessage& message); - void OnSliceImageError(const OrthancApiClient::HttpErrorMessage& message); + void OnGeometryError(const IWebService::HttpRequestErrorMessage& message); + + void OnSliceImageError(const IWebService::HttpRequestErrorMessage& message); void ParseSeriesGeometry(const OrthancApiClient::JsonResponseReadyMessage& message); @@ -195,7 +196,5 @@ void ScheduleLoadSliceImage(size_t index, SliceImageQuality requestedQuality); - - }; }