views:

316

answers:

2

I need to implement a web app, but instead of using relational database I need to use different SOAP Web Services as a back-end. An important part of application only calls web services and displays the result. Since Web Services are clearly defined in form of Operation: In parameters and Return Type it seems to me that basic GUI could be easily constructed just like in the case of scaffolding based on Domain Entities.

For example in case of SearchProducts web service operation I need to enter search parameters as input, so the search page can be constructed. Operation will return a list of products, so I need a page that will display this list in some kind of table.

Is there already some library in grails that let you achieve this. If not, how would you go about creating one?

A: 

You should be able to use XFire or CXF Plugins. For automatic scaffolding, modify your Controller.groovy template in scaffolding templates so it auto-generates methods you need.

Jean Barmash
A: 

Probably the easiest approach is to use wsimport on the WSDL files to generate the client-side stubs. Then you can call methods in the stubs from Groovy just as you would have called them from Java.

For example, consider the WSDL file for Microsoft's TerraServer, located at http://terraservice.net/TerraService.asmx?wsdl . Then you run something like

wsimport -d src -keep http://terraservice.net/TerraService.asmx?WSDL

which puts all the compiled stubs in the src directory. Then you can write Groovy code like

import com.terraserver_usa.terraserver.*;

TerraServiceSoap sei = new TerraService().getTerraServiceSoap()
Place home = new Place(city:'Boston',state:'MA',country:'US')
def pt = sei.convertPlaceToLonLatPt(home)
println "$pt.lat, $pt.lon"
assert Math.abs(pt.lat - 42.360000) < 0.001
assert Math.abs(pt.lon - -71.05000) < 0.001

If you want to access a lot of web services, generate the stubs for all of them. Or you can use dynamic proxies instead.

The bottom line, though, is to let Java do what it already does well, and use Groovy where it makes your life easier.

kousen