Example Code

The following Java codesnip shows how easy it is to develop a client application using FSI Servers API. Only a few lines of code are necessary to log in, upload an image and log out again. The example requires the FSI Server Dev Pack which can be downloaded from https://www.neptunelabs.com/ as well as the Jersey Client bundle available at http://jersey.dev.java.net. The FSI Server Dev Pack contains a jar file which includes the JAXB classes representing the request and response messages as described in "Messages used in Management Requests".

// initialize client
ApacheHttpClientConfig clientconfig =
new DefaultApacheHttpClientConfig();
Client c = ApacheHttpClient.create(clientconfig);
// send a GET request to obtain the salt
WebResource r =
SaltResponse sr = r.get(SaltResponse.class);
String salt = sr.salt;
// combine password with salt and generate login hash
String passwordhash = randomHelper.sha256(password);
String loginhash = randomHelper.sha256(salt + passwordhash);
// send login request
Form form = new Form();
form.add("username", username);
form.add("password", loginhash);
LoginResponse lr = r.post(LoginResponse.class, form);
if (lr.state.equals("success")) {
// create object to upload
Image i = new Image();
File imagefile = new File(testfile);
byte[] filedata = ... // read from disk …
// create resource to upload the image to
WebResource imageresource
= c.resource("http://your.fsi-server.com/"
+ "fsi/service/image/samples/image.tif");
// upload the image using a PUT request
ActionResponse ar =
imageresource.put(ActionResponse.class, i);
[ … check status and handle errors … ]
// logout
WebResource logoutresource
= c.resource("http://your.fsi-server.com"
+ "/fsi/service/logout");