0

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?

Topera
  • 12,223
  • 15
  • 67
  • 104

2 Answers2

1

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());
hitty5
  • 1,653
  • 12
  • 25
0

Using hitty5 answer, an method-encapsulated answer.

// class with proxy attribute instanciated
def setEndpoint(String endpoint){
    String url = new URL(endpoint).toExternalForm()
    this.proxy.client.conduit.target.address.setValue(url)
}

Extra: to set timeout, use:

proxy.client.conduit.clientSidePolicy.setReceiveTimeout(999)
proxy.client.conduit.clientSidePolicy.setConnectionTimeout(999)
Topera
  • 12,223
  • 15
  • 67
  • 104