Hi Ela
I can suggest the following, create a simple CXF out interceptor:
public class OAuth2OutInterceptor extends
AbstractPhaseInterceptor<Message> {
private String token;
public OAuth2OutInterceptor(String token) {
super(Phase.WRITE);
this.token = token;
}
public void handleMessage(Message message) throws Fault {
Map<String, List<String>> headers = CastUtils.cast((Map<?,
?>)message.get(Message.PROTOCOL_HEADERS));
headers.put("Authorization",
Collections.singletonList("Bearer " + token));
}
}
and then register it with the CXF WS client...
There could be more options...
Sergey
On 20/10/14 11:40, Elżbieta Jakubska wrote:
Hi all,
- I have bearer auth token ready to use (I implemented the code getting
this token)
- I used apache CXF wsdl2java to prepare a client from wsdl file
- In the main code I have created service object and port object and I know
how to make a request I need(
MyService service = new MyService();
MyServiceInterface i = service.getMyServiceInterfacePort();
- *BUT I have no idea how to pass this oauth2 bearer token to the http
header of the request.* Can you give me a tip how to set up the token in
http header? Should I modify the client somehow or is it possible to pass
the token to the client in the simple way? Currently I am using apache-cxf
2.7.12, but if it is needed I can switch to the newer one.
Thank you very much for your help!
Cheers,
Ela