Example of how to validate barcode scans in real-time in using Java and Spring boot framework.
First ensure you have Java and Maven installed.
Then execute the following:
# download this example code
git clone https://github.com/orca-scan/orca-validation-java.git
# go into the new directory
cd orca-validation-java
# install dependecies
mvn package
# start the project
mvn spring-boot:run
Your server will now be running on port 8080.
You can emulate an Orca Scan Validation input using cURL by running the following:
curl --location --request POST 'http://127.0.0.1:8080/' \
--header 'Content-Type: application/json' \
--data-raw '{
"___orca_sheet_name": "Vehicle Checks",
"___orca_user_email": "hidden@requires.https",
"Barcode": "orca-scan-test",
"Date": "2022-04-19T16:45:02.851Z",
"Name": "Orca Scan Validation"
}'
- Only Orca Scan system fields start with
___
- Properties in the JSON payload are an exact match to the field names in your sheet (case and space)
This example uses the srping boot framework:
@RequestMapping(
value = "/",
method = RequestMethod.POST)
ResponseEntity<String> index(@RequestBody Map<String, Object> data) throws Exception {
// debug purpose: show in console raw data received
System.out.println(data);
// NOTE:
// orca system fields start with ___
// you can access the value of each field using the field name (data.get("Name"), data.get("Barcode"), data.get("Location")
String name = data.get("Name").toString();
// validation example
if (name.length() > 20){
// return error message
JSONObject json = new JSONObject();
json.put("title", "Invalid Name");
json.put("message", "Name cannot contain more than 20 characters");
return new ResponseEntity<>(json.toJSONString(), HttpStatus.OK);
}
// return HTTP Status 200 with no body
return new ResponseEntity<>("", HttpStatus.OK);
}
To expose the server securely from localhost and test it easily agaisnt the real Orca Cloud environment you can use Secure Tunnels. Take a look at Ngrok or Cloudflare.
ngrok http 8080
If you run into any issues not listed here, please open a ticket.
- orca-validation-dotnet
- orca-validation-python
- orca-validation-go
- orca-validation-java
- orca-validation-php
- orca-validation-node
For change-log, check releases.
© Orca Scan, the Barcode Scanner app for iOS and Android.