Connecting the Oracle Sensor Edge Server to a simple application via HTTP
Connecting the Oracle Sensor Edge Server to a Simple
Application via HTTP
This tutorial describes how to write a simple JSP application
to receive sensor events from the 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: Because this action loads all screenshots
simultaneously, 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.
Back to Topic List
|
OracleAS Wireless Sensor Edge Server is a middle-tier
component that integrates sensors and other types of command or response
indication equipment with applications. Sensors are hardware or software
end points that make observations of certain changes of state. The Sensor
Edge Server uses these sensors to integrate sensor data and applications.
Sensor Edge Server is available as both stand-alone (Java edition) and
Enterprise Edition. For this tutorial, we are using the Enterprise Edition.
In this tutorial, you use the Sensor Edge Server to
connect a simple JSP application to a Radio Frequency Identification (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. You write these events to a file. However, you
can even store these events in a database. After you complete this tutorial,
you learn how to configure and integrate sensor information to existing
applications by using Oracle Sensor Edge Server.
|

|
The Sensor Edge Server is made up of three primary components:
the driver framework, the filter framework, and the dispatcher framework.
Device Drivers: Device Drivers are components
that communicate with all kinds of sensors and devices such as RFID readers,
message boards, and so on. They are responsible for normalizing data from various
devices into the standard format.
Filters: Filters generate logical events such as
In field, Out field, and so on. They remove unwanted or low-level events.
Filters can be bound to individual devices or groups of devices.
Dispatchers: Dispatchers are responsible for dispatching
the normalized and filtered data to your application.
For this tutorial, we plug in a simulator driver
in the driver framework to simulate RFID reader. We do not use a filter.
For the dispatcher layer, we use the HTTP dispatcher to send events
over to a JSP application that is waiting for these events. These events
are written to a text file.
|
Back to Topic List
Before starting this tutorial, you should:
| 1. |
Have installed Oracle JDeveloper
10g |
| 2. |
Have installed Oracle Application Server 10g Infrastructure
|
| 3. |
Have installed Oracle Application
Server 10g Portal and Wireless |
| 4. |
Have downloaded the zip file
Simulation.zip
and extracted it to drive E (E:\Simulation.xml) |
Back to Topic List
You can create a JSP application by using JDeveloper. To create
a JSP page, perform the following steps:
| 1. |
Start JDeveloper. Select Workspaces in System - Navigator. Right-click
and select New Workspace from the shortcut menu.
|
| 2. |
Change the workspace 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 System-Navigator and select New
from the shortcut menu.

|
| 5. |
Expand Web Tier under categories. Select JavaServer Pages (JSP)
and then select JSP Page from Items. Click OK.

|
| 6. |
Enter ReceiveEvent.jsp in the File Name field, and click OK.

|
| 7. |
You see the Design view and Source view of ReceiveEvent.jsp.
You also see the component palette on the
right. Close the component 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. We read
only three parameters: type, id, and time.
|
| 1. |
Modify ReceiveEvent.jsp to retrieve and print parameter values
from the request. Copy and paste the following code 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 we 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. |
Right-click ReceiveEvent.jsp and select Run. Note the URL
for the application. In our example, the URL is
http://localhost:8988/SensorApp-Sensorprj-context-root/ReceiveEvent.jsp.

|
| 3. |
You see the application running on the default browser.

Note that the parameter values are null because we have not passed any
parameters yet.
|
| 4. |
Add the following code to the <body> tag of the JSP Page.
The events are written to 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
|
We use the HTTP Dispatcher to test the application
with Sensor Edge Server. You have to configure the server for HTTP Dispatcher.
You use the webtool to configure HTTP Dispatcher and specify 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. Simulator generates fake events based on a
specified input file. This driver is very useful for testing and to see
how events are processed throughout the system.
To test the application with Sensor Edge Server, perform
the following steps:
|
Create a Stand-Alone Process
| 1. |
Open your Browser and enter the following URL:
http://<hostname>:1811/
Log in as ias_admin/<admin password you specified during
installation>. Click OK.

|
| 2. |
Click the middle-tier instance to go to the instance home page.

|
| 3. |
The Application Server home page is displayed.

|
| 4. |
Scroll down to see the System Components table, and click Wireless to
open the Wireless home page.

|
| 5. |
Look for Standalone Processes table and click Add.

|
| 6. |
Select Edge Server from the Process Type drop-down list.
Enter a name for the process in the Process Name field. In this
tutorial, we have used edge_server_demo as process name. Click
Continue.

|
| 7. |
Enter a name for Group in the Group Name field, and click Finish.

|
| 8. |
Observe that the edge_server_demo process is created but it is
not yet started. Select the process and click Start to start the
process that you just created.


Click OK when the message "edge_server_demo has been
started" appears.
|
Back to Topic
Configure the Dispatcher
| 1. |
Open another browser window and enter the following
URL:
http://<hostname>:7778/webtool
Log in as orcladmin/<orcladmin password you specified during
installation>. Click
Login.


|
| 2. |
Click the Sensor Services tab.

|
| 3. |
Click Manage Edge Dispatchers.

|
| 4. |
Click Create to create a new dispatcher.

|
| 5. |
Enter a name for the dispatcher. Select HTTP Dispatcher from the
Dispatcher drop-down list. Provide the URL of your JSP application
in the value field of the url parameter. Click Finish.

|
| 6. |
Select the dispatcher if it is not selected, and click Set Current
to set this dispatcher as the current dispatcher.

|
Back to Topic
Configure the Simulator
| 1. |
Click the Edge Devices link.

|
| 2. |
Click Create to create a new device.

|
| 3. |
Enter a name for the simulator. Select Edge Simulator Driver from
the Driver drop-down list, and click Go.

|
| 4. |
The simulator has one parameter that you need to set, which is the file name
of the input file. Enter the path for the Simulation.xml file in
the Value field of FileName parameter. Click Finish.


|
Back to Topic
Test the Application
| 1. |
Restart the edge server process that you created.
Return to the browser window that you used for creating a stand-alone
process. Select edge_server_demo, and click Stop.

|
| 2. |
Click Yes for confirmation.


|
| 3. |
Click OK when the message "edge_server_demo has been
stopped" appears.

|
| 4. |
Select edge_server_demo, and click Start
to start the server.


|
| 5. |
Click OK when the message "edge_server_demo has been
started" appears.

|
| 6. |
A file events.log must be created in the following location <jdev_home>\jdev\mywork\SensorApp\Sensorprj\public_html\WEB-INF.
Open the file and observe the events generated by the simulator.

|
Back to Topic List
In this lesson, you have learned how
to:
 |
To ask a question about this OBE tutorial, post a query on the OBE
Discussion Forum |
Place the cursor over this icon to hide all screenshots.
Copyright © 2004 Oracle Corporation. All Rights Reserved.
|