Index: SRUClient/trunk/src/main/java/eu/clarin/sru/client/SRUClientConfig.java
===================================================================
--- SRUClient/trunk/src/main/java/eu/clarin/sru/client/SRUClientConfig.java	(revision 7190)
+++ SRUClient/trunk/src/main/java/eu/clarin/sru/client/SRUClientConfig.java	(revision 7191)
@@ -21,4 +21,7 @@
 import java.util.List;
 
+import org.apache.http.client.protocol.HttpClientContext;
+import org.apache.http.impl.client.CloseableHttpClient;
+
 /**
  * A class for encapsulating the configuration of an SRU client.
@@ -34,4 +37,6 @@
     private final int connectTimeout;
     private final int socketTimeout;
+    private final CloseableHttpClient httpClient;
+    private final HttpClientContext httpContext;
     private final int threadCount;
     private final List<SRURecordDataParser> recordParsers;
@@ -50,5 +55,6 @@
 
     /**
-     * Get the connect timeout.
+     * Get the connect timeout. This value is ignored if a customized HTTP
+     * client is provided.
      *
      * @return the connect timeout
@@ -60,5 +66,6 @@
 
     /**
-     * Get the socket timeout.
+     * Get the socket timeout. This value is ignored if a customized HTTP client
+     * is provided.
      *
      * @return the connect timeout
@@ -66,4 +73,25 @@
     public int getSocketTimeout() {
         return socketTimeout;
+    }
+
+
+    /**
+     * Get the customized HTTP client which is to be used.
+     * 
+     * @return a configured HTTP client instance or <code>null</code>
+     */
+    public CloseableHttpClient getCustomizedHttpClient() {
+        return httpClient;
+    }
+
+
+    /**
+     * Get the HTTP client context which is to be used. Only relevant, if a
+     * customized HTTP client is set, see {{@link #getCustomizedHttpClient()}.
+     * 
+     * @return a HTTP client context instance or <code>null</code>
+     */
+    public HttpClientContext getHttpClientContext() {
+        return httpContext;
     }
 
@@ -104,10 +132,37 @@
             throw new NullPointerException("builder == null");
         }
-        this.defaultVersion   = builder.getDefaultVersion();
-        this.connectTimeout   = builder.getConnectTimeout();
-        this.socketTimeout    = builder.getSocketTimeout();
-        this.threadCount      = builder.getThreadCount();
-        this.recordParsers    = builder.getRecordDataParsers();
-        this.extraDataParsers = builder.getExtraResponseDataParsers();
+        this.defaultVersion   = builder.defaultVersion;
+        this.connectTimeout   = builder.connectTimeout;
+        this.socketTimeout    = builder.socketTimeout;
+        if (builder.httpClient != null) {
+            this.httpClient  = builder.httpClient;
+            this.httpContext = builder.httpContext;
+        } else {
+            this.httpClient  = null;
+            this.httpContext = null;
+        }
+        this.threadCount      = builder.threadCount;
+        if (builder.recordParsers != null) {
+            this.recordParsers =
+                    Collections.unmodifiableList(builder.recordParsers);
+        } else {
+            this.recordParsers = null;
+        }
+        if (builder.extraDataParsers != null) {
+            this.extraDataParsers =
+                    Collections.unmodifiableList(builder.extraDataParsers);
+        } else {
+            this.extraDataParsers = null;
+        }
+    }
+
+
+    /**
+     * Get a new builder for creating a new {@link SRUClientConfig} instance.
+     * 
+     * @return a builder instance
+     */
+    public static Builder builder() {
+        return new Builder();
     }
 
@@ -121,7 +176,9 @@
     public static class Builder {
         private SRUVersion defaultVersion = DEFAULT_SRU_VERSION;
-        private int connectTimeout        = DEFAULT_CONNECT_TIMEOUT;
-        private int socketTimeout         = DEFAULT_SOCKET_TIMEOUT;
-        private int threadCount           =
+        private int connectTimeout = DEFAULT_CONNECT_TIMEOUT;
+        private int socketTimeout = DEFAULT_SOCKET_TIMEOUT;
+        private CloseableHttpClient httpClient = null;
+        private HttpClientContext httpContext = null;
+        private int threadCount =
                 Runtime.getRuntime().availableProcessors() * 2;
         private List<SRURecordDataParser> recordParsers =
@@ -139,14 +196,4 @@
 
         /**
-         * Get the default SRU version to be used
-         *
-         * @return the defaultSRU version to be used
-         */
-        public SRUVersion getDefaultVersion() {
-            return defaultVersion;
-        }
-
-
-        /**
          * Set the default SRU version to be used.
          *
@@ -163,14 +210,4 @@
             this.defaultVersion = defaultVersion;
             return this;
-        }
-
-
-        /**
-         * Get the connect timeout.
-         *
-         * @return the connect timeout.
-         */
-        public int getConnectTimeout() {
-            return connectTimeout;
         }
 
@@ -193,15 +230,4 @@
             this.connectTimeout = connectTimeout;
             return this;
-        }
-
-
-        /**
-         * Get the socket timeout (<code>SO_TIMEOUT</code>) in milliseconds,
-         * which is the timeout for waiting for data.
-         *
-         * @return the socket timeout in milliseconds
-         */
-        public int getSocketTimeout() {
-            return socketTimeout;
         }
 
