protected void initAuthenticatingHttpClient()

in src/main/java/com/amazonaws/neptune/client/rdf4j/NeptuneSparqlRepository.java [115:154]


    protected void initAuthenticatingHttpClient() throws NeptuneSigV4SignerException {

        if (!authenticationEnabled) {
            return; // auth not initialized, no signing performed
        }

        // init an V4 signer for Apache HTTP requests
        v4Signer = new NeptuneApacheHttpSigV4Signer(regionName, awsCredentialsProvider);

        /*
         *  Set an interceptor that signs the request before sending it to the server
         * => note that we add our interceptor last to make sure we operate on the final
         *    version of the request as generated by the interceptor chain
         */
        final HttpClient v4SigningClient = HttpClientBuilder.create().addInterceptorLast(new HttpRequestInterceptor() {

            @Override
            public void process(final HttpRequest req, final HttpContext ctx) throws HttpException, IOException {

                if (req instanceof HttpUriRequest) {

                    final HttpUriRequest httpUriReq = (HttpUriRequest) req;
                    try {
                        v4Signer.signRequest(httpUriReq);
                    } catch (NeptuneSigV4SignerException e) {
                        throw new HttpException("Problem signing the request: ", e);
                    }

                } else {

                    throw new HttpException("Not an HttpUriRequest"); // this should never happen

                }
            }

        }).build();

        setHttpClient(v4SigningClient);

    }