18 | | The REP is basically the **adapter to the SENSEI system that needs to be implemented**. |
19 | | The Java REP reference implementation provides some helpers to Resource Providers. |
20 | | The stubs for RPI and RAI methods are given in the example code. |
| 18 | The REP is basically the **adapter to the SENSEI system that needs to be implemented**. |
| 19 | The Java REP reference implementation provides some help to Resource Providers showing an example using the Restlet framework. |
| 20 | |
| 21 | The REP class provides a method **createInboundRoot()** in which the routing of REST requests is defined. In the example below all requests issued to {REP_URL}/s/sensorName are routed to the handler class **Sensor Type** |
| 22 | |
| 23 | {{{ |
| 24 | @Override |
| 25 | public synchronized Restlet createInboundRoot() { |
| 26 | |
| 27 | // Create a router Restlet that defines routes. |
| 28 | Router router = new Router(getContext()); |
| 29 | |
| 30 | // attach the RAI handler class |
| 31 | String path = "/s/{sensorName}"; |
| 32 | Class<SensorType> handler = SensorType.class; |
| 33 | router.attach(path, handler); |
| 34 | |
| 35 | return router; |
| 36 | } |
| 37 | }}} |
| 38 | |
| 39 | The parameter sensor Name is taken from the URL used for the HTTP request so that the route can be used for temperature values as well as light values. In the first case the request would be http://{REP_URL}/s/temp in the light value case it would be http://{REP_URL}/s/light. |
| 40 | |
| 41 | The different handling for temp and light is implemented in the **RAI handler** class called Sensor Type in the example code. |