@@ -229,11 +255,27 @@
 
         /**
-         * Get the number of worker threads. This value is only relevant for the
-         * {@link SRUThreadedClient}.
-         *
-         * @return the number of worker threads
-         */
-        public int getThreadCount() {
-            return threadCount;
+         * Set a customized HTTP client which is to be used.
+         * 
+         * @param httpClient
+         *            a configured HTTP client instance
+         * @return this {@link Builder} instance
+         */
+        public Builder setCustomizedHttpClient(CloseableHttpClient httpClient) {
+            this.httpClient = httpClient;
+            return this;
+        }
+
+
+        /**
+         * Optionally set the HTTP context which is to be used by the customized
+         * HTTP client.
+         * 
+         * @param httpContext
+         *            a HTTP context instance
+         * @return this {@link Builder} instance
+         */
+        public Builder setHttpContext(HttpClientContext httpContext) {
+            this.httpContext = httpContext;
+            return this;
         }
 
@@ -253,30 +295,4 @@
             this.threadCount = threadCount;
             return this;
-        }
-
-
-        /**
-         * Get the list of record data parsers.
-         *
-         * @return the list of record data parsers
-         * @see SRURecordDataParser
-         */
-        public List<SRURecordDataParser> getRecordDataParsers() {
-            return Collections.unmodifiableList(recordParsers);
-        }
-
-
-        /**
-         * Get the list of extra response data parsers.
-         *
-         * @return the list of extra response data parsers
-         * @see SRUExtraResponseDataParser
-         */
-        public List<SRUExtraResponseDataParser> getExtraResponseDataParsers() {
-            if (extraDataParsers != null) {
-                return Collections.unmodifiableList(extraDataParsers);
-            } else {
-                return null;
-            }
         }
 
Index: SRUClient/trunk/src/main/java/eu/clarin/sru/client/SRUSimpleClient.java
===================================================================
--- SRUClient/trunk/src/main/java/eu/clarin/sru/client/SRUSimpleClient.java	(revision 7190)
+++ SRUClient/trunk/src/main/java/eu/clarin/sru/client/SRUSimpleClient.java	(revision 7191)
@@ -44,4 +44,5 @@
 import org.apache.http.impl.client.HttpClients;
 import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
+import org.apache.http.protocol.HttpContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -83,4 +84,5 @@
     private final Map<String, SRURecordDataParser> parsers;
     private final CloseableHttpClient httpClient;
+    private final HttpContext httpContext;
     private final XmlStreamReaderProxy proxy = new XmlStreamReaderProxy();
     private final SRUExplainRecordDataParser explainRecordParser =
@@ -123,7 +125,15 @@
         }
 
-        // create HTTP client
-        httpClient = createHttpClient(config.getConnectTimeout(),
-                                      config.getSocketTimeout());
+        final CloseableHttpClient client = config.getCustomizedHttpClient();
+        if (client != null) {
+            // use customized http client
+            this.httpClient = client;
+            this.httpContext = config.getHttpClientContext();
+        } else {
+            // create HTTP client
+            httpClient = createHttpClient(config.getConnectTimeout(),
+                    config.getSocketTimeout());
+            httpContext = null;
+        }
     }
 
@@ -405,5 +415,5 @@
             try {
                 HttpGet request = new HttpGet(uri);
-                response        = httpClient.execute(request);
+                response = httpClient.execute(request, httpContext);
                 StatusLine status = response.getStatusLine();
                 if (status.getStatusCode() != HttpStatus.SC_OK) {
@@ -1437,5 +1447,4 @@
                 .setSocketTimeout(socketTimeout)
                 .setConnectionRequestTimeout(0) /* infinite */
-                .setStaleConnectionCheckEnabled(false)
                 .build();
 
