REST Examples
The example code on this page shows how a small Java application can be used to communicate with the SLA webservices. Of course, webservices are language and platform neutral.
RestXMLClient
This simple example shows how to upload the batch data as an XML file using the REST webservice. It only requires Java SDK 1.5 and does not depend on any additional software packages to compile or run.
- Verify that you have a correct Java SDK and Runtime Environment:
java -version (the first line of output should say: java version "1.5.0_13")
javac -version (the first line of output should say: javac 1.5.0_13)
The exact version number may differ as long as it is at least version 1.5. Ideally the Java Runtime Environment version and the SDK version matches each other.
- If you haven't already done so, extract the keys and certificates from the zipfile that you received from the SLA. You will need the Broker*-key.p12 file which will be used as Keystore and the SLAtestCA-cacert.jks file which will be used as Truststore. For test purposes you can place those two files into the same directory from which you will run the sample application.
- Download the source code for this example: RestXMLClient.java
- Edit the RestXMLClient.java source code to reflect the correct location and filenames of the Truststore and Keystore. At the very least you will need to change the name of the Keystore from Broker9999-key.p12 to reflect your SLA Broker Number.
- Compile the sample application: javac RestXMLClient.java (This will create the RestXMLClient.class file)
- Create a sample SLACAL_BATCH XML file.
- Run the sample application to upload the batch data: java RestXMLClient sample.xml (this assumes you named the file sample.xml)
- If everything went fine, you should get a response with an SLA Batch Id.
RestImageClient
This simple example shows how to upload a single document image file using the REST webservice. It requires Java SDK 1.5 and the Base64 class from Robert Harder (Public Domain). No other software is required to compile or run this example.
- Verify that you have a correct Java SDK and Runtime Environment:
java -version (the first line of output should say: java version "1.5.0_13")
javac -version (the first line of output should say: javac 1.5.0_13)
The exact version number may differ as long as it is at least version 1.5. Ideally the Java Runtime Environment version and the SDK version matches each other.
- If you haven't already done so, extract the keys and certificates from the zipfile that you received from the SLA. You will need the Broker*-key.p12 file which will be used as Keystore and the SLAtestCA-cacert.jks file which will be used as Truststore. For test purposes you can place those two files into the same directory from which you will run the sample application.
- Download the source code for the example application: RestImageClient.java
- Download the source code for the required Base64 class: Base64.java (This class is used to encode the binary document image data into text format)
- Edit the RestImageClient.java source code to reflect the correct location and filenames of the Truststore and Keystore. At the very least you will need to change the name of the Keystore from Broker9999-key.p12 to reflect your SLA Broker Number.
- Compile the sample application: javac RestImageClient.java (This will produce the .class files for both Base64.java and RestImageClient.java)
- Find or create a suitable document image file to be used as sample image.
- Run the sample application to upload the document image: java RestImageClient sample.img (this assumes you named the file sample.img)
- This sample application is interactive and will prompt you for information about the image file that is to be uploaded (SLA and Broker Batch identification, Item and Page number, etc.). Since all those fields are optional you can hit enter without providing an answer. Obviously in production meaningful values should be provided so that the images can be associated with the correct batch.
- If everything went fine, you should get a response with a message that the image upload was successful.
RestBatchUpload
This example shows how to upload an entire Batch using both of the REST webservices. It combines the previous two examples and requires Java SDK 1.5 and the Base64 class from Robert Harder (Public Domain). No other software is required to compile or run this example.
- Verify that you have a correct Java SDK and Runtime Environment:
java -version (the first line of output should say: java version "1.5.0_13")
javac -version (the first line of output should say: javac 1.5.0_13)
The exact version number may differ as long as it is at least version 1.5. Ideally the Java Runtime Environment version and the SDK version matches each other.
- If you haven't already done so, extract the keys and certificates from the zipfile that you received from the SLA. You will need the Broker*-key.p12 file which will be used as Keystore and the SLAtestCA-cacert.jks file which will be used as Truststore. For test purposes you can place those two files into the same directory from which you will run the sample application.
- Download the source code for the example application: RestBatchUpload.java
- Download the source code for the required Base64 class: Base64.java (This class is used to encode the binary document image data into text format)
- Edit the RestBatchUpload.java source code to reflect the correct location and filenames of the Truststore and Keystore. At the very least you will need to change the name of the Keystore from Broker9999-key.p12 to reflect your SLA Broker Number.
- Compile the sample application: javac RestBatchUpload.java (This will produce the .class files for both Base64.java and RestBatchUpload.java)
- Create a temporary directory for your entire batch (data and images): mkdir my_batch
- Create a sample SLACAL_BATCH XML file (or download an example) and place it into the directory created in the previous step: cp sample.xml my_batch
- Create subdirectories for each Item in the batch: mkdir my_batch/item1; mkdir my_batch/item2; ...
- Find or create a suitable document image files to be used as sample images and copy them into the item# subdirectories. Note: image files copied into the top level directory are associated with the entire batch instead of a specific item.
- Run the sample application to upload the batch: java RestBatchUpload my_batch (this assumes you named the directory my_batch)
- If everything went fine, you should get a response with a message with the SLA_Batch_Id and how many images were uploaded.