Mercurial > hg > orthanc
comparison Plugins/Engine/OrthancPlugins.cpp @ 1445:d26c8a93d05a
refactoring: SimpleGet
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 01 Jul 2015 12:30:19 +0200 |
parents | f3672356c121 |
children | 8dc80ba768aa |
comparison
equal
deleted
inserted
replaced
1444:b2b09a3dbd8e | 1445:d26c8a93d05a |
---|---|
614 bool afterPlugins) | 614 bool afterPlugins) |
615 { | 615 { |
616 const _OrthancPluginRestApiGet& p = | 616 const _OrthancPluginRestApiGet& p = |
617 *reinterpret_cast<const _OrthancPluginRestApiGet*>(parameters); | 617 *reinterpret_cast<const _OrthancPluginRestApiGet*>(parameters); |
618 | 618 |
619 // TODO : Use "HttpToolbox::SimpleGet()" | |
620 | |
621 IHttpHandler::Arguments headers; // No HTTP header | |
622 std::string body; // No body for a GET request | |
623 | |
624 UriComponents uri; | |
625 IHttpHandler::GetArguments getArguments; | |
626 HttpToolbox::ParseGetQuery(uri, getArguments, p.uri); | |
627 | |
628 StringHttpOutput stream; | |
629 HttpOutput http(stream, false /* no keep alive */); | |
630 | |
631 LOG(INFO) << "Plugin making REST GET call on URI " << p.uri | 619 LOG(INFO) << "Plugin making REST GET call on URI " << p.uri |
632 << (afterPlugins ? " (after plugins)" : " (built-in API)"); | 620 << (afterPlugins ? " (after plugins)" : " (built-in API)"); |
633 | 621 |
634 bool ok = false; | 622 CheckContextAvailable(); |
623 IHttpHandler& handler = pimpl_->context_->GetHttpHandler().RestrictToOrthancRestApi(!afterPlugins); | |
624 | |
635 std::string result; | 625 std::string result; |
636 | 626 if (HttpToolbox::SimpleGet(result, handler, p.uri)) |
637 if (afterPlugins) | 627 { |
638 { | |
639 ok = Handle(http, HttpMethod_Get, uri, headers, getArguments, body); | |
640 } | |
641 | |
642 if (!ok) | |
643 { | |
644 ok = (pimpl_->restApi_ != NULL && | |
645 pimpl_->restApi_->Handle(http, HttpMethod_Get, uri, headers, getArguments, body)); | |
646 } | |
647 | |
648 if (ok) | |
649 { | |
650 stream.GetOutput(result); | |
651 CopyToMemoryBuffer(*p.target, result); | 628 CopyToMemoryBuffer(*p.target, result); |
652 } | 629 } |
653 else | 630 else |
654 { | 631 { |
655 throw OrthancException(ErrorCode_BadRequest); | 632 throw OrthancException(ErrorCode_BadRequest); |
662 bool afterPlugins) | 639 bool afterPlugins) |
663 { | 640 { |
664 const _OrthancPluginRestApiPostPut& p = | 641 const _OrthancPluginRestApiPostPut& p = |
665 *reinterpret_cast<const _OrthancPluginRestApiPostPut*>(parameters); | 642 *reinterpret_cast<const _OrthancPluginRestApiPostPut*>(parameters); |
666 | 643 |
644 // TODO : Use "HttpToolbox::SimplePost()" | |
645 | |
667 IHttpHandler::Arguments headers; // No HTTP header | 646 IHttpHandler::Arguments headers; // No HTTP header |
668 IHttpHandler::GetArguments getArguments; // No GET argument for POST/PUT | 647 IHttpHandler::GetArguments getArguments; // No GET argument for POST/PUT |
669 | 648 |
670 UriComponents uri; | 649 UriComponents uri; |
671 Toolbox::SplitUriComponents(uri, p.uri); | 650 Toolbox::SplitUriComponents(uri, p.uri); |
710 bool afterPlugins) | 689 bool afterPlugins) |
711 { | 690 { |
712 // The "parameters" point to the URI | 691 // The "parameters" point to the URI |
713 UriComponents uri; | 692 UriComponents uri; |
714 Toolbox::SplitUriComponents(uri, reinterpret_cast<const char*>(parameters)); | 693 Toolbox::SplitUriComponents(uri, reinterpret_cast<const char*>(parameters)); |
694 | |
695 // TODO : Use "HttpToolbox::SimpleDelete()" | |
715 | 696 |
716 IHttpHandler::Arguments headers; // No HTTP header | 697 IHttpHandler::Arguments headers; // No HTTP header |
717 IHttpHandler::GetArguments getArguments; // No GET argument for POST/PUT | 698 IHttpHandler::GetArguments getArguments; // No GET argument for POST/PUT |
718 std::string body; // No body for DELETE | 699 std::string body; // No body for DELETE |
719 | 700 |