mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-14 13:57:13 +02:00
test
This commit is contained in:
@ -249,45 +249,47 @@ class RestHelper {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int n=0;
|
int n = 0;
|
||||||
int code = -1;
|
int code = -1;
|
||||||
while(n<n_connection_tries){
|
while(n < n_connection_tries){
|
||||||
|
|
||||||
req.setContentType("application/json");
|
req.setContentType("application/json");
|
||||||
//without this you need to tell the lenght: http://pocoproject.org/forum/viewtopic.php?f=12&t=5741&p=10019&hilit=post+json#p10019
|
//without this you need to tell the lenght: http://pocoproject.org/forum/viewtopic.php?f=12&t=5741&p=10019&hilit=post+json#p10019
|
||||||
// request.setContentLength(my_string.length());
|
// request.setContentLength(my_string.length());
|
||||||
req.setChunkedTransferEncoding(true);
|
req.setChunkedTransferEncoding(true);
|
||||||
try {
|
try {
|
||||||
//istringstream rs(request_body);
|
//istringstream rs(request_body);
|
||||||
//req.read(rs);
|
//req.read(rs);
|
||||||
//cout << " --- " << rs << endl;
|
//cout << " --- " << rs << endl;
|
||||||
if (request_body == "")
|
if (request_body == "")
|
||||||
session->sendRequest( (req) );
|
session->sendRequest( (req) );
|
||||||
else{
|
else{
|
||||||
ostream &os = session->sendRequest( req ) ;
|
ostream &os = session->sendRequest( req ) ;
|
||||||
os << request_body;
|
os << request_body;
|
||||||
}
|
}
|
||||||
|
|
||||||
HTTPResponse res;
|
HTTPResponse res;
|
||||||
istream &is = session->receiveResponse(res);
|
istream &is = session->receiveResponse(res);
|
||||||
StreamCopier::copyToString(is, *answer);
|
StreamCopier::copyToString(is, *answer);
|
||||||
code = res.getStatus();
|
code = res.getStatus();
|
||||||
if (code != 200){
|
if (code != 200){
|
||||||
FILE_LOG(logERROR) << "HTTP ERROR " << res.getStatus() << ": " << res.getReason() ;
|
FILE_LOG(logERROR) << "HTTP ERROR " << res.getStatus() << ": " << res.getReason() ;
|
||||||
code = -1;
|
code = -1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
code = 0;
|
code = 0;
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
catch (exception& e){
|
catch (exception& e){
|
||||||
FILE_LOG(logERROR) << "Exception connecting to "<< full_hostname << ": "<< e.what() << ", sleeping 5 seconds (" << n << "/"<<n_connection_tries << ")";
|
FILE_LOG(logERROR) << "Exception connecting to "<< full_hostname << ": "<< e.what() << ", sleeping 5 seconds (" << n << "/"<<n_connection_tries << ")";
|
||||||
sleep(5);
|
sleep(5);
|
||||||
}
|
}
|
||||||
n+=1;
|
n+=1;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw std::string("Cannot connect to the REST server! Please check...");
|
std::cout << "Hostname: " << full_hostname << std::endl;
|
||||||
|
FILE_LOG(logERROR) << "Cannot connect to the REST server host " << full_hostname << "! Please check..." ;
|
||||||
|
throw std::runtime_error("Cannot connect to the REST server! Please check...");
|
||||||
//return code;
|
//return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,7 +110,8 @@ void UDPRESTImplementation::initialize_REST(){
|
|||||||
|
|
||||||
|
|
||||||
if (code != 0){
|
if (code != 0){
|
||||||
throw answer;
|
FILE_LOG(logERROR) << __AT__ << " REST state returned: " << answer;
|
||||||
|
throw;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
isInitialized = true;
|
isInitialized = true;
|
||||||
@ -1202,8 +1203,8 @@ int UDPRESTImplementation::startReceiver(char message[]){
|
|||||||
//std::string request_body = "{\"settings\": {\"nimages\":1, \"scanid\":999, \"bit_depth\":16}}";
|
//std::string request_body = "{\"settings\": {\"nimages\":1, \"scanid\":999, \"bit_depth\":16}}";
|
||||||
FILE_LOG(logDEBUG) << __FILE__ << "::" << " sending this configuration body: " << request_body;
|
FILE_LOG(logDEBUG) << __FILE__ << "::" << " sending this configuration body: " << request_body;
|
||||||
code = rest->post_json("state/configure", &answer, request_body);
|
code = rest->post_json("state/configure", &answer, request_body);
|
||||||
//code = rest->get_json("state", &answer);
|
code = rest->get_json("state", &answer);
|
||||||
//FILE_LOG(logDEBUG) << __FILE__ << "::" << " got: " << answer;
|
FILE_LOG(logDEBUG) << __FILE__ << "::" << " got: " << answer;
|
||||||
|
|
||||||
//code = rest->post_json("state/open", &answer);
|
//code = rest->post_json("state/open", &answer);
|
||||||
//code = rest->get_json("state", &answer);
|
//code = rest->get_json("state", &answer);
|
||||||
|
Reference in New Issue
Block a user