diff --git a/Modules/CppRestSdk/include/mitkRESTServerMicroService.h b/Modules/CppRestSdk/include/mitkRESTServerMicroService.h index c3675da227..b332706af8 100644 --- a/Modules/CppRestSdk/include/mitkRESTServerMicroService.h +++ b/Modules/CppRestSdk/include/mitkRESTServerMicroService.h @@ -1,37 +1,39 @@ #ifndef mitkRESTServerMicroService_h #define mitkRESTServerMicroService_h #include "cpprest/asyncrt_utils.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" #include "MitkCppRestSdkExports.h" typedef web::http::experimental::listener::http_listener MitkListener; typedef web::http::http_request MitkRequest; typedef web::http::http_response MitkResponse; typedef web::http::methods MitkRESTMethods; typedef web::http::status_codes MitkRestStatusCodes; typedef web::json::json_exception MitkJsonException; namespace mitk { class RESTServerMicroService { public: RESTServerMicroService(web::uri uri); ~RESTServerMicroService(); + web::uri GetUri(); private: - MitkListener m_Listener; pplx::task openListener(); pplx::task closeListener(); void HandleGet(MitkRequest request); + MitkListener m_Listener; + web::uri m_Uri; }; } // namespace mitk #endif \ No newline at end of file diff --git a/Modules/CppRestSdk/src/mitkCppRestSdkActivator.cpp b/Modules/CppRestSdk/src/mitkCppRestSdkActivator.cpp index 10bd104f1d..2ae820cac5 100644 --- a/Modules/CppRestSdk/src/mitkCppRestSdkActivator.cpp +++ b/Modules/CppRestSdk/src/mitkCppRestSdkActivator.cpp @@ -1,39 +1,40 @@ #include "mitkCppRestSdkActivator.h" #include #include #include #include #include #include #include #include #include #include void MitkCppRestSdkActivator::Load(us::ModuleContext *context) { //Registration of the RESTManagerMicroservice m_RESTManager.reset(new mitk::RESTManager); context->RegisterService(m_RESTManager.get()); //Test use of the RESTManagerMicroservice, later done in Module us::ServiceReference refManager = context->GetServiceReference(); if (refManager) { auto serviceClient = context->GetService(refManager); if (serviceClient) { - serviceClient->receiveRequest(L"http://localhost:8080"); + serviceClient->receiveRequest(L"http://localhost:8080/test"); + serviceClient->receiveRequest(L"http://localhost:8080/example"); serviceClient->receiveRequest(L"http://localhost:8090"); } } } void MitkCppRestSdkActivator::Unload(us::ModuleContext *) { } US_EXPORT_MODULE_ACTIVATOR(MitkCppRestSdkActivator) diff --git a/Modules/CppRestSdk/src/mitkRESTManager.cpp b/Modules/CppRestSdk/src/mitkRESTManager.cpp index c4d9834086..10d74f3d42 100644 --- a/Modules/CppRestSdk/src/mitkRESTManager.cpp +++ b/Modules/CppRestSdk/src/mitkRESTManager.cpp @@ -1,32 +1,50 @@ #include "mitkRESTManager.h" #include mitk::RESTManager::RESTManager() {} mitk::RESTManager::~RESTManager() {} void mitk::RESTManager::sendRequest(RequestType type) { switch (type) { case get: //Call get in mitkRESTClientMicroService break; case post: //Call post in mitkRESTClientMicroService break; case put: //Call put in mitkRESTClientMicroService break; } } void mitk::RESTManager::receiveRequest(web::uri uri) { //New instance of RESTServerMicroservice in m_ServerMap, key is port of the request int port = uri.port(); - RESTServerMicroService* server = new RESTServerMicroService(uri); - m_ServerMap[port] = server; - MITK_INFO <GetUri() == uri.authority()) + { + //new observer has to be added + MITK_INFO << "started listening"; + } + else + { + MITK_ERROR << "there is already another server listening under this port"; + } + } } diff --git a/Modules/CppRestSdk/src/mitkRESTServerMicroService.cpp b/Modules/CppRestSdk/src/mitkRESTServerMicroService.cpp index 9ac91fc93b..35c8a9d58b 100644 --- a/Modules/CppRestSdk/src/mitkRESTServerMicroService.cpp +++ b/Modules/CppRestSdk/src/mitkRESTServerMicroService.cpp @@ -1,35 +1,43 @@ #include "mitkRESTServerMicroService.h" #include mitk::RESTServerMicroService::RESTServerMicroService(web::uri uri) : m_Listener(uri) { + m_Uri = uri; m_Listener.support(MitkRESTMethods::GET, std::bind(&RESTServerMicroService::HandleGet, this, std::placeholders::_1)); - openListener(); + openListener(); } mitk::RESTServerMicroService::~RESTServerMicroService() { closeListener(); } pplx::task mitk::RESTServerMicroService::openListener() { return m_Listener.open(); } pplx::task mitk::RESTServerMicroService::closeListener() { return m_Listener.close(); } +web::uri mitk::RESTServerMicroService::GetUri() +{ + return m_Uri; +} + void mitk::RESTServerMicroService::HandleGet(MitkRequest request) { int port = m_Listener.uri().port(); + utility::string_t uri = request.absolute_uri().to_string(); + std::string uriString(uri.begin(), uri.end()); web::json::value content; content[L"key 1"] = web::json::value::string(U("this is a first test")); request.set_body(content); auto answer = request.extract_json().get(); - MITK_INFO << "Test for Server at port "<