public ResponseEntity invokeFabcar()

in src/main/java/com/lambdajavablockchain/controller/ApiController.java [189:218]


    public ResponseEntity<?> invokeFabcar(@RequestBody @Valid Car car) {
        try {
            log.debug("Inserting new Car:" + car.toString());

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

            // build arguments list required by the chaincode
            String[] arguments = {car.getId(), car.getMake(), car.getModel(), car.getColour(), car.getOwner()};

            // invoke createCar function on fabcar chaincode
            service.invokeChaincode(service.getClient(), service.getChannel(), "fabcar",
                    "createCar", arguments);

            return new ResponseEntity<>("Car created successfully", HttpStatus.ACCEPTED);
        } catch (EnrollmentNotFoundException | AppException e){
            log.error("Error creating car - " + e.getMessage());
            return new ResponseEntity<>("Error creating car - " + e.getMessage(), HttpStatus.BAD_REQUEST);
        } catch (ManagedBlockchainServiceException e) {
            log.error("Error creating car, ManagedBlockchainService startup failed - " + e.getMessage());
            return new ResponseEntity<>("Error creating car, ManagedBlockchainService startup failed - "
                    + e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
        } catch (Exception e) {
            log.error("Error while invoking - function:createCar chaincode:fabcar");
            e.printStackTrace();
            return new ResponseEntity<>("Error creating car, chaincode invocation failed", HttpStatus.INTERNAL_SERVER_ERROR);
        }
    }