in src/main/java/com/lambdajavablockchain/controller/ApiController.java [68:98]
public ResponseEntity<?> query(@RequestParam String chaincodeName,
@RequestParam String functionName,
@RequestParam(required = false) String args) {
try {
if (args == null)
args = "";
log.debug("Querying chaincode - chaincodeName:" + chaincodeName +
"functionName:" + functionName +
"args:" + args);
service.setupClient();
// First retrieve LambdaUser's credentials and set user context
service.setUser(AMBConfig.LAMBDAUSER);
service.initChannel();
String res = service.queryChaincode(service.getClient(), service.getChannel(), chaincodeName, functionName, args);
return new ResponseEntity<>(res, HttpStatus.OK);
} catch (EnrollmentNotFoundException | AppException e){
log.error("Error while querying chaincode - " + e.getMessage());
return new ResponseEntity<>("Error while querying chaincode - " + e.getMessage(), HttpStatus.BAD_REQUEST);
} catch (ManagedBlockchainServiceException e) {
log.error("Error while querying chaincode, " + e.getMessage());
return new ResponseEntity<>("Error while querying chaincode, ManagedBlockchainService startup failed - "
+ e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
} catch (Exception e) {
log.error("Error while querying - function:" + functionName + " chaincode:" + chaincodeName);
e.printStackTrace();
return new ResponseEntity<>("Error while querying chaincode", HttpStatus.INTERNAL_SERVER_ERROR);
}
}