Published on WSO2 Oxygen Tank (http://wso2.org)

Earthquake Information via WSO2 Data Services

By sumedha
Created 2008-01-30 23:36

"An earthquake is the way the earth relieves its stress, by transferring it to the people who live on it" - (http://itsyourfault.net/ [1])

Introduction 

USGS (http://www.usgs.gov [2]) provides reliable scientific information to describe & understand the Earth. As part of its services, USGS hosts latest earthquake information in comma separated (CSV) text files online.

WSO2 Data Services is capable of exposing data in CSV files as services over the web.

This guide explains how to combine these two features & create a web service that will expose earthquake information – the SOA way. 

Step 1

1. Download latest version of WSO2WSAS from http://dist.wso2.org/products/wsas/java/ [3]

2. Install it as a standalone server (Install location will be referred to as WSAS_HOME hereafter.)

3. Start WSO2WSAS-<VERSION> (run WSAS_HOME/bin/wso2wsas.bat | wso2wsas.sh)

4. Open a web browser & navigate to https://localhost:9443/ [4]

5. Login to WSAS (using Username/password = admin/admin) & get yourself familiar.

 

Step 2 : Creating service descriptor

Create a file called EarthquakeInfoService.dbs containing following. This is the service description file for our service. 

<data name="EarthquakeInfoService">
<config>
<property name="csv_datasource">http://earthquake.usgs.gov/eqcenter/catalogs/eqs1day-M1.txt</property>
<property name="csv_columnseperator">,</property>
<property name="csv_columns">Src,Eqid,Version,Datetime,Lat,Lon,Magnitude,Depth,NST</property>
<property name="csv_columnordinal">1,2,3,4,5,6,7,8,9</property>
<property name="csv_startingrow">2</property>
<property name="csv_maxrowcount">-1</property>
<property name="csv_hasheader">true</property>
</config>

<query id="fullEarthquakeList">
<result element="Earthquakes" rowName="Earthquake" defaultNamespace="http://eq.myservice.org">
<element name="Source" column="1" />
<element name="Eqid" column="2" />
<element name="Version" column="3" />
<element name="Datetime" column="4" />
<element name="Latitude" column="5" />
<element name="Longtitude" column="6" />
<element name="Magnitude" column="7" />
<element name="Depth" column="8" />
<element name="NST" column="9" />
</result>
</query>

<operation name="getEarthquakesForPastDay">
<call-query href="fullEarthquakeList" />
</operation>
</data> 

This will read CSV file available @ http://earthquake.usgs.gov/eqcenter/catalogs/eqs1day-M1.txt [5] and expose its 9 columns conforming to following xml format.  

<data:Earthquakes>
<Earthquake>
<Source>VALUE</Source>
<Eqid>VALUE</Eqid>
<Version>VALUE</Version>
<Datetime>VALUE</Datetime>
<Latitude>VALUE</Latitude>
<Longtitude>-VALUE</Longtitude>
<Magnitude>VALUE</Magnitude>
<Depth>VALUE</Depth>
<NST>VALUE</NST>
</Earthquake>
.....
.....
.....
</data:Earthquakes>

This format is defined in the following section of EarthquakeInfoService.dbs.

<result element="Earthquakes" rowName="Earthquake" defaultNamespace="http://eq.myservice.org">
<element name="Source" column="1" />
<element name="Eqid" column="2" />
<element name="Version" column="3" />
<element name="Datetime" column="4" />
<element name="Latitude" column="5" />
<element name="Longtitude" column="6" />
<element name="Magnitude" column="7" />
<element name="Depth" column="8" />
<element name="NST" column="9" />
</result>

You can replace “element” with “ attribute” to get response as attributes.

 

Step 3 : Uploading service descriptor to WSAS

Service Upload 

 

Step 4 : Testing Service

Try it

 <<image>>

Browser URL – using SOAP HTTP binding

http://localhost:9762/services/EarthquakeInfoService/getEarthquakesForPastDay

 Accessing service using SOAP http binding

 

 

 

 

 

 

 


Source URL:
http://wso2.org/blog/sumedha/3157