Index: /OAIHarvester/trunk/OAIHarvester/pom.xml
===================================================================
--- /OAIHarvester/trunk/OAIHarvester/pom.xml	(revision 5457)
+++ /OAIHarvester/trunk/OAIHarvester/pom.xml	(revision 5458)
@@ -1,103 +1,77 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-  <modelVersion>4.0.0</modelVersion>
+<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+	<modelVersion>4.0.0</modelVersion>
 
-  <groupId>eu.clarin.cmdi</groupId>
-  <artifactId>OAIHarvester</artifactId>
-  <version>0.2.0-SNAPSHOT</version>
-  <packaging>jar</packaging>
-  <name>OAIHarvester</name>
+	<groupId>eu.clarin.cmdi</groupId>
+	<artifactId>OAIHarvester</artifactId>
+	<version>0.3.0-SNAPSHOT</version>
+	<packaging>jar</packaging>
+	<name>OAIHarvester</name>
 
-  <repositories>
-    <repository>
-      <id>repository.jboss-public</id>
-      <name>JBoss Repository</name>
-      <url>https://repository.jboss.org/nexus/content/groups/public/</url>
-    </repository>
+    <properties>
+        <!-- project settings -->
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+        <!-- plug-in settings -->
+        <maven.compiler.source>1.6</maven.compiler.source>
+        <maven.compiler.target>1.6</maven.compiler.target>
+        <!-- versions of common dependencies -->
+        <slf4j.version>1.7.7</slf4j.version>
+    </properties>
 
-    <repository>
-      <id>repository.java-net</id>
-      <name>Java.net Repository</name>
-      <url>http://download.java.net/maven/2/</url>
-    </repository>
-  </repositories>
+    <dependencies>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
+            <version>${slf4j.version}</version>
+        </dependency>
 
-  <build>
-    <resources>
-      <resource>
-        <directory>src/main/resources</directory>
-      </resource>
-    </resources>
+        <dependency>
+            <groupId>org.apache.httpcomponents</groupId>
+            <artifactId>httpclient</artifactId>
+            <version>4.3.4</version>
+        </dependency>
 
-    <plugins>
-      <plugin>
-        <groupId>org.apache.maven.plugins</groupId>
-        <artifactId>maven-compiler-plugin</artifactId>
-        <version>2.3.2</version>
-        <configuration>
-          <source>${maven.compiler.source}</source>
-          <target>${maven.compiler.target}</target>
-        </configuration>
-      </plugin>
-    </plugins>
-  </build>
+        <dependency>
+            <groupId>org.codehaus.woodstox</groupId>
+            <artifactId>woodstox-core-lgpl</artifactId>
+            <version>4.4.0</version>
+        </dependency>
 
-  <dependencies>
-    <dependency>
-      <groupId>org.slf4j</groupId>
-      <artifactId>slf4j-api</artifactId>
-      <version>${slf4j.version}</version>
-    </dependency>
+        <!--
+        <dependency>
+            <groupId>net.java.dev.msv</groupId>
+            <artifactId>msv-core</artifactId>
+            <version>2010.2</version>
+            <scope>runtime</scope>
+        </dependency>
+        -->
 
-    <dependency>
-    	<groupId>commons-lang</groupId>
-    	<artifactId>commons-lang</artifactId>
-    	<version>2.6</version>
-    	<type>jar</type>
-    	<scope>compile</scope>
-    </dependency>
+        <dependency>
+            <groupId>joda-time</groupId>
+            <artifactId>joda-time</artifactId>
+            <version>2.3</version>
+        </dependency>
 
-    <dependency>
-        <groupId>org.apache.httpcomponents</groupId>
-        <artifactId>httpclient</artifactId>
-        <version>4.2.5</version>
-    </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-log4j12</artifactId>
+            <version>${slf4j.version}</version>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
 
-    <dependency>
-    	<groupId>org.codehaus.woodstox</groupId>
-    	<artifactId>woodstox-core-lgpl</artifactId>
-    	<version>4.2.0</version>
-    </dependency>
-
-    <dependency>
-    	<groupId>net.java.dev.msv</groupId>
-    	<artifactId>msv-core</artifactId>
-    	<version>2010.2</version>
-    	<scope>runtime</scope>
-    </dependency>
-
-    <dependency>
-    	<groupId>joda-time</groupId>
-    	<artifactId>joda-time</artifactId>
-    	<version>2.0</version>
-    </dependency>
-
-    <dependency>
-      <groupId>org.slf4j</groupId>
-      <artifactId>slf4j-log4j12</artifactId>
-      <version>${slf4j.version}</version>
-      <scope>test</scope>
-    </dependency>
-  </dependencies>
-
-  <properties>
-    <!-- project settings -->
-    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
-    <!-- plug-in settings -->
-    <maven.compiler.source>1.6</maven.compiler.source>
-    <maven.compiler.target>1.6</maven.compiler.target>
-    <!-- versions of common dependencies -->
-    <slf4j.version>1.7.2</slf4j.version>
-  </properties>
+	<build>
+		<plugins>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-compiler-plugin</artifactId>
+				<version>2.3.2</version>
+				<configuration>
+					<source>${maven.compiler.source}</source>
+					<target>${maven.compiler.target}</target>
+				</configuration>
+			</plugin>
+		</plugins>
+	</build>
 
 </project>
