Use SOAP Webservices to drive the content for a site
From bemoko developer wiki
- Summary: Use SOAP Webservices to drive the content for a site
- Level: Advanced
Contents |
Get the Site
- Check out the source from SVN into your bemokoLive sites directory.
- cd ~/bemoko/sites
- svn co http://bemoko.googlecode.com/svn/sites/exercise_webservice_soap/trunk exercise_webservice_soap
- Or download (coming soon) and extract the site into your bemokoLive sites directory.
- Access the page on your bemokoLive install, e.g. http://localhost:8080/live/exercise_webservice_soap/i
You can also simply browse the source.
Configuration
To get this example working you need to have Grape working to dynamically load the libraries that this site needs. These libraries can be explicitly installed as follows:
- Install Groovy on the server on which bemokoLive is running.
- Configure the grape repository as described @ Configuring Ivy Repository.
- Resolve the dependencies on the local machine using the user which runs the bemokoLive server:
- grape -V resolve org.codehaus.groovy.modules groovyws 0.5.0
- If you are having trouble with resolving the dependency with grape you can run the command with the -V option to get verbose information.
- Note that the grape command should be in the bin directory of the groovy install
- You can configure the location of grape repository using the groovy.root JVM parameter if you do not wish to use the grape repository of the user that runs the bemokoLive server
- Be patient - groovyws has a lot of dependencies and it may take 10 minutes or so to download and install them all.
What you should see
When you enter in location into the form and submit you should get back the latitude and longitude coordinates:
How does it work?
The plugin LocationPlugin.groovy does all the hard work in interacting with the webservice. It creates a proxy using the WSDL at http://terraservice.net/TerraService.asmx?WSDL and exposes the method getCoordinates(city,state,country) which resolves the longitude and latitude of a particular location using the underlying webservice.
The template location.html calls the getCoordinates method and displays the resulting information:
<div id="body"> ${content.location.getCoordinates("mountain view","ca","us")} </div>
Note that the LocationPlugin plugin is loaded in the site scope so that the proxy is initialised once and reused:
<intent name="location" type="template" view="template.html"> <param name="page">location.html</param> <source name="location" plugin="LocationPlugin" scope="site"/> </intent>

