What JVM-based scripting language support @WebService to create services at runtime?

后端 未结 1 1347
情书的邮戳
情书的邮戳 2021-02-05 15:28

I am at a situation where I need to be able to create and expose a webservice at run time. (i.e. no \"javac\"-compilation step).

Is there a JVM-based scripting language

相关标签:
1条回答
  • 2021-02-05 16:08

    Many do, the one that is most Java-like and supports what you want would probably be groovy.

    Update to add an example:

    There are lots of them available via a google search. The best one I know about is here as this should walk you through an example that works. This link is to another question/answer site focused on groovy. They walk you through this simple example:

    If you try this site and find that it is not instructive, please provide that feedback here. Likewise, if you do search and find one that you find better/easier to understand, please add that here. I can't come at from that same perspective, thus you would have more to contribute in this vein that I.

    Geom.groovy
    -------------------
    package webservices
    
    import javax.jws.WebService
    import javax.jws.soap.SOAPBinding.Style
    import javax.jws.soap.SOAPBinding
    
    @WebService
    @SOAPBinding(style=Style.RPC)
    interface Geom {
        double getArea(double val)
    }
    
    Circle.groovy
    -------------------
    package webservices
    
    import javax.jws.WebService
    
    @WebService(endpointInterface='webservices.Geom')
    class Circle implements Geom {
            double getArea(double r) { Math.PI*r*r }
    }
    
    publish.groovy
    --------------------
    package webservices
    
    import javax.xml.ws.Endpoint
    
    Endpoint.publish('http://localhost:5555/circle',new Circle())
    println 'ready to receive requests...'
    

    The link I provided may eventually break or be removed. However (IMO), this would most likely occur if (when?) the technology moves forward to something newer/better. While I have duplicated the code from there above, the reference has other very useful information and pointers (such as the use of SoapUI).

    0 讨论(0)
提交回复
热议问题