views:

181

answers:

1

I'm experimenting with Apache CXF and have a question about the client part.

Below is my current Spring configuration of the WS client of some com.example.customerservice.service.CustomerService:

<jaxws:client
    name="com.example.customerservice.service.CustomerServiceClient"
    serviceName="customer:CustomerServiceService" endpointName="customer:CustomerServiceEndpoint"
    address="http://localhost:8080/CustomerServicePort"
    serviceClass="com.example.customerservice.service.CustomerService">
    <jaxws:features>
        <bean class="org.apache.cxf.feature.LoggingFeature" />
    </jaxws:features>
</jaxws:client>

As you see, the address attribute is configured statically. This is not suitable for me because I don't know the server URL in advance. Moreover, in certain scenarios I'd like to use this client for different services which have different addresses.

Therefore static configuration of the server address in Spring is not appropriate. So my question is - how can I make it dynamic?

  • At the moment my solution is to set a system property - something like baseUrl and inject it into the Spring config using the property placeholder configurer.
  • Another possibility would be to simply construct the client manually which I don't really like either.

But I believe I'm really missing something. Maybe there is a possibility of something like clientFactory.createClientFor("http://myserver:8080")?

+1  A: 

See post to CXF Users Mailing List.

DavidValeri
Hi David,yes, thank you, I've seen it. I'm trying it out today and report back.
lexicore
I have finally opted to programmatic creation via jaxWsProxyFactoryBean:final JaxWsProxyFactoryBean jaxWsProxyFactoryBean = new JaxWsProxyFactoryBean();jaxWsProxyFactoryBean.setServiceClass(CustomerService.class);jaxWsProxyFactoryBean.setAddress(webAppEnvironment.getBaseUrl() + "/CustomerServicePort");This is it, three lines of code. Enough for my purposes at the moment.
lexicore