/*
* Copyright 2005-2007 WSO2, Inc. http://www.wso2.org
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
this.documentation =
The RESTSample service demonstrate the use of httpmethod and httpLocation annotations to develop RESTy mashups.
;
this.scope="application";
var cities;
initialise.visible = false;
function initialise()
{
cities = session.get("cities");
if ( cities == null )
{
var cities = [];
session.put( "cities", cities );
}
}
getWeather.safe = true;
getWeather.httpMethod = "GET";
getWeather.httpLocation = "weather";
getWeather.inputTypes = "none";
getWeather.outputType = "string";
function listWeather()
{
initialise();
var weatherlist = new XML();
weatherlist = ;
cities = session.get("cities");
for ( var i = 0; i < cities.length; i++ )
{
var weatheritem = new XML();
weatheritem = ;
weatheritem.@city = cities[i];
weatheritem.@weather = session.get(cities[i]);
weatherlist.appendChild( weatheritem );
}
return weatherlist.toXMLString();
}
getWeather.safe = true;
getWeather.httpMethod = "GET";
getWeather.httpLocation = "weather/{city}";
getWeather.inputTypes = "string";
getWeather.outputType = "string";
function getWeather(city)
{
initialise();
var details = session.get(city);
if (details == null) {
throw ("Cannot find weather details of city " + city + ".")
}
return details;
}
postWeather.httpMethod = "POST";
postWeather.httpLocation = "weather/{city}";
postWeather.inputTypes = {"city" : "string",
"weatherDetails" : "string"};
postWeather.outputType = "string";
function postWeather(city, weatherDetails)
{
initialise();
var details = session.get(city);
if (details != null) {
throw ("Weather details of city " + city + " already exists.")
}
session.put(city ,weatherDetails);
cities = session.get("cities");
cities[cities.length] = city;
return city;
}
deleteWeather.httpMethod = "DELETE";
deleteWeather.httpLocation = "weather/{city}";
deleteWeather.inputTypes = "string";
deleteWeather.outputType = "string";
function deleteWeather(city)
{
initialise();
var details = session.get(city);
if (details == null) {
throw ("Cannot find weather details of city " + city + " to delete.")
}
session.remove(city);
cities = session.get("cities");
for ( var i = 0; i < cities.length; i++ )
{
if ( cities[i] == city )
{
cities.splice(i,1);
break;
}
}
return city;
}
putWeather.httpMethod = "PUT";
putWeather.httpLocation = "weather/{city}";
putWeather.inputTypes = {"city" : "string",
"weatherDetails" : "string"};
putWeather.outputType = "string";
function putWeather(city, weatherDetails)
{
initialise();
var details = session.get(city);
if (details == null) {
throw ("Cannot find weather details of city " + city + " to update.")
}
session.put(city ,weatherDetails);
return city;
}