You can use a try/catch to try the first connection. If it get an error then you will try the second connection in the catch.
message = qie.createJSONMessage('');
var prod1Used = false;
var prod2Used = false;
try{
// try your connection using qie.callRESTWebService or some other code;
prod1Used = true;
}catch(err){
qie.debug("ERROR:" + err);
prod1Used = false;
}
if( prod1Used === false ){
try{
// try your connection using qie.callRESTWebService or some other code;
prod2Used = true;
}catch(err){
qie.debug("ERROR:" + err);
prod2Used = false;
}
}