Index: /OAIHarvester/trunk/OAIHarvester/src/main/java/eu/clarin/cmdi/oai/harvester/impl/HarvestWorker.java
===================================================================
--- /OAIHarvester/trunk/OAIHarvester/src/main/java/eu/clarin/cmdi/oai/harvester/impl/HarvestWorker.java	(revision 5457)
+++ /OAIHarvester/trunk/OAIHarvester/src/main/java/eu/clarin/cmdi/oai/harvester/impl/HarvestWorker.java	(revision 5458)
@@ -13,14 +13,15 @@
 import org.apache.http.HttpResponse;
 import org.apache.http.HttpStatus;
-import org.apache.http.client.HttpClient;
+import org.apache.http.client.config.CookieSpecs;
+import org.apache.http.client.config.RequestConfig;
+import org.apache.http.client.methods.CloseableHttpResponse;
 import org.apache.http.client.methods.HttpGet;
-import org.apache.http.client.utils.HttpClientUtils;
-import org.apache.http.impl.client.DefaultHttpClient;
-import org.apache.http.impl.cookie.DateParseException;
-import org.apache.http.impl.cookie.DateUtils;
-import org.apache.http.params.CoreConnectionPNames;
-import org.apache.http.params.CoreProtocolPNames;
-import org.apache.http.params.HttpParams;
-import org.apache.http.util.EntityUtils;
+import org.apache.http.client.utils.DateUtils;
+import org.apache.http.config.SocketConfig;
+import org.apache.http.impl.NoConnectionReuseStrategy;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
+import org.apache.http.protocol.BasicHttpContext;
 import org.joda.time.DateTime;
 import org.joda.time.DateTimeZone;
@@ -45,4 +46,5 @@
 
 public class HarvestWorker {
+    private static final String USER_AGENT = "OAI-Harvester/1.0.0";
     private static final String OAI_NS = "http://www.openarchives.org/OAI/2.0/";
     private static final String ARG_METADATA_PREFIX = "metadataPrefix";
@@ -68,5 +70,5 @@
             LoggerFactory.getLogger(HarvestWorker.class);
     private final AbstractHarvester harvester;
-    private final HttpClient client;
+    private final CloseableHttpClient client;
     private final RequestUriBuilder uriBuilder;
     private final HeaderImpl header;
@@ -77,8 +79,11 @@
     HarvestWorker(AbstractHarvester harvester) {
         this.harvester = harvester;
-        // http client
-        client = new DefaultHttpClient();
-        client.getParams().setParameter(CoreProtocolPNames.USER_AGENT,
-                "eu.clarin.cmdi.oai.Harvester/0.0.1");
+
+        // create HTTP client
+        // FIXME: get timeout values from somewhere?
+        final int connectTimeout = 30 * 1000;
+        final int socketTimeout = 180 * 1000;
+        client = createHttpClient(connectTimeout, socketTimeout);
+
         // request stuff
         uriBuilder = new RequestUriBuilder();
@@ -490,19 +495,18 @@
         }
         request.addHeader(HEADER_CONNECTION, "close");
-        // FIXME: get timeout values from somewhere?
-        HttpParams params = request.getParams();
-        params.setParameter(CoreConnectionPNames.SO_TIMEOUT, 180000);
-        params.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 30000);
-
-        final HttpResponse response = client.execute(request);
+
         /*
          * FIXME: the following code need serious re-factoring
          */
