Java Mailing List Archive

http://www.gg3721.com/

Home » user.groovy »

[groovy-user] GroovyWS and Grails - how do I create one proxy and access it everywhere?

Bilal Sheikh

2008-08-14


Author LoginPost Reply
Hi,

I'm new to Groovy and Grails.

I've created a Grails Service class that consumes a third party's service, and I've written a controller to allow access to the Grails Service via browser (similar to the http://www.ibm.com/developerworks/java/library/j-grails05208/index.html example, only I'm using GroovyWS to access a WSDL/SOAP service).

I'm creating a new WSClient in my controller's closure every time the closure is run, and am finding it is quite slow (it's creating the classes, based on the WSDL, everytime the closure is run).

Is there a more proper/efficient way of doing this?  Can I somehow have the WSClient created once somewhere and access it from everywhere?

Here's an example of what I currently have (working but slow) with the details changed to protect the innocent:
[CODE]
import groovyx.net.ws.WSClient
class FooService {

    boolean transactional = false
    def wsdl = "https://somecompany.com/Services/FooService?WSDL"

    def fooColors() {
        def proxy = new WSClient(
                wsdl ,
                this.class.classLoader
        )
        def fooColorsRequest = proxy .create("com.somecompany.fooservice.FooColorsRequest")
        def fooColors = chromeProxy.getFooColors(fooColorsRequest)
        return fooColors.i
    }
}
[/CODE]

I tried the code below, but get
java.lang.ClassNotFoundException: com.somecompany.fooservice.FooColorsRequest
        at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
        at groovyx.net.ws.WSClient.create(WSClient.java:144)
[CODE]
import groovyx.net.ws.WSClient
class FooService {

    boolean transactional = false
    def wsdl = "https://somecompany.com/Services/FooService?WSDL"
    def proxy = new WSClient(
         wsdl ,
         this.class.classLoader
    )

    def fooColors() {
        def fooColorsRequest = proxy .create("com.somecompany.fooservice.FooColorsRequest")
        def fooColors = chromeProxy.getFooColors(fooColorsRequest)
        return fooColors.i
    }
}
[/CODE]

I'd really appreciate any help resolving this.

Thanks!
Bilal
©2008 gg3721.com - Jax Systems, LLC, U.S.A.