Как написать odataclient olingo, где odata api V4 может быть аутентифицирован с использованием HMAC

У меня есть конечная точка odata с работами по аутентификации HMAC. В основном это обычный

Http URL url = new URL(uri);
        HttpURLConnection con = (HttpURLConnection) url.openConnection();
        con.setRequestMethod("GET");
        String currentUTCTime = getCurrentUTCTime();

        Map<String, String> headers = new LinkedHashMap<>();
        headers.put("x-csod-date", currentUTCTime);
        headers.put("x-csod-session-token", sessionToken);

        con.setRequestProperty("x-csod-date", currentUTCTime);
        con.setRequestProperty("x-csod-session-token", sessionToken);
        String stringToSign = constructStringToSign(con.getRequestMethod(), headers, url.getPath());
        String sig = signString512(stringToSign, sessionSecret);
        con.setRequestProperty("x-csod-signature", sig);
        System.out.println("signation is : "+sig);
        //*********
        con.setConnectTimeout(90000);
        con.setReadTimeout(99000);
        int status = con.getResponseCode();

Я пытался подражать то же самое через клиент Apache olingo

 ODataClient client = ODataClientFactory.getV4();
        String serviceRoot = "https://knet.csod.com/services/api/x/odata/api/views/vw_rpt_transcript";
        URI url=new URI(serviceRoot);
        ODataRawRequest req=
client.getRetrieveRequestFactory().getRawRequest(url);
        req.setXHTTPMethod("GET");

        String currentUTCTime = getCurrentUTCTime();
        req.addCustomHeader("x-csod-date",currentUTCTime);
        req.addCustomHeader("x-csod-session-token",sessionToken);
        Map<String, String> headers = new LinkedHashMap<>();
        headers.put("x-csod-date", currentUTCTime);
        headers.put("x-csod-session-token", sessionToken);

        String stringToSign = constructStringToSign(req.getMethod().name(), headers, serviceRoot);
        String sig = signString512(stringToSign, sessionSecret);
        req.addCustomHeader("x-csod-signature",sig);
        ODataResponse res=req.execute();

первый http-код работает, и я получаю ответы, но мой код odata выдает 401 несанкционированную ошибку

Исключение в потоке "main" org.apache.olingo.client.api.communication.ODataClientErrorException: (401) CSOD Несанкционированное исключение: проверьте свои учетные данные. [HTTP/1.1 401 неавторизовано] в org.apache.olingo.client.core.communication.header.ODataErrorResponseChecker.checkResponse(ODataErrorResponseChecker.java:73) в org.apache.olingo.client.core.communcheques (AbstractRequest.java:53) в org.apache.olingo.client.core.communication.request.AbstractODataRequest.doExecute(AbstractODataRequest.java:324) в org.apache.olingo.client.core.communication.request.retrieve.ODmpl.execute(ODataRawRequestImpl.java:66) в GetClient.main(GetClient.java:180)

0 ответов

Другие вопросы по тегам