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.