Restful Service Integration Jumpstart

From RifidiWiki

Jump to: navigation, search

Create a RifidiApp

  • 1. Create a RifidiApp. First, be sure to set up a developer environment using these steps.

Then check the developer guide for creating your own Rifidi App. Check the section starting at "Importing a Project Template" on page 5 for how to do this.

After your application is set up, you'll have to choose how you want to receive your tags. Tags that are read by RFID readers will be inserted into an event processing engine called Esper. There are a few different ways to receive these tags, as outlined here:

Import Rifidi Services

  • 2. You can use one of the default services to send and receive tags. You can see a description of the default services here.

You can also see an example of the two services in action in the "Northwind" example (specifically, the "ReadZoneMonitoringService" and the "StableSetService"). See the developer's guide for an overview of the Northwind example. The source code for the example (which can be imported as a project) is in the "apps" folder of the SDK.

Taking the ReadZoneMonitoringService as an example, a method will be called on designated classes whenever a tag arrives or departs. You can find out the ID of this tag (as well as other useful information) and then do whatever you wish with it, including writing the event to a cloud or to social media.

Create Custom Esper Rules

  • 3. You can also write your own custom Esper rules, usually in concert with the ReadZoneMonitoringService. You can find out how to create custom Esper rules at the Custom Esper Rules Jumpstart page.

Add Third Party Libraries

Restful Service Code snippet

  • 5. Here is an example code snippet on how to invoke a restful service call within Rifidi to publish events from Rifidi services such as tag arrived or departed events
	public void changeReader(TagReadEvent tag, String readerID) 
          { logger.debug("Changing reader: " + tag + " to reader " + readerID); 
             this.sendWebServiceMessage(tag, readerID); } 

      public void sendWebServiceMessage(TagReadEvent tag, String readerID) { 
         try {
           System.out.println("Sending a message: " + tag); 
          URL obj = new URL(this.webserviceAddress); 
          HttpURLConnection con = (HttpURLConnection) obj.openConnection(); 
          //add reuqest header 
          con.setRequestMethod("POST"); 
           con.setRequestProperty("Accept-Language", "en-US,en;q=0.5"); String urlParameters = tag.getTagID() + "/" + tag.getReaderID();
        // Send post    request 
            con.setDoOutput(true); DataOutputStream wr = new DataOutputStream(con.getOutputStream()); 
          wr.writeBytes(urlParameters); wr.flush(); 
          wr.close(); 
       int responseCode = con.getResponseCode(); 
       if(responseCode!=this.webserviceSuccessInt)
         {} 
         catch(Exception e) { //Exception occured... logger.error("Exception occured when trying to send webservice message: " + e.getMessage()); 
           } 
}


Personal tools