Hi David,

thank you for the answer.

> 1) If you want to leave your Spring context as is and change the address
> programmatically at runtime:
>
> You can set a standard property in the request context.  Here is an example
> of how to do this programmatically.
>
> BindingProvider bp = (BindingProvider)port;
> Map<String, Object> context = bp.getRequestContext();
> Object oldAddress = context.get(BindingProvider.ENDPOINT_ADDRESS_PROPERTY);
> context.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
>            newAddress);
>
> When doing this, you should be aware of multi-threaded access to a client
> proxy.  See the CXF FAQ (Are JAX-WS client proxies thread safe?)[1]
>
> 2) If you are willing/able to provide WSDL URLs and use the JAX-WS APIs, you
> can write portable code that will create a client proxy wired to an endpoint
> of your choosing. You can use the "createdFromAPI" (Configuring a Spring
> Client (Option 1)) [2] attribute in your Spring context file to still allow
> Spring based configuration of the programmatically constructed client proxy.
> I think that wildcards are also supported here so you should be able to
> configure a number of clients using a single <jaxws:client> entry in your
> Spring context.  This approach will get more complex if the endpoint
> namespaces/local names vary greatly between the endpoints you are trying to
> interact with.
>
> 3) Use org.apache.cxf.jaxws.JaxWsProxyFactoryBean programmatically as shown
> in the Spring configuration of Configuring a Spring Client (Option 2) [2].
> This lets you set the interface and address and create new client proxy
> instances at will.  You may even want to configure a single instance of this
> factory with most properties already set in Spring and then inject it into
> your code where you can change the address and construct a new client proxy
> at will (providing for synchronized access to the factory bean of course).
> You can also cache the client proxies to avoid the expense of re-creating
> them repeatedly.
>
> [1] http://cxf.apache.org/faq.html#FAQ-AreJAXWSclientproxiesthreadsafe%253F
> [2] http://cxf.apache.org/docs/jax-ws-configuration.html

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.

Bye.
/lexi

Reply via email to