Legal | Privacy
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:

Overview
Prerequisites
Creating a Simple JSP Application
Reading the Events and Writing the Events to a File
Summary
Related Information

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.

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.

 

Prerequisites

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)

 

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.

Move your mouse over this icon to see the image


2.

Change the workspace name to SensorApp. Click OK.

Move your mouse over this icon to see the image

 

3.

The Create Project dialog box appears. Enter Sensorprj in the Project Name field, and click OK.

Move your mouse over this icon to see the image

 

4.

Right-click the project in System-Navigator and select New from the shortcut menu.

Move your mouse over this icon to see the image

 

5.

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

Move your mouse over this icon to see the image

 

6.

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

Move your mouse over this icon to see the image

 

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.

Move your mouse over this icon to see the image

 

 

 

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 ); %>

Move your mouse over this icon to see the image

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.

Move your mouse over this icon to see the image

 

3.

You see the application running on the default browser.

Move your mouse over this icon to see the image

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" );
}

%>

Move your mouse over this icon to see the image

Run the jsp file.

 

 

 

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
Configure the Dispatcher
Configure the Simulator

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.

Place the cursor over this icon to see the image

 

2.

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

Place the cursor over this icon to see the image

 

3.

The Application Server home page is displayed.

Place the cursor over this icon to see the image

 

4.

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

Place the cursor over this icon to see the image

 

5.

Look for Standalone Processes table and click Add.

Place the cursor over this icon to see the image

 

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.

Place the cursor over this icon to see the image

 

7.

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

Place the cursor over this icon to see the image

 

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.

Place the cursor over this icon to see the image

Place the cursor over this icon to see the image

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.

Place the cursor over this icon to see the image

Place the cursor over this icon to see the image

 

2.

Click the Sensor Services tab.

Place the cursor over this icon to see the image

 

3.

Click Manage Edge Dispatchers.

Place the cursor over this icon to see the image

 

4.

Click Create to create a new dispatcher.

Place the cursor over this icon to see the image

 

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.

Place the cursor over this icon to see the image

 

6.

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

Place the cursor over this icon to see the image

 

Back to Topic

Configure the Simulator

1.

Click the Edge Devices link.

Place the cursor over this icon to see the image

 

2.

Click Create to create a new device.

Place the cursor over this icon to see the image

 

3.

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

Place the cursor over this icon to see the image

 

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.

Place the cursor over this icon to see the image

Place the cursor over this icon to see the image

 

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.

Place the cursor over this icon to see the image

 

2.

Click Yes for confirmation.

Place the cursor over this icon to see the image

Place the cursor over this icon to see the image

 

3.

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

Place the cursor over this icon to see the image

 

4.

Select edge_server_demo, and click Start to start the server.

Place the cursor over this icon to see the image

Place the cursor over this icon to see the image

 

5.

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

Place the cursor over this icon to see the image

 

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.

Place the cursor over this icon to see the image

 

 

 

In this lesson, you have learned how to:

Integrate a simple JSP application with Oracle Sensor Edge Server

Configure HTTP Dispatcher for JSP application

Plug in a simulator to simulate an RFID device
Write the generated events to a file

Related Information

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.

 

 

 

 

E-mail this page
Printer View Printer View
Oracle Is The Information Company About Oracle | Oracle RSS Feeds | Careers | Contact Us | Site Maps | Legal Notices | Terms of Use | Privacy