Discovery Tutorial

From Wsmx-WIKI
Jump to: navigation, search

In this tutorial we will walk through an illustrative use of the discovery engine with an example from the traveling domain. If you haven't got a local WSMX instance, get started now.

Open the web console and navigate to the component view of DiscoveryFramework. Optionally you may ssh into your WSMX instance and type 'll' (LogListen) to remotely view the log4j logs. While this not necessary to complete this tutorial, it is recommended for didactic purposes as it shows the workings of the machinery that is inside WSMX.

In the webconsole find the operations for adding Web services to the engine, with the signatures:

addWebServiceByUrl(String)
addWebServiceByContent(String)

One possibility to add a Web service is to invoke the first operation for the URL of the Web service. Alternatively, you can invoke the second operation directly for the WSML code. If the service is added successfully, you should see a confirmation message.

In our simple example, provider A offers tickets for flights from Austria and Germany to anywhere within Europe, while provider B offers train tickets in USA.

wsmlVariant _"http://www.wsmo.org/wsml/wsml-syntax/wsml-flight"

namespace {_"http://www.gsmo.org/dip/travel/webServiceA#",
 	dO _"http://www.gsmo.org/dip/travel/domainOntology#",
	dc _"http://purl.org/dc/elements/1.1#"}
/*
 * Web Service A
 */
webService _"http://www.gsmo.org/dip/travel/webServiceA.wsml"
	nfp
		dc#title hasValue "First Web Service"
		dc#contributor hasValue "Adina Sirbu"
                dc#description hasValue "Web service for booking plane tickets from Austria and Germany to any european city"
	endnfp
	importsOntology _"http://www.gsmo.org/dip/travel/domainOntology.wsml"
	capability webServiceACapability
		postcondition		
			definedBy 
				?ticket[
					dO#from hasValue ?from,
					dO#to hasValue ?to,
					dO#vehicle hasValue ?vehicle
				] memberOf dO#Ticket and 
				(?from memberOf dO#AustrianCity or ?from memberOf dO#GermanCity) and 
				?to memberOf dO#EUCity and
				?vehicle memberOf dO#Airplane.				 
wsmlVariant _"http://www.wsmo.org/wsml/wsml-syntax/wsml-flight"

namespace {_"http://www.gsmo.org/dip/travel/webServiceB#",
 	dO _"http://www.gsmo.org/dip/travel/domainOntology#",
	dc _"http://purl.org/dc/elements/1.1#"}
/*
 * Web Service B
 */
webService _"http://www.gsmo.org/dip/travel/webServiceB.wsml"
	nfp
		dc#title hasValue "Second Web Service"
		dc#contributor hasValue "Adina Sirbu"
                dc#description hasValue "Web service for booking train tickets within US"
	endnfp
	importsOntology _"http://www.gsmo.org/dip/travel/domainOntology.wsml"
	capability webServiceBCapability
		postcondition		
			definedBy 
				?ticket[
					dO#from hasValue ?from,
					dO#to hasValue ?to,
					dO#vehicle hasValue ?vehicle
					] memberOf dO#Ticket and 
				?from memberOf dO#USCity and 
				?to memberOf dO#USCity and 
				?vehicle memberOf dO#Train.				 

The next step is to send discovery requests for different goals. The operations are:

discoverByGoalUrl(String)
discoverByGoalContent(String)

As for the Web service addition/removal operations, you have two possibilities for specifying the goal, either by giving the URL of the goal or directly the WSML file. Consider a Web service requestor who searches for a flight from Austria to UK. The WSML specification of this goal is:

wsmlVariant _"http://www.wsmo.org/wsml/wsml-syntax/wsml-flight"

namespace {_"http://www.gsmo.org/dip/travel/goal#",
 	dO _"http://www.gsmo.org/dip/travel/domainOntology#",
	dc _"http://purl.org/dc/elements/1.1#"}
/*
 * Test Goal
 */
goal _"http://www.gsmo.org/dip/travel/goal.wsml"
	nfp
		dc#title hasValue "Goal"
		dc#contributor hasValue "Adina Sirbu"
                dc#description hasValue "Express the goal of buying a plane ticket from Austria to UK"
	endnfp
	importsOntology _"http://www.gsmo.org/dip/travel/domainOntology.wsml"
	capability goalCapability
		postcondition		
			definedBy 
				?ticket[
					dO#from hasValue ?from,
					dO#to hasValue ?to,
					dO#vehicle hasValue ?vehicle
				] memberOf dO#Ticket and
				?from memberOf dO#AustrianCity and
				?to memberOf dO#UKCity and
				?vehicle memberOf dO#Airplane.

The output message should inform you that the matching service is

http://www.gsmo.org/dip/webServiceA.wsml