Difference: Examples (r16 vs. r15)

This document is valid for Wille's development version.


All examples In this section, we will introduce and explain the functionalities of some example services for Wille. In order to try out the services, you can either paste the source code directly from the examples. The services are available under Wille's Basic Bundle, in also delivered as part of Wille2 Core package. examples profile. You can also add individual example services to your Wille installation, by creating a new directory for each service under Wille's services folder.

TBD: more examples Request Sniffer Service from core?

@@@ Request Sniffer ( requestsniffer) is a service that displays all information that gets passed to Wille services written using Python adapter, allowing inspection/"sniffing" of this information. The sniffer is used for the purpose of demonstrating what data is passed and how they can be accessed from Wille Services. The service is particularly useful also for inspecting the actual content during service development and usage as well.

The sniffer does not require any additional libraries.

Implementation (servicerequestsniffer.py)

import cgi

import wille

class RequestSnifferService(wille.Service):
	def execute(self, params, servicepool, keyring, workdir):
		data = '

Request Data Sniffer

' # Data data += '

Input parameters:

' data += '

    ' for key in params: data += "
  • %s=%s
  • " % (key, params[key]) if len(params) == 0: data += '
  • No input parameters. Try adding some!
  • ' data += '

' data += '


' data += '

    ' if servicepool: for service in servicepool.services(): data += "
  • %s
  • " % service.name data += '

' data += '


' data += '

    ' if keyring: print keyring.keys() for key in keyring.keys(): data += ("
  • %s
  • " % cgi.escape(str(key))) else: data += "
  • (empty)
  • " data += '

' # Return tuple response: # First item: data # Second item: additional HTTP headers # Third item: HTTP response code (default=200) return (data, {'Content-type': 'text/html'})

Service Wrapper (willeservice.properties)

description=Service for inspecting ("sniffing") information that gets passed to Wille services

Weather Report Service

Weather Report (weather) is a service that generates a seven-day weather report for a given location by utilising public web APIs.

The service demonstrates the use of Wille for following purposes:

  • Calling a HTTP-based web API (Google Maps Geocoding Service)
  • Generation of a Web Services client from WSDL and calling a service from the client (National Weather Service Web Services API)

The service uses the following Python libraries:

Implementation (weather.py)

import wille

class WeatherService(wille.Service):
	def execute(self, params, servicepool, keyring, workdir):
		# Parse end urlencode input parameter(s)
		from urllib import quote
		e_address = quote(params['address'])

		# Define to get a seven day weather report, starting from today
		from datetime import datetime, timedelta
		starttime = datetime.today().strftime("%Y-%m-%d")
		endtime = (datetime.today()+timedelta(days=7)).strftime("%Y-%m-%d")
		# Geocode address
		import httplib2
		import simplejson as json
		geocoder_root_url = 'http://maps.google.com/maps/api/geocode/json?'
		geocoder_req_url = geocoder_root_url+'address='+e_address+'&sensor=false'
		h = httplib2.Http("")
		resp, content = h.request(geocoder_req_url)
		geocoder_result = json.loads(content)
		location = geocoder_result['results'][0]['geometry']['location']
		# Get a day weather report
		from suds.client import Client
		forecast_wsdl_url = 'http://www.weather.gov/forecasts/xml/DWMLgen/wsdl/ndfdXML.wsdl'
		client = Client(forecast_wsdl_url)
		weather_report = client.service.NDFDgen(latitude = location['lat'], \
											    longitude = location['lng'], \
											    product = 'time-series', \
											    startTime = starttime, \
											    endTime = endtime, \
											    weatherParameters = False )
		# Return weather report XML
		return (weather_report.encode('utf-8'), {'Content-type': 'application/xml; charset=utf-8'})

Service Wrapper (willeservice.properties)

description=Exemplary weather report generator service parameters=address profile=examples adapter=PythonService adapter.command=weather.WeatherService}}} adapter.command=weather.WeatherService 

Copyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TUTWiki? Send feedback