Home Navigation

Wednesday 28 November 2018

Apache CXF creating rest client authentication and customize header

There are two ways you can authenticate rest client.

Setting header authorization:

WebClient client = WebClient.create(url);
String authorizationHeader = "Basic " + org.apache.cxf.common.util.Base64Utility
                                    .encode((username + ":" +  password)).getBytes());

                    client.header("Authorization", authorizationHeader);



Pass user and password when you create your rest client.


WebClient client = WebClient.create(url, username, password, null);



If you want to pass client_id or any other parameter just use

client.header("CLIENT_ID",{your_id})

Settings media type:

client.type(MediaType.APPLICATION_JSON_TYPE)

client.accept(MediaType.APPLICATION_JSON_TYPE)

Then follow the url to get the response from server.

https://problemslicer.blogspot.com/2018/09/no-message-body-reader-has-been-found.html