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

1

5

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);
Mythomania answered 11/11, 2016 at 14:21 Comment(0)
M
8

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)
Mythomania answered 11/11, 2016 at 14:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.