How to override the service address ? - 7.3

Talend ESB Service Developer Guide

Version
7.3
Language
English
Product
Talend Data Fabric
Talend Data Services Platform
Talend ESB
Talend MDM Platform
Talend Open Studio for ESB
Talend Real-Time Big Data Platform
Module
Talend ESB
Talend Runtime
Content
Design and Development
Installation and Upgrade
Last publication date
2023-04-17

If you are using JAXWS API to create the proxy obejct, here is an example which is complete JAX-WS compliant code

URL wsdlURL = MyService.class.getClassLoader.getResource ("myService.wsdl");
QName serviceName = new QName("urn:myService", "MyService");
MyService service = new MyService(wsdlURL, serviceName);
ServicePort client = service.getServicePort();
BindingProvider provider = (BindingProvider)client;
// You can set the address per request here
provider.getRequestContext().put(
   BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
   "http://my/new/url/to/the/service");

If you are using CXF ProxyFactoryBean to create the proxy object , you can do like this

JaxWsProxyFactoryBean proxyFactory = new JaxWsProxyFactoryBean();
proxyFactory.setServiceClass(ServicePort.class);
// you could set the service address with this method
proxyFactory.setAddress("theUrlyouwant");
ServicePort client = (ServicePort) proxyFactory.create();

Here is another way which takes advantage of JAXWS's Service.addPort() API

URL wsdlURL = MyService.class.getClassLoader.getResource(
   "service2.wsdl");
QName serviceName = new QName("urn:service2", "MyService");
QName portName = new QName("urn:service2", "ServicePort");
MyService service = new MyService(wsdlURL, serviceName);
// You can add whatever address as you want
service.addPort(portName, "http://schemas.xmlsoap.org/soap/", 
   "http://the/new/url/myService");
// Passing the SEI class that is generated by wsdl2java      
ServicePort proxy = service.getPort(portName, SEI.class);