[
https://issues.apache.org/jira/browse/OLINGO-705?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14591414#comment-14591414
]
Francesco Chicchiriccò commented on OLINGO-705:
-----------------------------------------------
{{ODataRequest#addCustomHeader}} is for adding entries to {{ODataHeaders}},
e.g. for OData-specific request / response headers.
For other general purpose headers (like {{Authorization}} as in your case), the
idea is to work at HTTP client level; some facilities are provided by default,
as for your (very common indeed) use case:
{code:java}
ODataClient client = ODataClientFactory.getClient();
client.getConfiguration().setHttpClientFactory(new
BasicAuthHttpClientFactory("username", "password"));
EdmMetadataRequest metadataRequest =
client.getRetrieveRequestFactory().getMetadataRequest(serviceRoot);
ODataRetrieveResponse<Edm> metadataRespose = metadataRequest.execute();
Edm edm = metadataRespose.getBody();
{code}
You can take a look at integration tests to see further possibilities
[[1|https://github.com/apache/olingo-odata4/blob/master/fit/src/test/java/org/apache/olingo/fit/v4/AuthBatchTestITCase.java]]
[[2|https://github.com/apache/olingo-odata4/blob/master/fit/src/test/java/org/apache/olingo/fit/v4/OAuth2TestITCase.java]]
with authentication / autorization
> EdmMetadataRequest ignores the Custom Headers set
> -------------------------------------------------
>
> Key: OLINGO-705
> URL: https://issues.apache.org/jira/browse/OLINGO-705
> Project: Olingo
> Issue Type: Bug
> Components: odata4-client
> Affects Versions: (Java) V4 4.0.0-beta-03
> Reporter: Ramesh Reddy
> Priority: Critical
>
> I am trying to add "Authorization" header for retrieving $metadata on the
> service that is secured though HTTPBasic. The following code fails with 401.
> {code}
> EdmMetadataRequest metadataRequest =
> client.getRetrieveRequestFactory().getMetadataRequest(serviceRoot);
> metadataRequest.addCustomHeader("Authorization", "Basic
> dXNlcjpyZWRoYXQxIQ==");
> ODataRetrieveResponse<Edm> metadataRespose = metadataRequest.execute();
> Edm edm = metadataRespose.getBody();
> {code}
> While debugging through the code, I found out that the header is never set on
> the request object. The same worked on the "ODataEntitySetIteratorRequest",
> but I suggest verify this on all the requests.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)