grailsgroovyendpointws-client

Groovy: How to change endpoint using ws-client?


I'm using ws-client in a Grails Project to call an web service.

It's ok, but it's reading endpoint from WSDL.

How to change endpoint in runtime?

def proxy = new WSClient(wsdlURL, Thread.currentThread().getContextClassLoader());
proxy.setEndpoint(''); // this doesn't exists, ERROR!

Thanks!

Note: Need I use BindingProvider.ENDPOINT_ADDRESS_PROPERTY to solve this?


Solution

  • you can change the endpoint address by performing following code:

    // getter method for the wrapped client class
    WSClient.metaClass.getCxfClient = { ->
        delegate.client
    }
    // init ws client
    proxy = new WSClient(wsdlURL, this.class.classLoader)
    proxy.initialize()
    // get client instance
    def cxfClient = proxy.cxfClient
    // create new endpoint url
    URL newUrl = new URL("http://edu-02:8080/educenter/services/sync")
    // assign new created url to the client
    cxfClient.getConduit().getTarget().getAddress().setValue(newUrl.toExternalForm());