我正在使用Apache Olingo Java Client API来调用OData服务端点,这需要进行身份验证。
我曾尝试在我的环境中使用代码:
URI absoluteUri = client.newURIBuilder(serviceUrl).build();
client.getConfiguration().setHttpClientFactory(new BasicAuthHttpClientFactory("username", "passxxx"));
ODataEntitySetIteratorRequest<ClientEntitySet, ClientEntity> request = client.getRetrieveRequestFactory().getEntitySetIteratorRequest(absoluteUri);
request.setAccept("application/json;odata.metadata=none");
ODataRetrieveResponse<ClientEntitySetIterator<ClientEntitySet, ClientEntity>> response = request.execute();
当我执行我的请求时,它会出现以下错误:
java.lang.NullPointerException
at org.apache.olingo.client.core.serialization.JsonODataErrorDeserializer.doDeserialize(JsonODataErrorDeserializer.java:46)
at org.apache.olingo.client.core.serialization.JsonDeserializer.toError(JsonDeserializer.java:442)
at org.apache.olingo.client.core.serialization.ClientODataDeserializerImpl.toError(ClientODataDeserializerImpl.java:91)
at org.apache.olingo.client.core.serialization.ODataReaderImpl.readError(ODataReaderImpl.java:86)
at org.apache.olingo.client.core.communication.header.ODataErrorResponseChecker.checkResponse(ODataErrorResponseChecker.java:59)
at org.apache.olingo.client.core.communication.request.AbstractRequest.checkResponse(AbstractRequest.java:54)
at org.apache.olingo.client.core.communication.request.AbstractODataRequest.doExecute(AbstractODataRequest.java:310)
at org.apache.olingo.client.core.communication.request.retrieve.ODataEntitySetIteratorRequestImpl.execute(ODataEntitySetIteratorRequestImpl.java:59)
at org.apache.olingo.client.core.communication.request.retrieve.ODataEntitySetIteratorRequestImpl.execute(ODataEntitySetIteratorRequestImpl.java:36)
at org.apache.olingo.samples.client.OlingoSampleApp.perform(OlingoSampleApp.java:131)
at org.apache.olingo.samples.client.OlingoSampleApp.main(OlingoSampleApp.java:112)
Exception in thread "main" org.apache.olingo.client.api.communication.ODataClientErrorException: (401) Unauthorized [HTTP/1.1 401 Unauthorized]
at org.apache.olingo.client.core.communication.header.ODataErrorResponseChecker.checkResponse(ODataErrorResponseChecker.java:76)
at org.apache.olingo.client.core.communication.request.AbstractRequest.checkResponse(AbstractRequest.java:54)
at org.apache.olingo.client.core.communication.request.AbstractODataRequest.doExecute(AbstractODataRequest.java:310)
at org.apache.olingo.client.core.communication.request.retrieve.ODataEntitySetIteratorRequestImpl.execute(ODataEntitySetIteratorRequestImpl.java:59)
at org.apache.olingo.client.core.communication.request.retrieve.ODataEntitySetIteratorRequestImpl.execute(ODataEntitySetIteratorRequestImpl.java:36)
at org.apache.olingo.samples.client.OlingoSampleApp.perform(OlingoSampleApp.java:131)
at org.apache.olingo.samples.client.OlingoSampleApp.main(OlingoSampleApp.java:112)