-
I am using SPARQLRepository to connect via HTTP to Stardog. Stardog is configured to authenticate incoming connections via OAuth2. So I need to set the required Authorization Header for every Request made to Stardog. I know of SPARQLRepository.setAdditionalHttpHeaders but this methods intention is to set custom http headers for all requests issued. What I need is to set a custom http header for every SPARQLProtocolSession that is used by a SPARQLTupleQuery. Currently this is only possible by creating a new HttpClient for every SPARQLConnection and setting it through SPARQLConnection.setHttpClient. Codewise this looks like:
Then the SPARQLTupleQuery spawned by SPARQLConnection.prepareTupleQuery will receive my custom HttpClient and pass it on to SPARQLTupleQuery.evaluate as SPARQLProtocolSession. The downside of this is that I need to create a new HttpClientBuilder and HttpClient for every SPARQLConnection, so for every request issued to Stardog. I would prefer it if I could set the custom http header directly on the SPARQLProtocolSession used by SPARQLTupleQuery . I have not yet found a public API to do this. Does anybody know of a way how to do this or has some other advice? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
You can use an interceptor to add your auth header in your HttpClient, I think this code can help you: HttpClientBuilder bld = HttpClientBuilder.create();
bld.addInterceptorFirst(
(HttpRequestInterceptor) (httpRequest, httpContext) ->
httpRequest.addHeader(HttpHeaders.AUTHORIZATION, "bearer JWTTOKEN")
);
CloseableHttpClient httpClient = bld.build(); You can then replace your auth header without having to recreate the HttpClient |
Beta Was this translation helpful? Give feedback.
You can use an interceptor to add your auth header in your HttpClient, I think this code can help you:
You can then replace your auth header without having to recreate the HttpClient