diff --git a/Modules/CppRestSdk/include/mitkRESTServer.h b/Modules/CppRestSdk/include/mitkRESTServer.h index e729248094..b3149504cc 100644 --- a/Modules/CppRestSdk/include/mitkRESTServer.h +++ b/Modules/CppRestSdk/include/mitkRESTServer.h @@ -1,60 +1,64 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef MITKRESTSERVER_H #define MITKRESTSERVER_H -#include "cpprest/json.h" -#include "cpprest/http_listener.h" -#include "cpprest/uri.h" #include "cpprest/asyncrt_utils.h" -#include "cpprest/json.h" -#include "cpprest/filestream.h" #include "cpprest/containerstream.h" +#include "cpprest/filestream.h" +#include "cpprest/http_listener.h" +#include "cpprest/json.h" #include "cpprest/producerconsumerstream.h" +#include "cpprest/uri.h" + +// hm.. maybe go after that warning at some time? seems like a nasty hack, but works so far :) +#pragma warning(disable : 4251) -#include "MitkRESTServerExports.h" +#include "MitkCppRestSdkExports.h" typedef web::http::experimental::listener::http_listener MitkListener; typedef web::http::http_request MitkRequest; typedef web::http::methods MitkRESTMethods; typedef web::http::status_codes MitkRestStatusCodes; +typedef web::json::json_exception MitkJsonException; -namespace mitk { - - class MITKRESTSERVER_EXPORT RESTServer +namespace mitk +{ + class MITKCPPRESTSDK_EXPORT RESTServer { public: - RESTServer(); RESTServer(utility::string_t url); virtual ~RESTServer(); pplx::task open() { return m_Listener.open(); } pplx::task close() { return m_Listener.close(); } + static std::string convertToUtf8(utility::string_t stringT) { return utility::conversions::to_utf8string(stringT); } + protected: - virtual void HandleGet(MitkRequest message) { }; - virtual void HandlePut(MitkRequest message) { }; - virtual void HandlePost(MitkRequest message) { }; - virtual void HandleDelete(MitkRequest message) { }; - void HandleError(pplx::task& t); + virtual void HandleGet(MitkRequest message){}; + virtual void HandlePut(MitkRequest message){}; + virtual void HandlePost(MitkRequest message){}; + virtual void HandleDelete(MitkRequest message){}; + void HandleError(pplx::task &t); MitkListener m_Listener; }; }; #endif // MITKRESTSERVER_H \ No newline at end of file diff --git a/Modules/CppRestSdk/src/mitkRESTServer.cpp b/Modules/CppRestSdk/src/mitkRESTServer.cpp index 01d12705df..bef1754211 100644 --- a/Modules/CppRestSdk/src/mitkRESTServer.cpp +++ b/Modules/CppRestSdk/src/mitkRESTServer.cpp @@ -1,27 +1,37 @@ +/*=================================================================== + +The Medical Imaging Interaction Toolkit (MITK) + +Copyright (c) German Cancer Research Center, +Division of Medical and Biological Informatics. +All rights reserved. + +This software is distributed WITHOUT ANY WARRANTY; without +even the implied warranty of MERCHANTABILITY or FITNESS FOR +A PARTICULAR PURPOSE. + +See LICENSE.txt or http://www.mitk.org for details. + +===================================================================*/ + #include "mitkRESTServer.h" #include -mitk::RESTServer::RESTServer() -{ -} +mitk::RESTServer::RESTServer() {} -mitk::RESTServer::RESTServer(utility::string_t url) : m_Listener(url) -{ -} +mitk::RESTServer::RESTServer(utility::string_t url) : m_Listener(url) {} -mitk::RESTServer::~RESTServer() -{ -} +mitk::RESTServer::~RESTServer() {} -void mitk::RESTServer::HandleError(pplx::task& t) +void mitk::RESTServer::HandleError(pplx::task &t) { try { t.get(); } catch (...) { mitkThrow() << "An error occured."; } } \ No newline at end of file diff --git a/Plugins/org.mitk.gui.qt.segmentation.rework/src/internal/SegmentationReworkREST.cpp b/Plugins/org.mitk.gui.qt.segmentation.rework/src/internal/SegmentationReworkREST.cpp index e042b976b2..415911f64a 100644 --- a/Plugins/org.mitk.gui.qt.segmentation.rework/src/internal/SegmentationReworkREST.cpp +++ b/Plugins/org.mitk.gui.qt.segmentation.rework/src/internal/SegmentationReworkREST.cpp @@ -1,20 +1,58 @@ +/*=================================================================== + +The Medical Imaging Interaction Toolkit (MITK) + +Copyright (c) German Cancer Research Center, +Division of Medical and Biological Informatics. +All rights reserved. + +This software is distributed WITHOUT ANY WARRANTY; without +even the implied warranty of MERCHANTABILITY or FITNESS FOR +A PARTICULAR PURPOSE. + +See LICENSE.txt or http://www.mitk.org for details. + +===================================================================*/ + #include "SegmentationReworkREST.h" #include -SegmentationReworkREST::SegmentationReworkREST(utility::string_t url) : mitk::RESTServer(url) +SegmentationReworkREST::SegmentationReworkREST(utility::string_t url) : mitk::RESTServer(url) { m_Listener.support(MitkRESTMethods::PUT, std::bind(&SegmentationReworkREST::HandlePut, this, std::placeholders::_1)); } -SegmentationReworkREST::~SegmentationReworkREST() -{ -} +SegmentationReworkREST::~SegmentationReworkREST() {} void SegmentationReworkREST::HandlePut(MitkRequest message) { - MITK_DEBUG << utility::conversions::to_utf8string(message.to_string()); + auto messageString = message.to_string(); + MITK_INFO << "Message PUT incoming..."; + MITK_INFO << convertToUtf8(messageString); + + std::string imageSeriesUID = ""; + try + { + auto jsonMessage = message.extract_json().get(); + auto messageTypeKey = jsonMessage.at(U("messageType")); + if (messageTypeKey.as_string() == U("downloadData")) + { + auto imageSeriesUIDKey = jsonMessage.at(U("imageSeriesUID")); + imageSeriesUID = convertToUtf8(imageSeriesUIDKey.as_string()); + MITK_INFO << "value of imageSeriesUID " << imageSeriesUID; + // trigger download function + } + else + { + message.reply(MitkRestStatusCodes::BadRequest, "Oh man, i can only deal with 'messageType' = 'downloadData'..."); + } + } + catch (MitkJsonException &e) + { + MITK_ERROR << e.what() << ".. oh man, that was not expected"; + } message.reply(MitkRestStatusCodes::OK, "Sure, i got you.. have an awesome day"); return; } diff --git a/Plugins/org.mitk.gui.qt.segmentation.rework/src/internal/SegmentationReworkView.cpp b/Plugins/org.mitk.gui.qt.segmentation.rework/src/internal/SegmentationReworkView.cpp index b37aa46b50..70bff2c088 100644 --- a/Plugins/org.mitk.gui.qt.segmentation.rework/src/internal/SegmentationReworkView.cpp +++ b/Plugins/org.mitk.gui.qt.segmentation.rework/src/internal/SegmentationReworkView.cpp @@ -1,113 +1,111 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ - // Blueberry #include #include // Qmitk #include "SegmentationReworkView.h" // Qt #include // mitk image #include const std::string SegmentationReworkView::VIEW_ID = "org.mitk.views.segmentationreworkview"; void SegmentationReworkView::SetFocus() { m_Controls.buttonPerformImageProcessing->setFocus(); } void SegmentationReworkView::CreateQtPartControl(QWidget *parent) { // create GUI widgets from the Qt Designer's .ui file m_Controls.setupUi(parent); - connect(m_Controls.buttonPerformImageProcessing, &QPushButton::clicked, this, &SegmentationReworkView::DoImageProcessing); - - MITK_INFO << "in qt part control"; + connect( + m_Controls.buttonPerformImageProcessing, &QPushButton::clicked, this, &SegmentationReworkView::DoImageProcessing); utility::string_t port = U("2020"); utility::string_t address = U("http://127.0.0.1:"); address.append(port); m_HttpHandler = std::unique_ptr(new SegmentationReworkREST(address)); m_HttpHandler->open().wait(); MITK_INFO << "Listening for requests at: " << utility::conversions::to_utf8string(address); } void SegmentationReworkView::OnSelectionChanged(berry::IWorkbenchPart::Pointer /*source*/, const QList &nodes) { // iterate all selected objects, adjust warning visibility foreach (mitk::DataNode::Pointer node, nodes) { if (node.IsNotNull() && dynamic_cast(node->GetData())) { m_Controls.labelWarning->setVisible(false); m_Controls.buttonPerformImageProcessing->setEnabled(true); return; } } m_Controls.labelWarning->setVisible(true); m_Controls.buttonPerformImageProcessing->setEnabled(false); } void SegmentationReworkView::DoImageProcessing() { QList nodes = this->GetDataManagerSelection(); if (nodes.empty()) return; mitk::DataNode *node = nodes.front(); if (!node) { // Nothing selected. Inform the user and return QMessageBox::information(nullptr, "Template", "Please load and select an image before starting image processing."); return; } // here we have a valid mitk::DataNode // a node itself is not very useful, we need its data item (the image) mitk::BaseData *data = node->GetData(); if (data) { // test if this data item is an image or not (could also be a surface or something totally different) mitk::Image *image = dynamic_cast(data); if (image) { std::stringstream message; std::string name; message << "Performing image processing for image "; if (node->GetName(name)) { // a property called "name" was found for this DataNode message << "'" << name << "'"; } message << "."; MITK_INFO << message.str(); // actually do something here... } } } diff --git a/Plugins/org.mitk.gui.qt.segmentation.rework/src/internal/SegmentationReworkView.h b/Plugins/org.mitk.gui.qt.segmentation.rework/src/internal/SegmentationReworkView.h index 343dc011fd..36f4b22c5b 100644 --- a/Plugins/org.mitk.gui.qt.segmentation.rework/src/internal/SegmentationReworkView.h +++ b/Plugins/org.mitk.gui.qt.segmentation.rework/src/internal/SegmentationReworkView.h @@ -1,64 +1,63 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ - #ifndef SegmentationReworkView_h #define SegmentationReworkView_h #include #include #include "ui_SegmentationReworkViewControls.h" #include "SegmentationReworkRest.h" /** \brief SegmentationReworkView \warning This class is not yet documented. Use "git blame" and ask the author to provide basic documentation. \sa QmitkAbstractView \ingroup ${plugin_target}_internal */ class SegmentationReworkView : public QmitkAbstractView { // this is needed for all Qt objects that should have a Qt meta-object // (everything that derives from QObject and wants to have signal/slots) Q_OBJECT public: static const std::string VIEW_ID; protected: virtual void CreateQtPartControl(QWidget *parent) override; virtual void SetFocus() override; /// \brief called by QmitkFunctionality when DataManager's selection has changed virtual void OnSelectionChanged(berry::IWorkbenchPart::Pointer source, const QList &nodes) override; /// \brief Called when the user clicks the GUI button void DoImageProcessing(); Ui::SegmentationReworkViewControls m_Controls; private: std::unique_ptr m_HttpHandler; }; #endif // SegmentationReworkView_h