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

1

14

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 that has good support for JAX-WS so I can write a central engine in Java, and then just let the scripting language create the snippets containing the web service methods (with either @WebService or @WebMethod annotations) which can then be passed to

http://docs.oracle.com/javase/6/docs/api/javax/xml/ws/Endpoint.html#publish(java.lang.String, java.lang.Object)

If at all possible, please provide an example of how to do it correctly.

Any suggestions?

Tanagra answered 20/8, 2012 at 8:37 Comment(0)
E
10

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).

Expedition answered 20/8, 2012 at 11:7 Comment(3)
Thank you for pointing out there are "lots available via a google search". If there truly are lots of search results readily available, some may be better than others, and then perhaps you - with your experience in the matter at hand - could help me and other visitors to this site by pointing them out directly. Also, when you inline the actual nuggets you do not rely on an external source which may go away, making your answer better.Halfwit
Yes, 1000 apologies! My choice of words was particularly poor. I edited the response and tried to address your points and have it make more sense. To be honest, I am not sure what the policy is with respect to inlining such references or not - will research this as well.Expedition
wish I could do the same in jruby 1.7Winstead

© 2022 - 2024 — McMap. All rights reserved.