Skip to end of metadata
Go to start of metadata

The Server

You can develop your web service using a groovy script and/or a groovy class. Imagine, we want to publish a web service performing simple arithmetics. First, we have to write the business class implementing the basic operations. In our example, we chose to just implement simple add and square operations. Note that this class is quite generic and could be use locally.

Then we have to publish this service. In order to do so, we use WSServer and create one so called node linking our class with a URL.


That's all !

  • No labels

3 Comments

  1. Hi, its a nice example, but if i need use spring:
    like this

    MathService.groovy (interface)
    MathServiceImpl.groovy (implementation)
    WSServer.groovy (Publish WS)

    how i can do this. Can you put a example please
    thanks

  2. I've been trying to get this simple example to work for a while and had no luck...  I am a novice to web services and groovy, so I am likely just missing something here.  

    Here's my MathService class:

    package com.groovy.service;
    public class MathService { double add(double arg0, double arg1)

    Unknown macro: { return (arg0 + arg1); }

    double square(double arg0)

    Unknown macro: { return (arg0 * arg0); }

    }
    package com.groovy.service;

    public class MathService {

    double add(double arg0, double arg1)

    Unknown macro: { return (arg0 + arg1); }

    double square(double arg0)

    Unknown macro: { return (arg0 * arg0); }

    }

    Here's the simple driver: 

    package com.groovy.service;

    import groovyx.net.ws.WSServer

    class MathServiceLauncher {

    static main(args)

    Unknown macro: { MathService ms = new MathService() println "value}

    }

    When I launch the driver, I get the following message: java.lang.ClassNotFoundException: MathService

    I don't seem to know what I am doing wrong or more likely, what piece of the puzzle I am missing as I am trying to start the server from within Eclipse.

    Any help would be greatly appreciated.

  3. Looks like you are not using groovy.  You can run the sample pretty much as-is.  I just moved the import up to the top and put the whole script in as below.  The interesting bit was getting Jetty to stop, as the script terminates but jetty keeps on going.

    You can test the service simply by putting this in your browser: "http://localhost:6980/MathService?WSDL"