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