comparison Framework/Oracle/WebAssemblyOracle.cpp @ 841:266e2b0b9abc

better error reporting in DicomStructureSetLoader + fixed POST request logic in WebAssemblyOracle + support for LookupTableTextureSceneLayer in OpenGL (NOT using shaders!) (2 new files) + a few small non-functional changes
author Benjamin Golinvaux <bgo@osimis.io>
date Tue, 11 Jun 2019 15:41:21 +0200
parents d71cf8504159
children 67f9c27214c5
comparison
equal deleted inserted replaced
840:47fc7919977d 841:266e2b0b9abc
282 uri_ = oracle_.orthancRoot_ + uri; 282 uri_ = oracle_.orthancRoot_ + uri;
283 } 283 }
284 284
285 void SetBody(std::string& body /* will be swapped */) 285 void SetBody(std::string& body /* will be swapped */)
286 { 286 {
287 if (body != "")
288 {
289 LOG(ERROR) << "Setting non-empty body. body size = " << body.size() << " body = " << body;
290 }
287 body_.swap(body); 291 body_.swap(body);
292 LOG(ERROR) << "After setting non-empty body. body_ size = " << body_.size() << " body_ = " << body_;
288 } 293 }
289 294
290 void SetHttpHeaders(const HttpHeaders& headers) 295 void SetHttpHeaders(const HttpHeaders& headers)
291 { 296 {
292 headers_ = headers; 297 headers_ = headers;
363 368
364 headers.push_back(NULL); // Termination of the array of HTTP headers 369 headers.push_back(NULL); // Termination of the array of HTTP headers
365 370
366 attr.requestHeaders = &headers[0]; 371 attr.requestHeaders = &headers[0];
367 372
373 char* requestData = NULL;
368 if (!body_.empty()) 374 if (!body_.empty())
369 { 375 requestData = reinterpret_cast<char*>(malloc(body_.size()));
370 attr.requestDataSize = body_.size(); 376
371 attr.requestData = body_.c_str(); 377 try
372 } 378 {
373 379 if (!body_.empty())
374 // Must be the last call to prevent memory leak on error 380 {
375 attr.userData = new FetchContext(oracle_, receiver_, command_.release(), expectedContentType); 381 memcpy(requestData, &(body_[0]), body_.size());
376 emscripten_fetch(&attr, uri_.c_str()); 382 attr.requestDataSize = body_.size();
377 } 383 attr.requestData = requestData;
384 }
385 attr.userData = new FetchContext(oracle_, receiver_, command_.release(), expectedContentType);
386
387 // Must be the last call to prevent memory leak on error
388 emscripten_fetch(&attr, uri_.c_str());
389 }
390 catch(...)
391 {
392 if(requestData != NULL)
393 free(requestData);
394 throw;
395 }
396 }
378 }; 397 };
379
380 398
381 void WebAssemblyOracle::Execute(const IObserver& receiver, 399 void WebAssemblyOracle::Execute(const IObserver& receiver,
382 OrthancRestApiCommand* command) 400 OrthancRestApiCommand* command)
383 { 401 {
384 FetchCommand fetch(*this, receiver, command); 402 FetchCommand fetch(*this, receiver, command);
386 fetch.SetMethod(command->GetMethod()); 404 fetch.SetMethod(command->GetMethod());
387 fetch.SetUri(command->GetUri()); 405 fetch.SetUri(command->GetUri());
388 fetch.SetHttpHeaders(command->GetHttpHeaders()); 406 fetch.SetHttpHeaders(command->GetHttpHeaders());
389 fetch.SetTimeout(command->GetTimeout()); 407 fetch.SetTimeout(command->GetTimeout());
390 408
391 if (command->GetMethod() == Orthanc::HttpMethod_Put || 409 if (command->GetMethod() == Orthanc::HttpMethod_Post ||
392 command->GetMethod() == Orthanc::HttpMethod_Put) 410 command->GetMethod() == Orthanc::HttpMethod_Put)
393 { 411 {
394 std::string body; 412 std::string body;
395 command->SwapBody(body); 413 command->SwapBody(body);
396 fetch.SetBody(body); 414 fetch.SetBody(body);
397 } 415 }
398 416
399 fetch.Execute(); 417 fetch.Execute();
400 } 418 }
401 419
402 420
403 void WebAssemblyOracle::Execute(const IObserver& receiver, 421 void WebAssemblyOracle::Execute(const IObserver& receiver,