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, ERR开发者_如何学COR!
Thanks!
Note: Need I use BindingProvider.ENDPOINT_ADDRESS_PROPERTY
to solve this?
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());
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)
精彩评论