You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Elżbieta Jakubska <e....@gmail.com> on 2014/10/20 12:40:04 UTC
CXF - passing oauth2 bearer token in http header in SOAP ws client request
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
Re: CXF - passing oauth2 bearer token in http header in SOAP ws
client request
Posted by Elżbieta Jakubska <el...@gmail.com>.
It works for me, thank you! You saved my day:)
Cheers,
Ela
On 20 October 2014 16:24, Sergey Beryozkin <sb...@gmail.com> wrote:
> 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
>>
>>
>
Re: CXF - passing oauth2 bearer token in http header in SOAP ws client
request
Posted by Sergey Beryozkin <sb...@gmail.com>.
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
>