Connecting the Oracle Sensor Edge Server to a Simple Application via HTTP
Connecting Oracle Sensor Edge Server to a Simple Application
via HTTPThis tutorial describes how to write a simple JavaServer Pages
(JSP) application to receive sensor events from Oracle Sensor Edge Server. Approximately 35 minutes
This
tutorial covers the following topics:
Place the cursor over this icon to load and view all
the screenshots for this tutorial. (Caution: This action loads all screenshots
simultaneously, so response time may be slow, depending on your Internet connection.)
Note:
Alternatively, you can place the cursor over each individual icon in the following
steps to load and view only the screenshot associated with that step.
Oracle
Sensor Edge Server provides companies that want to adopt Radio Frequency Identification
(RFID) technology with a comprehensive set of capabilities to capture, manage,
analyze, access, and respond to data from different sensors such as RFID, location,
and temperature. On the basis of Oracle's mature, proven technology (including
Oracle Database 10g, Oracle Application Server 10g, Oracle Enterprise
Manager 10g, and Oracle E-Business Suite 11i),
Oracle sensor-based services enable companies to quickly and easily integrate
sensor-based information into their enterprise systems to gain near real-time
supply chain visibility and leverage this insight to optimize business process. The
primary goal of the Sensor Edge Server is to transform raw data from the physical
world into meaningful business events in your Enterprise Information System. This
can be achieved in a closed loop, directly on the Sensor Edge Server, or by sending
events to an Enterprise Information System. Access to the raw data and additional
contextual and system information is always available through the data repository. In
this tutorial, you use the Sensor Edge Server to connect a simple JSP application
to an RFID device. You integrate the application with the Sensor Edge Server and
add a simulation driver to simulate an RFID device. As a result of this integration,
you see the events generated by the Sensor Edge Server and the simulation driver.
After you complete this tutorial, you learn how to configure sensor information
and integrate it with existing applications by using Oracle Sensor Edge Server. 
The
Oracle Sensor Edge Server architecture is made up of four primary components:
Device Drivers, Local Processing and Filtering, Dispatchers, and Management. Device
drivers: Device drivers are components that communicate with all kinds
of sensors and devices such as RFID readers and message boards. They are responsible
for normalizing data from various devices into the standard format. Drivers can
be organized into logical groups. This enables administrators to manage them efficiently.
Oracle Sensor Edge Server can have one or many device groups instantiated. Each
device group is responsible for the device driver that it manages. Local
processing and filtering: Local processing (filters and rules) removes
unwanted or low-level events. Filters generate logical events such as In field
and Out field. Local processing can be bound to individual devices or groups of
devices. Dispatchers: The dispatcher is
the central processing engine for event delivery. The process is started on startup.
The process loads the rest of the components, which include the driver manager
and (on start up) the event dispatcher. Internally, it reads the configuration
to find out which event dispatcher to load. Management
and administration console: Management is provided at different levels: Server
management: The server can be administered with the Sensor Edge Server (SES) Admin
Console, JMX, or Enterprise Manager. Data management: Data is configured,
organized, and stored in the Sensor Data Repository as a single source of truth. Development
Service: This service provides API access for developers to manage SES with custom
solutions. For this tutorial, you plug in a simulator driver
in the driver framework to simulate the RFID reader. You do not use a filter.
For the dispatcher layer, you use the HTTP Dispatcher to send events to a JSP
application that is waiting for these events. Back
to Topic List Before starting this tutorial, you should:
| 1. |
Have access to or have installed Oracle JDeveloper 10g.
You can download Oracle JDeveloper 10g from here. |
| 2. | Have
access to or have installed Oracle Application Server 10g Release 3 (10.1.3).
You can download Oracle Application Server 10g 10.1.3 software from here. | | 3. | Have
access to or have installed Oracle Sensor Edge Server 10.1.3. You can download
Oracle Sensor Edge Server software from here. |
Back to Topic List To demonstrate how an application
can consume SES events, you create a simple JSP application. You can create a
JSP application by using JDeveloper. To create a JSP page, perform the following
steps:
1. | Start
JDeveloper. Close the Connections palette. Select Applications in Applications
Navigator. Right-click and select New Application from the shortcut menu.
| 2. | Change
the application name to SensorApp. Click OK. 
|
| 3. | The
Create Project dialog box appears. Enter Sensorprj in the Project
Name field, and click OK. |
| 4. | Right-click
the project in Applications Navigator, and select New from the shortcut
menu. | | 5. | Expand
Web Tier under categories. Select JSP, and then select JSP
from Items. Click OK. | | 6. | Click
Next in the Welcome window. | | 7. | In
the Create JSP window, select Servlet 2.4\JSP 2.0 (J2EE 1.4). Click Next. | | 8. | Enter
ReceiveEvent.jsp in the File Name field. Click Finish. | | 9. | You
can see the Design view and Source view of ReceiveEvent.jsp. You also see
Component Palette and the Property Inspector palette on the right. Close Component
Palette and the Property Inspector palette. Click the Source tab. You see the
source code for ReceiveEvent.jsp. | Back to Topic List Add code to
the JSP page to read events. You read only three parameters: type, id, and time.
| 1. | Modify ReceiveEvent.jsp
to retrieve and print parameter values from the request. Copy the following code,
and paste it to the <body> tag of ReceiveEvent.jsp. <% long
type = 0; String tagId = null; String timeStr = null; //Get Event Parameters try { //Available
Parameters: //id, siteName, deviceName, data, time, type, subtype, //sourceName,
correlationId type = Long.parseLong(request.getParameter("type")); tagId
= request.getParameter("id"); timeStr = request.getParameter("time"); } catch
(Exception e) { out.println("Error:
"+e.getMessage() ); }
%> <p>For
browser debug;
<% //
Display to screen for browser test out.println(
"Type="+type+" ID="+tagId +" time="+timeStr );
%> Note
that you are receiving three parameters from the event: type: Specifies
the event type id: Holds the name or hexadecimal number of the device time:
Holds the time stamp of when the tag was read |
| 2. | Click the plus (+) sign next
to Web Content. Right-click ReceiveEvent.jsp, and select Run. Note
the URL for the application. In the example, the URL is http://139.185.35.125:8988/SensorApp-Sensorprj-context-root/ReceiveEvent.jsp.
| | 3. | You see
the application running in the default browser. Note
that the parameter values are null because you have not passed any parameters
yet. | | 4. |
Add the following code to the <body> tag of the JSP page. The
events are written to the events.log file. Observe the path for the events.log
file. <%
//Write events to file try { // Open file String fileName = application.getRealPath("/WEB-INF/events.log"
); java.io.PrintWriter pw = new java.io.PrintWriter( new java.io.FileWriter(
fileName, true ) ); // Print line out to file pw.println( "Type="+type+"
ID="+tagId +" time="+timeStr ); pw.close(); out.println(
"Written to file" ); } catch (Exception e) { out.println(
"Error: Cannot write to file" ); } %>
Run
the .jsp file. | Back
to Topic List
Oracle Sensor
Edge Server collects sensor information, filters it, and performs local sensor
event processing. Oracle Sensor Edge Server then securely and reliably dispatches
event data back to the central applications or databases. You perform Oracle Sensor
Edge Server administration, configuration, and monitoring using the SES console. You use the HTTP Dispatcher to test the application with the Sensor
Edge Server. You have to configure the server for the HTTP Dispatcher. You use
the SES console to configure the HTTP Dispatcher and specify the parameters. When
the Sensor Edge Server starts up, it checks the configuration and loads all the
necessary components and extensions. You also see how to configure a simulator
to send events. The simulator generates fake events that are based on a specified
input file. This simulator driver is very useful for testing and to see how events
are processed throughout the system. To test the
application with the Sensor Edge Server, perform the following steps: Back
to Topic List Configure
the Dispatcher
| 1. | Open your browser, and
enter the following URL: http://<host
name>.<domain>:<port>/edge For
example, http://localhost:8888/edge. Log in as oc4jadmin with the OC4J
administrator password that you specified during installation. Click Login. |
| 2. | The navigation
tree, which displays on each page of the SES console, enables you to browse all
available extensions and to configure groups and instantiated extensions. | | 3. | The
main output of Oracle Sensor Edge Server is filtered data events. Both the devices
and respective filters normalize and minimize this event data. Configuring the
dispatcher to route events to clients using HTTP 1.0 results in Oracle Sensor
Edge Server posting each event message to the client separately. Change Log Level
to monitor in General Settings. Click Change dispatcher to change
the dispatcher used by Oracle Sensor Edge Server. | | 4. | The
Search and Select: Change current dispatcher page appears. Select
Http Dispatcher. Click Select. | | 5. | Provide
the URL of your JSP application in the Value field of the url parameter. Click
Save Changes. | | 6. | An
Oracle Sensor Edge Server instance uses only one dispatcher at a time. After you
assign a dispatcher as current, the Oracle Sensor Edge Server instance must be
restarted. The SES console displays a message notifying you to restart the Oracle
Sensor Edge Server instance using OracleAS Enterprise Manager. You can restart
the Oracle Sensor Edge Server instance later, after you have configured the simulator. |
Back to Topic Configure
the Simulator
| 1. | Creating a device group
is the first step to connecting the Oracle Sensor Edge Server instance to devices
and filters. After you create a device group, you populate it with devices (the
instances of the available drivers) and then attach filter instances to the individual
devices (or to the entire device group). To create a new device group, click
Groups. |
| 2. | On the Group Management
page, enter SES in the Group Name field. Click Create New Group.
| | 3. | The
Configure Group page appears for the new device group. Click Add new device
to create a device for the device group. | | 4. | The
Search and Select: Add new device page appears, listing the drivers
in the repository. Select Edge Simulator Driver. Click Select. | | 5. | The
Configure Group page reappears, listing the device in the Devices section. Click
Edge Simulator Driver1. | | 6. | The
Device Configuration page appears, displaying the parameters specific to the driver. | | 7. | The
Edge Simulator Driver generates events to simulate a real device. The Edge Simulator
Driver behaves the same way as any driver, except that instead of connecting to
a physical device to read events, it takes parameters from an input file such
as Simulation.xml. The input file provides instructions about when to generate
events. Scroll down to the Parameters section. The simulator has one parameter,
which is the file name of the input file, that you need to set. Enter the path
for the Simulation.xml file in the Value field of the Filename parameter.
Click Save Changes. | | 8. | A
sample Simulation.xml file looks like this: <EdgeEventSimulation> <EventList
repeat=1> <Event> <type>100</type> <subtype>1</subtype> <id>03ffff045679</id> <data>No
Data</data> <deviceName>My Device</deviceName>
</Event> ......... .......... ...........
</EventList>
</EdgeEventSimulation> The
<EventList> element defines a loop. This element is also the main
block that groups all the other instructions together. The <EventList> element
has one attribute, repeat, which must be present to control looping. The value
for repeat must be a decimal number from 0 to LONG_MAX. The <EventInterval>
element instructs the simulator to pause for a certain period of time before proceeding. The
<type> element represents the number value that corresponds to the type
of event. The <subtype> element represents the number value
for the subtype. For example, the subtype value corresponds with a General Instruction
Event, which is an event sent by the application or device to instruct a specific
device to perform an operation. The value 1 turns on the device. The
<id> element represents a text value that identifies a tag (that is,
a read or target) to an event instruction. One of the <id> values for a
tag is 03ffff045679. The <data> element is optional. The
<deviceName> element represents the name of the device or application
that generates the event. The <deviceName> enables the simulator to appear
as if it is another device when generating events. | | 9. | When
you make any change in an Oracle Sensor Edge Server instance, the SES console
displays a message notifying you to restart the Oracle Sensor Edge Server instance
using OracleAS Enterprise Manager. Click the Enterprise Manager link in
the message. | | 10. | The
Login page for OracleAS Enterprise Manager appears. Enter the OC4J username and
password. Click Login. | | 11. | Click
the home link on the Cluster Topology page. | | 12. | Click
Applications.
| | 13. | Select edge,
and click Restart. | | 14. | Click
Yes on the Confirmation page. | | 15. | The
Oracle Sensor Edge Server instance has been restarted successfully. |
Back to Topic
Monitor the Event Data
| 1. | Open your browser, and enter the following
URL: http://<host name>.<domain>:<port>/edge For
example, http://localhost:8888/edge. Log in as oc4jadmin with the OC4J
administrator password that you specified during installation>. Click Login. |
| 2. | The SES console enables
you to know the condition of Oracle Sensor Edge Server from the event data that
is displayed on the Monitor Events and Event Reports tabbed page. Click the Monitor
Events tab to view the data currently in the queue. The inbound and outbound
event data includes: Type: Text representation of the event type
Description: A text representation of the event subtype Device Name:
The name of the device that generated the event Data: The payload of
the event Time: The time that the event was generated |
Back to Topic In
this lesson, you learned how to:
 | Integrate
a simple JSP application with Oracle Sensor Edge Server |
 | Configure
the HTTP Dispatcher for the JSP application |  | Plug
in a simulator to simulate an RFID device | Back
to Topic List To
learn more about JDeveloper, you can refer to:
 |
Additional OBEs
on the OTN Web site. |  | Demonstration
material (viewlets
) | Back
to Topic List
Place the cursor over this icon to hide
all screenshots.
|