cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrei Shakirin <ashaki...@talend.com>
Subject RE: How can I make requests with dynamic headers?
Date Fri, 07 Nov 2014 16:26:02 GMT
Hi,

You can use binding provider context to add SOAP custom headers: 
http://cxf.apache.org/faq.html#FAQ-HowcanIaddsoapheaderstotherequest/response?

Regards,
Andrei.

> -----Original Message-----
> From: smirnov.kirill [mailto:smirnov.kirill.vladimirovich@gmail.com]
> Sent: Mittwoch, 5. November 2014 18:23
> To: users@cxf.apache.org
> Subject: How can I make requests with dynamic headers?
> 
> I have already asked this question on StackOverflow, but nobody has answered
> yet.
> http://stackoverflow.com/questions/26762175/how-can-i-make-soap-java-
> client-requests-with-dynamic-headers
> 
> I want to make a Java-based SOAP client, which connects to the server which
> uses CXF. I have services' interfaces (jar from the Server) and classes which
> wrap requests/responses to the server. So I tried to use CXF on the client side
> too.
> 
> So what I do now is
> 
> 1) get instance for the service's interface
> 
> JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
> List<Interceptor&lt;? extends Message>> outInterceptors = new
> ArrayList<Interceptor&lt;? extends Message>>(); List<Interceptor&lt;?
extends
> Message>> inInterceptors = new ArrayList<Interceptor&lt;? extends
> Message>>(); outInterceptors.add(new OutInterceptor(login, password));
> inInterceptors.add(new InInterceptor());
> factory.setOutInterceptors(outInterceptors);
> factory.setInInterceptors(inInterceptors);
> factory.setServiceClass(OxygenService.class);
> factory.setAddress(currentEndpoint + "/oxygen"); oxygenService =
> (OxygenService)factory.create();
> 
> 2) So now I have an instance of the service - oxygenService. And so I can
> perform requests. Like this:
> 
> oxygenService.updateProfile(userId, lastName, firstName, phone);
> Unfortunately, there is a huge problem - how can I specify extra dynamic
> headers for each request? The server expects from me special header called
> 'dynamicId'. I can calculate it's value while calling oxygenService, but it seems
> there is no way to specify headers there - all I can is to call something from
> oxygenService. The only way to specify header is to use interceptors, but I can
> not get 'dynamicId' in the interceptor (because how can I know which
> 'dynamicId' is related to which request).
> 
> So to sum up, there is a list of what I want:
> 
> 1) I want to keep using services' interfaces
> 2) I want to keep using request and response wrappers (not to generate xml
> manually)
> 3) I want to dynamically specify headers for exact request
> 4) Solution has to be thread-safe
> 
> I also figured out that there is ClientProxy which can change headers for
> oxygenService, but it's not safe in terms of concurrency.
> 
> 
> 
> --
> View this message in context: http://cxf.547215.n5.nabble.com/How-can-I-
> make-requests-with-dynamic-headers-tp5750756.html
> Sent from the cxf-user mailing list archive at Nabble.com.

Mime
View raw message