-        boolean close = false;
+        CloseableHttpResponse response = null;
+        boolean close = true;
         try {
+            response = client.execute(request, new BasicHttpContext());
             job.addToNetworkTime(System.currentTimeMillis() - now);
+
             final int status = response.getStatusLine().getStatusCode();
             if (status == HttpStatus.SC_OK) {
                 delay = 0;
+                close = false;
                 return new Response(job, response, harvester);
             } else {
@@ -511,5 +515,4 @@
                     logger.debug("got service unavailable status, retrying " +
                             "after {} seconds", delay);
-                    close = true;
                     return null;
                 } else {
@@ -520,29 +523,13 @@
             }
         } catch (IOException e) {
-            close = true;
             throw e;
         } catch (XMLStreamException e) {
-            close = true;
             throw e;
         } catch (HarvesterException e) {
-            close = true;
             throw e;
         } finally {
-            if (close) {
-                /*
-                 * try hard to release HTTP client resources ...
-                 */
-                try {
-                    EntityUtils.consume(response.getEntity());
-                } catch (IOException ex) {
-                    /* IGNORE */
-                }
-
-                /* make sure to release allocated resources */
-                HttpClientUtils.closeQuietly(response);
-
-                if (request != null) {
-                    request.abort();
-                }
+            if (close && (response != null)) {
+                /* make sure. response is closed ... */
+                response.close();
             }
         }
@@ -561,10 +548,8 @@
                 delay = Integer.parseInt(v) * 1000;
             } catch (NumberFormatException e) {
-                try {
                     Date date = DateUtils.parseDate(v);
-                    delay = date.getTime() - System.currentTimeMillis();
-                } catch (DateParseException f) {
-                    /* IGNORE */
-                }
+                    if (date != null) {
+                        delay = date.getTime() - System.currentTimeMillis();
+                    }
             }
         }
@@ -615,3 +600,37 @@
     }
 
+
+    private static CloseableHttpClient createHttpClient(int connectTimeout,
+            int socketTimeout) {
+        final PoolingHttpClientConnectionManager manager =
+                new PoolingHttpClientConnectionManager();
+        manager.setDefaultMaxPerRoute(8);
+        manager.setMaxTotal(128);
+
+        final SocketConfig socketConfig = SocketConfig.custom()
+                .setSoReuseAddress(true)
+                .setSoLinger(0)
+                .build();
+
+        final RequestConfig requestConfig = RequestConfig.custom()
+                .setAuthenticationEnabled(false)
+                .setRedirectsEnabled(true)
+                .setMaxRedirects(4)
+                .setCircularRedirectsAllowed(false)
+                .setCookieSpec(CookieSpecs.IGNORE_COOKIES)
+                .setConnectTimeout(connectTimeout)
+                .setSocketTimeout(socketTimeout)
+                .setConnectionRequestTimeout(0) /* infinite */
+                .setStaleConnectionCheckEnabled(false)
+                .build();
+
+        return HttpClients.custom()
+                .setUserAgent(USER_AGENT)
+                .setConnectionManager(manager)
+                .setDefaultSocketConfig(socketConfig)
+                .setDefaultRequestConfig(requestConfig)
+                .setConnectionReuseStrategy(new NoConnectionReuseStrategy())
+                .build();
+    }
+
 } // class HarvestWorker
Index: /OAIHarvester/trunk/OAIHarvester/src/main/java/eu/clarin/cmdi/oai/harvester/impl/Response.java
===================================================================
--- /OAIHarvester/trunk/OAIHarvester/src/main/java/eu/clarin/cmdi/oai/harvester/impl/Response.java	(revision 5457)
+++ /OAIHarvester/trunk/OAIHarvester/src/main/java/eu/clarin/cmdi/oai/harvester/impl/Response.java	(revision 5458)
@@ -19,7 +19,5 @@
 
 import org.apache.http.HttpEntity;
-import org.apache.http.HttpResponse;
-import org.apache.http.client.utils.HttpClientUtils;
-import org.apache.http.util.EntityUtils;
+import org.apache.http.client.methods.CloseableHttpResponse;
 import org.codehaus.stax2.XMLStreamReader2;
 import org.slf4j.Logger;
@@ -84,5 +82,5 @@
     private static final Logger logger =
             LoggerFactory.getLogger(Response.class);
-    private final HttpResponse response;
+    private final CloseableHttpResponse response;
     private final long now = System.currentTimeMillis();
     private final CountingInputStream stream;
@@ -90,5 +88,5 @@
 
 
-    Response(HarvestJobImpl job, HttpResponse response, AbstractHarvester harvester)
+    Response(HarvestJobImpl job, CloseableHttpResponse response, AbstractHarvester harvester)
             throws IOException, XMLStreamException, HarvesterException {
         if (job == null) {
@@ -165,15 +163,10 @@
         }
 
-        /*
-         * try hard to release HTTP client resources ...
-         */
+        /* make sure to release allocated resources */
         try {
-            EntityUtils.consume(response.getEntity());
-        } catch (IOException ex) {
+            response.close();
+        } catch (IOException e) {
             /* IGNORE */
         }
-
-        /* make sure to release allocated resources */
-        HttpClientUtils.closeQuietly(response);
     }
 
@@ -382,5 +375,5 @@
         while (reader.isCharacters()) {
             String s = reader.getText();
-            if (s != null) {
+            if ((s != null) && !s.isEmpty()) {
                 sb.append(s);
             }
