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);
cw24
  • 1,613
  • 2
  • 22
  • 31

1 Answers1

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)
cw24
  • 1,613
  • 2
  • 22
  • 31