diff --git a/core/http/client/src/main/java/org/eclipse/rdf4j/http/client/RDF4JProtocolSession.java b/core/http/client/src/main/java/org/eclipse/rdf4j/http/client/RDF4JProtocolSession.java index 42ce6801b02..cc9aa8b5aa0 100644 --- a/core/http/client/src/main/java/org/eclipse/rdf4j/http/client/RDF4JProtocolSession.java +++ b/core/http/client/src/main/java/org/eclipse/rdf4j/http/client/RDF4JProtocolSession.java @@ -121,11 +121,11 @@ public RDF4JProtocolSession(HttpClient client, ScheduledExecutorService executor super(client, executor); this.executor = executor; - // we want to preserve bnode ids to allow Sesame API methods to match + // we want to preserve bnode ids to allow RDF4J API methods to match // blank nodes. getParserConfig().set(BasicParserSettings.PRESERVE_BNODE_IDS, true); - // Sesame client has preference for binary response formats, as these are + // RDF4J Protocol has a preference for binary response formats, as these are // most performant setPreferredTupleQueryResultFormat(TupleQueryResultFormat.BINARY); setPreferredRDFFormat(RDFFormat.BINARY); diff --git a/core/http/client/src/main/java/org/eclipse/rdf4j/http/client/SPARQLProtocolSession.java b/core/http/client/src/main/java/org/eclipse/rdf4j/http/client/SPARQLProtocolSession.java index ca439d5889c..82816848cc7 100644 --- a/core/http/client/src/main/java/org/eclipse/rdf4j/http/client/SPARQLProtocolSession.java +++ b/core/http/client/src/main/java/org/eclipse/rdf4j/http/client/SPARQLProtocolSession.java @@ -55,6 +55,7 @@ import org.apache.http.params.BasicHttpParams; import org.apache.http.params.CoreConnectionPNames; import org.apache.http.params.HttpParams; +import org.apache.http.protocol.HttpContext; import org.apache.http.util.EntityUtils; import org.eclipse.rdf4j.RDF4JConfigException; import org.eclipse.rdf4j.RDF4JException; @@ -127,10 +128,6 @@ */ public class SPARQLProtocolSession implements HttpClientDependent, AutoCloseable { - /*-----------* - * Constants * - *-----------*/ - protected static final Charset UTF8 = StandardCharsets.UTF_8; /** @@ -159,10 +156,6 @@ public class SPARQLProtocolSession implements HttpClientDependent, AutoCloseable final static Logger logger = LoggerFactory.getLogger(SPARQLProtocolSession.class); - /*-----------* - * Variables * - *-----------*/ - private ValueFactory valueFactory; private String queryURL; @@ -187,10 +180,6 @@ public class SPARQLProtocolSession implements HttpClientDependent, AutoCloseable private Map additionalHttpHeaders = Collections.emptyMap(); - /*--------------* - * Constructors * - *--------------*/ - public SPARQLProtocolSession(HttpClient client, ExecutorService executor) { this.httpClient = client; this.httpContext = new HttpClientContext(); @@ -215,10 +204,6 @@ public SPARQLProtocolSession(HttpClient client, ExecutorService executor) { this.maximumUrlLength = maximumUrlLength; } - /*-----------------* - * Get/set methods * - *-----------------*/ - @Override public final HttpClient getHttpClient() { return httpClient; @@ -252,8 +237,7 @@ protected void setUpdateURL(String updateURL) { } /** - * Sets the preferred format for encoding tuple query results. The {@link TupleQueryResultFormat#BINARY binary} - * format is preferred by default. + * Sets the preferred format for encoding tuple query results. * * @param format The preferred {@link TupleQueryResultFormat}, or null to indicate no specific format is * preferred. @@ -263,7 +247,8 @@ public void setPreferredTupleQueryResultFormat(TupleQueryResultFormat format) { } /** - * Gets the preferred {@link TupleQueryResultFormat} for encoding tuple query results. + * Gets the preferred {@link TupleQueryResultFormat} for encoding tuple query results. The + * {@link TupleQueryResultFormat#SPARQL SPARQL/XML} format is preferred by default. * * @return The preferred format, of null if no specific format is preferred. */ @@ -272,8 +257,7 @@ public TupleQueryResultFormat getPreferredTupleQueryResultFormat() { } /** - * Sets the preferred format for encoding RDF documents. The {@link RDFFormat#TURTLE Turtle} format is preferred by - * default. + * Sets the preferred format for encoding RDF documents. * * @param format The preferred {@link RDFFormat}, or null to indicate no specific format is preferred. */ @@ -282,7 +266,8 @@ public void setPreferredRDFFormat(RDFFormat format) { } /** - * Gets the preferred {@link RDFFormat} for encoding RDF documents. + * Gets the preferred {@link RDFFormat} for encoding RDF documents. The {@link RDFFormat#TURTLE Turtle} format is + * preferred by default. * * @return The preferred format, of null if no specific format is preferred. */ @@ -291,8 +276,7 @@ public RDFFormat getPreferredRDFFormat() { } /** - * Sets the preferred format for encoding boolean query results. The {@link BooleanQueryResultFormat#TEXT binary} - * format is preferred by default. + * Sets the preferred format for encoding boolean query results. * * @param format The preferred {@link BooleanQueryResultFormat}, or null to indicate no specific format is * preferred. @@ -302,7 +286,8 @@ public void setPreferredBooleanQueryResultFormat(BooleanQueryResultFormat format } /** - * Gets the preferred {@link BooleanQueryResultFormat} for encoding boolean query results. + * Gets the preferred {@link BooleanQueryResultFormat} for encoding boolean query results. The + * {@link BooleanQueryResultFormat#TEXT binary} format is preferred by default. * * @return The preferred format, of null if no specific format is preferred. */ @@ -1202,4 +1187,13 @@ public void setConnectionTimeout(long timeout) { } params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, (int) timeout); } + + /** + * Get the {@link HttpContext} used for sending HTTP requests. + * + * @return the {@link HttpContext} instance used for all protocol session requests. + */ + protected HttpContext getHttpContext() { + return this.httpContext; + } } diff --git a/core/http/client/src/main/java/org/eclipse/rdf4j/http/client/SharedHttpClientSessionManager.java b/core/http/client/src/main/java/org/eclipse/rdf4j/http/client/SharedHttpClientSessionManager.java index cedf5fbd32f..518bcbdd094 100644 --- a/core/http/client/src/main/java/org/eclipse/rdf4j/http/client/SharedHttpClientSessionManager.java +++ b/core/http/client/src/main/java/org/eclipse/rdf4j/http/client/SharedHttpClientSessionManager.java @@ -66,7 +66,7 @@ public SharedHttpClientSessionManager() { final int corePoolSize = Integer.getInteger(CORE_POOL_SIZE_PROPERTY, 1); this.executor = Executors.newScheduledThreadPool(corePoolSize, (Runnable runnable) -> { Thread thread = backingThreadFactory.newThread(runnable); - thread.setName(String.format("rdf4j-sesameclientimpl-%d", threadCount.getAndIncrement())); + thread.setName(String.format("rdf4j-SharedHttpClientSessionManager-%d", threadCount.getAndIncrement())); thread.setDaemon(true); return thread; }); @@ -120,18 +120,6 @@ public void setHttpClientBuilder(HttpClientBuilder httpClientBuilder) { this.httpClientBuilder = httpClientBuilder; } - private CloseableHttpClient createHttpClient() { - HttpClientBuilder nextHttpClientBuilder = httpClientBuilder; - if (nextHttpClientBuilder != null) { - return nextHttpClientBuilder.build(); - } - return HttpClientBuilder.create() - .useSystemProperties() - .disableAutomaticRetries() - .setDefaultRequestConfig(RequestConfig.custom().setCookieSpec(CookieSpecs.STANDARD).build()) - .build(); - } - @Override public SPARQLProtocolSession createSPARQLProtocolSession(String queryEndpointUrl, String updateEndpointUrl) { SPARQLProtocolSession session = new SPARQLProtocolSession(getHttpClient(), executor) { @@ -169,10 +157,6 @@ public void close() { return session; } - /*-----------------* - * Get/set methods * - *-----------------*/ - @Override public void shutDown() { try { @@ -212,4 +196,25 @@ public void shutDown() { public void initialize() { } + /** + * Get the {@link ScheduledExecutorService} used by this session manager. + * + * @return a {@link ScheduledExecutorService} used by all {@link SPARQLProtocolSession} and + * {@link RDF4JProtocolSession} instances created by this session manager. + */ + protected final ScheduledExecutorService getExecutorService() { + return this.executor; + } + + private CloseableHttpClient createHttpClient() { + HttpClientBuilder nextHttpClientBuilder = httpClientBuilder; + if (nextHttpClientBuilder != null) { + return nextHttpClientBuilder.build(); + } + return HttpClientBuilder.create() + .useSystemProperties() + .disableAutomaticRetries() + .setDefaultRequestConfig(RequestConfig.custom().setCookieSpec(CookieSpecs.STANDARD).build()) + .build(); + } }