# HG changeset patch # User Sebastien Jodogne # Date 1559751250 -7200 # Node ID 3766775411b5d4203904a3b6c9ed54c023c67833 # Parent d5c223df16c85df33defcedd4026b8432e769fdd testing stow client diff -r d5c223df16c8 -r 3766775411b5 NEWS --- a/NEWS Mon Jun 03 18:09:59 2019 +0200 +++ b/NEWS Wed Jun 05 18:14:10 2019 +0200 @@ -1,6 +1,8 @@ Pending changes in the mainline =============================== +=> Minimum SDK version: 1.5.7 <= + * Handling of the HTTP header "Forwarded" for WADO-RS diff -r d5c223df16c8 -r 3766775411b5 Plugin/Plugin.cpp --- a/Plugin/Plugin.cpp Mon Jun 03 18:09:59 2019 +0200 +++ b/Plugin/Plugin.cpp Wed Jun 05 18:14:10 2019 +0200 @@ -170,6 +170,105 @@ } + +#include +#include + +class StowSender : public OrthancPlugins::HttpClient::IChunkedBody +{ +private: + std::vector files_; + size_t position_; + std::string boundary_; + +public: + StowSender(unsigned int size) : + position_(0), + boundary_(Orthanc::Toolbox::GenerateUuid()) + { + boost::filesystem::path p("/home/jodogne/DICOM/Demo/KNIX/Knee (R)/AX. FSE PD - 5"); + + boost::filesystem::directory_iterator end; + + // cycle through the directory + for (boost::filesystem::directory_iterator it(p); it != end; ++it) + { + if (is_regular_file(it->path())) + { + files_.push_back(it->path().string()); + } + } + } + + const std::string& GetBoundary() const + { + return boundary_; + } + + virtual bool ReadNextChunk(std::string& chunk) + { + if (position_ == files_.size() + 1) + { + return false; + } + else + { + if (position_ == files_.size()) + { + chunk = ("--" + boundary_ + "--"); + } + else + { + std::string f; + Orthanc::SystemToolbox::ReadFile(f, files_[position_]); + chunk = ("--" + boundary_ + "\r\n" + + "Content-Type: application/dicom\r\n" + + "Content-Length: " + boost::lexical_cast(f.size()) + "\r\n" + + "\r\n" + f + "\r\n"); + } + + position_++; + return true; + } + } +}; + + +ORTHANC_PLUGINS_API OrthancPluginErrorCode OnChangeCallback(OrthancPluginChangeType changeType, + OrthancPluginResourceType resourceType, + const char* resourceId) +{ + if (changeType == OrthancPluginChangeType_OrthancStarted) + { + try + { + StowSender stow(1024*128); + + OrthancPlugins::HttpClient client; + client.SetUrl("http://localhost:8080/dicom-web/studies"); + client.SetMethod(OrthancPluginHttpMethod_Post); + client.AddHeader("Accept", "application/dicom+json"); + client.AddHeader("Transfer-Encoding", "chunked"); + client.AddHeader("Expect", ""); + client.AddHeader("Content-Type", "multipart/related; type=application/dicom; boundary=" + stow.GetBoundary()); + client.SetTimeout(120); + client.SetBody(stow); + client.Execute(); + + Json::Value v; + client.GetAnswerBody().ToJson(v); + std::cout << v.toStyledString() << std::endl; + } + catch (Orthanc::OrthancException& e) + { + LOG(ERROR) << "EXCEPTION: " << e.What(); + } + } + + return OrthancPluginErrorCode_Success; +} + + extern "C" { ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* context) @@ -198,6 +297,8 @@ // Read the configuration OrthancPlugins::Configuration::Initialize(); + //OrthancPluginRegisterOnChangeCallback(context, OnChangeCallback); // TODO => REMOVE + // Initialize GDCM OrthancPlugins::GdcmParsedDicomFile::Initialize();