Skip to content

Instantly share code, notes, and snippets.

@ilgrosso
Last active December 13, 2018 11:35
// instructs ODataJClient to send a BasicAuth HTTP header
// for username 'sampleUsername' and password ' samplePassword'
Configuration.setHttpClientFactory(new AbstractBasicAuthHttpClientFactory() {
@Override
protected String getUsername() {
return "sampleUsername";
}
@Override
protected String getPassword() {
return "samplePassword";
}
});
// perform any operation via ODataJClient: all requests will bear the BasicAuth HTTP header
// this restores the default unauthenticated behavior
Configuration.setHttpClientFactory(new DefaultHttpClientFactory());
@HestonHoltmann
Copy link

I tried using the above code pattern to test the use of BasicAuth with my OData 3.0 service end-point.. and i get the following

Dec 07, 2017 12:26:19 PM org.apache.http.impl.client.HttpAuthenticator authenticate
WARNING: Malformed challenge: Authentication challenge is empty
Exception in thread "main" com.msopentech.odatajclient.engine.communication.ODataClientErrorException: (401) Unauthorized. Login Required. [HTTP/1.1 401 Unauthorized. Login Required.]
at com.msopentech.odatajclient.engine.communication.request.ODataRequestImpl.doExecute(ODataRequestImpl.java:412)
at com.msopentech.odatajclient.engine.communication.request.retrieve.ODataServiceDocumentRequest.execute(ODataServiceDocumentRequest.java:52)
at ca.holtmann.cmms.App.main(App.java:62)

@TurkiBt
Copy link

TurkiBt commented Dec 13, 2018

I tried using the above code pattern to test the use of BasicAuth with my OData 3.0 service end-point.. and i get the following

Dec 07, 2017 12:26:19 PM org.apache.http.impl.client.HttpAuthenticator authenticate
WARNING: Malformed challenge: Authentication challenge is empty
Exception in thread "main" com.msopentech.odatajclient.engine.communication.ODataClientErrorException: (401) Unauthorized. Login Required. [HTTP/1.1 401 Unauthorized. Login Required.]
at com.msopentech.odatajclient.engine.communication.request.ODataRequestImpl.doExecute(ODataRequestImpl.java:412)
at com.msopentech.odatajclient.engine.communication.request.retrieve.ODataServiceDocumentRequest.execute(ODataServiceDocumentRequest.java:52)
at ca.holtmann.cmms.App.main(App.java:62)

Hi Heston,

Did you find a solution for this error?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment