Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make an HTTP authenticated service call with Olingo (Odata)

I have a webservice to access that is protected by basic HTTP authentification.

How do I set up the ODataClient to send the authentication to the web service?

ODataClient client = ODataClientFactory.getClient();
String iCrmServiceRoot = "https://example.dev/Authenticated/Service";

ODataServiceDocumentRequest odClientReq = 
    client.getRetrieveRequestFactory().getServiceDocumentRequest(iCrmServiceRoot);
like image 906
cw24 Avatar asked Mar 10 '23 16:03

cw24


1 Answers

To access the web service you just need to add the basic HTTP authentification to the configuration as follows:

ODataClient client = ODataClientFactory.getClient();

// add the configuration here
client.getConfiguration()
    .setHttpClientFactory(new BasicAuthHttpClientFactory("[username]", "[password]"));

String iCrmServiceRoot = "https://example.dev/Authenticated/Service";
ODataServiceDocumentRequest odClientReq = 
    client.getRetrieveRequestFactory().getServiceDocumentRequest(iCrmServiceRoot)
like image 114
cw24 Avatar answered Apr 06 '23 22:04

cw24