どうやら、Groovy は Web サービスを簡単に利用できるようです。JAX-WS の代わりに JAX-RPC を必要とする Web サービスを使用できますか? そのために古いバージョンの Groovy またはそのライブラリを使用する必要がありますか?
3 に答える
It's really easy to consume XML-RPC web services. You need the Groovy XML-RPC as well as the Smack library in your classpath.
I wrote some groovy scripts to work with our Atlassian Confluence wiki and here's a short example to retrieve a wiki page using XML-RPC:
import groovy.net.xmlrpc.*
def c = new XMLRPCServerProxy("http://host:port/rpc/xmlrpc")
def token = c.confluence1.login("username","password")
def page = c.confluence1.getPage(token, "SPACE", "pagename")
println page.content
c.confluence1.logout(token);
You use the XMLRPCServerProxy
to access the XML-RPC services. If your services require complex parameters as parameters or return one, these are represented as Groovy maps, with the attribute name as key and it's value as the corresponding value. In the script above, the service getPage
returns a Page object, which is a map, but as you can directly access a map's key using the dot-notation in Groovy, page.content
is the same as page.get("content")
.
「JAX-WSの代わりにJAX-RPCを必要とするWebサービスを利用できる」とはどういう意味ですか?Groovy側ではどのような違いがありますか?文書化されているように、そのWebサービスを呼び出そうとしましたか?
import groovyx.net.ws.WSClient
def proxy = new WSClient("http://localhost:6980/MathService?wsdl", this.class.classLoader)
proxy.initialize() // from 0.5.0
def result = proxy.add(1.0 as double, 2.0 as double)
assert (result == 3.0)
result = proxy.square(3.0 as double)
assert (result == 9.0)
特定のエラーが発生しますか?