public ResponseEntity queryFabcar()

in src/main/java/com/lambdajavablockchain/controller/ApiController.java [150:180]


    public ResponseEntity<?> queryFabcar(@PathVariable(name = "carId") String carId) {
        try {
            log.debug("Querying car by carId:" + carId);

            service.setupClient();
            // First retrieve LambdaUser's credentials and set user context
            service.setUser(AMBConfig.LAMBDAUSER);
            service.initChannel();

            // query chaincode
            String res = service.queryChaincode(service.getClient(), service.getChannel(),
                    "fabcar", "queryCar", carId);

            // convert the response into Car object
            ObjectMapper objectMapper = new ObjectMapper();
            Car car = objectMapper.readValue(res, Car.class);
            car.setId(carId);
            return new ResponseEntity<>(car, HttpStatus.OK);
        } catch (EnrollmentNotFoundException | AppException e){
            log.error("Error while querying - " + e.getMessage());
            return new ResponseEntity<>("Error querying car - " + e.getMessage(), HttpStatus.BAD_REQUEST);
        } catch (ManagedBlockchainServiceException e) {
            log.error("Error querying car, ManagedBlockchainService startup failed - " + e.getMessage());
            return new ResponseEntity<>("Error querying car, ManagedBlockchainService startup failed - "
                    + e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
        } catch (Exception e) {
            log.error("Error while querying - function:queryCar chaincode:fabcar");
            e.printStackTrace();
            return new ResponseEntity<>("Error querying car, chaincode query failed", HttpStatus.INTERNAL_SERVER_ERROR);
        }
    }