Hi,
I would consider to use this code to set HTTP headers directly in your client:
Map<String, List<String>> headers = new HashMap<String, List<String>>();
headers.put("HEADER_NAME", Arrays.asList("HEADER_VALUE"));
((BindingProvider)proxy).getRequestContext().put("thread.local.request.context",
"true");
((BindingProvider)proxy).getRequestContext().put(Message.PROTOCOL_HEADERS,
headers);
Regards,
Andrei.
> -----Original Message-----
> From: membersound2 [mailto:[email protected]]
> Sent: Dienstag, 2. Dezember 2014 16:56
> To: [email protected]
> Subject: How to pass dynamic values to OutInterceptor for HTTP headers?
>
> I want to put dynamic HTTP header values in a cxf client. The value should be
> based on the current logged in user running the client request, thus the
> process
> must be threadsafe.
>
> For a single user, it would work adding the HTTP header statically inside an
> OutInterceptor as follows:
> /
> @Configuration
> public class AppConfig {
> @Autowired
> SpringBus bus;
>
> @PostConstruct
> public void init() {
> bus.getOutInterceptors().add(new
> AbstractOutDatabindingInterceptor(Phase.MARSHAL) {
> @Override
> public void handleMessage(Message message) throws Fault {
> Map<String, List<String>> headers = (Map<String,
> List<String>>) message.get(Message.PROTOCOL_HEADERS);
> headers.put("Auth", Arrays.asList("dynamic pass per user");
> //TODO
> how to get the current user dynamically?
> }
> });
> }
>
> @Bean
> public WebservicePort getPort() {
> WebservicePort port = new Webservice(bus);
> return port;
> }
> }
>
>
>
> @Service
> public class WebserviceClient {
> @Autowired
> private WebservicePort port;
>
> @Autowired
> private AuthService authService;
>
> public void run() {
> //construct the xmlRequest
>
> User user = authService.getCurrentUser();
> port.send(xmlRequest); //invoke the auto-generated webservice stub
> }
> }/
>
> But how could I get the current user into the OutInterceptor at time of
> sending
> the xml dynamically, and just for this send request not having an impact on
> other users or the proxy instance itself?
>
>
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/How-to-pass-
> dynamic-values-to-OutInterceptor-for-HTTP-headers-tp5751779.html
> Sent from the cxf-user mailing list archive at Nabble.com.