Mercurial > hg > orthanc
comparison Plugins/Engine/OrthancPlugins.cpp @ 1606:31f4adefb88f
issuing HTTP requests from the plugin SDK
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 01 Sep 2015 17:37:26 +0200 |
parents | fd0464ce1962 |
children | adc6a5704cdb |
comparison
equal
deleted
inserted
replaced
1605:fd0464ce1962 | 1606:31f4adefb88f |
---|---|
1119 | 1119 |
1120 CopyToMemoryBuffer(*p.target, compressed.size() > 0 ? compressed.c_str() : NULL, compressed.size()); | 1120 CopyToMemoryBuffer(*p.target, compressed.size() > 0 ? compressed.c_str() : NULL, compressed.size()); |
1121 } | 1121 } |
1122 | 1122 |
1123 | 1123 |
1124 void OrthancPlugins::CallHttpClient(const void* parameters) | |
1125 { | |
1126 const _OrthancPluginCallHttpClient& p = *reinterpret_cast<const _OrthancPluginCallHttpClient*>(parameters); | |
1127 | |
1128 HttpClient client; | |
1129 client.SetUrl(p.url); | |
1130 | |
1131 if (p.username != NULL && | |
1132 p.password != NULL) | |
1133 { | |
1134 client.SetCredentials(p.username, p.password); | |
1135 } | |
1136 | |
1137 switch (p.method) | |
1138 { | |
1139 case OrthancPluginHttpMethod_Get: | |
1140 client.SetMethod(HttpMethod_Get); | |
1141 break; | |
1142 | |
1143 case OrthancPluginHttpMethod_Post: | |
1144 client.SetMethod(HttpMethod_Post); | |
1145 client.GetBody().assign(p.body, p.bodySize); | |
1146 break; | |
1147 | |
1148 case OrthancPluginHttpMethod_Put: | |
1149 client.SetMethod(HttpMethod_Put); | |
1150 client.GetBody().assign(p.body, p.bodySize); | |
1151 break; | |
1152 | |
1153 case OrthancPluginHttpMethod_Delete: | |
1154 client.SetMethod(HttpMethod_Delete); | |
1155 break; | |
1156 | |
1157 default: | |
1158 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
1159 } | |
1160 | |
1161 std::string s; | |
1162 client.ApplyAndThrowException(s); | |
1163 | |
1164 if (p.method != OrthancPluginHttpMethod_Delete) | |
1165 { | |
1166 CopyToMemoryBuffer(*p.target, s); | |
1167 } | |
1168 } | |
1169 | |
1170 | |
1124 bool OrthancPlugins::InvokeService(_OrthancPluginService service, | 1171 bool OrthancPlugins::InvokeService(_OrthancPluginService service, |
1125 const void* parameters) | 1172 const void* parameters) |
1126 { | 1173 { |
1127 VLOG(1) << "Calling plugin service: " << service; | 1174 VLOG(1) << "Calling plugin service: " << service; |
1128 | 1175 |
1477 | 1524 |
1478 case _OrthancPluginService_CompressImage: | 1525 case _OrthancPluginService_CompressImage: |
1479 CompressImage(parameters); | 1526 CompressImage(parameters); |
1480 return true; | 1527 return true; |
1481 | 1528 |
1529 case _OrthancPluginService_CallHttpClient: | |
1530 CallHttpClient(parameters); | |
1531 return true; | |
1532 | |
1482 default: | 1533 default: |
1483 { | 1534 { |
1484 // This service is unknown to the Orthanc plugin engine | 1535 // This service is unknown to the Orthanc plugin engine |
1485 return false; | 1536 return false; |
1486 } | 1537 } |