cw24
cw24

Reputation: 1733

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);

Upvotes: 5

Views: 3995

Answers (1)

cw24
cw24

Reputation: 1733

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)

Upvotes: 8

Related Questions