You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@marmotta.apache.org by ja...@apache.org on 2013/12/13 23:08:14 UTC
[1/2] MARMOTTA-406: Moved HttpClient usage to the 4.3 mode,
but some tests are failing...
Updated Branches:
refs/heads/MARMOTTA-406 [created] fedcc159a
http://git-wip-us.apache.org/repos/asf/marmotta/blob/fedcc159/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/http/HttpClientServiceImpl.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/http/HttpClientServiceImpl.java b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/http/HttpClientServiceImpl.java
index afda0df..18b2b44 100644
--- a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/http/HttpClientServiceImpl.java
+++ b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/http/HttpClientServiceImpl.java
@@ -17,32 +17,65 @@
*/
package org.apache.marmotta.platform.core.services.http;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.charset.Charset;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Date;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicLong;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.event.Observes;
+import javax.enterprise.inject.Instance;
+import javax.inject.Inject;
+
import net.sf.ehcache.Ehcache;
-import org.apache.http.*;
+
+import org.apache.http.Header;
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpEntityEnclosingRequest;
+import org.apache.http.HttpHost;
+import org.apache.http.HttpRequest;
+import org.apache.http.HttpResponse;
+import org.apache.http.HttpStatus;
+import org.apache.http.ProtocolException;
+import org.apache.http.RequestLine;
import org.apache.http.client.ClientProtocolException;
-import org.apache.http.client.HttpClient;
import org.apache.http.client.HttpRequestRetryHandler;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.cache.CacheResponseStatus;
+import org.apache.http.client.cache.HttpCacheContext;
import org.apache.http.client.cache.HttpCacheStorage;
-import org.apache.http.client.methods.*;
-import org.apache.http.client.params.ClientPNames;
+import org.apache.http.client.config.RequestConfig;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpDelete;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpHead;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.client.methods.HttpPut;
+import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.conn.ClientConnectionManager;
-import org.apache.http.conn.scheme.PlainSocketFactory;
-import org.apache.http.conn.scheme.Scheme;
-import org.apache.http.conn.scheme.SchemeRegistry;
-import org.apache.http.conn.ssl.SSLSocketFactory;
+import org.apache.http.conn.HttpClientConnectionManager;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
-import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.DefaultRedirectStrategy;
+import org.apache.http.impl.client.HttpClientBuilder;
+import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.client.cache.CacheConfig;
-import org.apache.http.impl.client.cache.CachingHttpClient;
+import org.apache.http.impl.client.cache.CachingHttpClientBuilder;
import org.apache.http.impl.client.cache.ehcache.EhcacheHttpCacheStorage;
-import org.apache.http.impl.conn.PoolingClientConnectionManager;
-import org.apache.http.params.*;
+import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
+import org.apache.http.params.HttpParams;
import org.apache.http.pool.PoolStats;
-import org.apache.http.protocol.HTTP;
import org.apache.http.protocol.HttpContext;
import org.apache.http.util.EntityUtils;
import org.apache.marmotta.platform.core.api.config.ConfigurationService;
@@ -58,20 +91,6 @@ import org.apache.marmotta.platform.core.services.http.response.StatusCodeRespon
import org.apache.marmotta.platform.core.services.http.response.StringBodyResponseHandler;
import org.slf4j.Logger;
-import javax.annotation.PostConstruct;
-import javax.annotation.PreDestroy;
-import javax.enterprise.context.ApplicationScoped;
-import javax.enterprise.event.Observes;
-import javax.enterprise.inject.Instance;
-import javax.inject.Inject;
-import java.io.IOException;
-import java.io.InputStream;
-import java.nio.charset.Charset;
-import java.util.*;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicLong;
-import java.util.concurrent.locks.ReentrantReadWriteLock;
-
/**
**/
@ApplicationScoped
@@ -103,9 +122,9 @@ public class HttpClientServiceImpl implements HttpClientService {
@MarmottaCache("http-client-cache")
private Instance<Ehcache> ehcache;
- private HttpClient httpClient;
+ private CloseableHttpClient httpClient;
private IdleConnectionMonitorThread idleConnectionMonitorThread;
- private BasicHttpParams httpParams;
+// private BasicHttpParams httpParams;
private AtomicLong bytesSent = new AtomicLong();
private AtomicLong bytesReceived = new AtomicLong();
@@ -139,11 +158,11 @@ public class HttpClientServiceImpl implements HttpClientService {
}
/**
- * Get a ready-to-use {@link HttpClient}.
+ * Get a ready-to-use {@link CloseableHttpClient}.
*/
@Override
- public HttpClient getHttpClient() {
- return new ReadLockHttpClient();
+ public CloseableHttpClient getHttpClient() {
+ return new ReadLockHttpClient(httpClient);
}
/**
@@ -274,51 +293,48 @@ public class HttpClientServiceImpl implements HttpClientService {
try {
lock.writeLock().lock();
- httpParams = new BasicHttpParams();
+ final HttpClientBuilder clientBuilder;
+ if (configurationService.getBooleanConfiguration("core.http.client_cache_enable", true)) {
+ CacheConfig cacheConfig = CacheConfig.custom()
+ // FIXME: Hardcoded constants - is this useful?
+ .setMaxCacheEntries(1000)
+ .setMaxObjectSize(81920)
+ .build();
+
+ final HttpCacheStorage cacheStore = new EhcacheHttpCacheStorage(ehcache.get(), cacheConfig);
+ clientBuilder = CachingHttpClientBuilder.create()
+ .setCacheConfig(cacheConfig)
+ .setHttpCacheStorage(cacheStore);
+ } else {
+ clientBuilder = HttpClients.custom();
+ }
String userAgentString =
"Apache Marmotta/" + configurationService.getStringConfiguration("kiwi.version") +
" (running at " + configurationService.getServerUri() + ")" +
" lmf-core/" + configurationService.getStringConfiguration("kiwi.version");
- userAgentString = configurationService.getStringConfiguration("core.http.user_agent", userAgentString);
-
- httpParams.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, configurationService.getIntConfiguration("core.http.so_timeout", 60000));
- httpParams.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT,
- configurationService.getIntConfiguration("core.http.connection_timeout", 10000));
-
- httpParams.setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, true);
- httpParams.setIntParameter(ClientPNames.MAX_REDIRECTS, 3);
+ clientBuilder.setUserAgent(configurationService.getStringConfiguration("core.http.user_agent", userAgentString));
- SchemeRegistry schemeRegistry = new SchemeRegistry();
- schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
- schemeRegistry.register(new Scheme("https", 443, SSLSocketFactory.getSocketFactory()));
+ clientBuilder.setDefaultRequestConfig(RequestConfig.custom()
+ .setSocketTimeout(configurationService.getIntConfiguration("core.http.so_timeout", 60000))
+ .setConnectTimeout(configurationService.getIntConfiguration("core.http.connection_timeout", 10000))
+ .setRedirectsEnabled(true)
+ .setMaxRedirects(3)
+ .build());
- PoolingClientConnectionManager cm = new PoolingClientConnectionManager(schemeRegistry);
+ PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
cm.setMaxTotal(configurationService.getIntConfiguration("core.http.max_connections", 20));
cm.setDefaultMaxPerRoute(configurationService.getIntConfiguration("core.http.max_connections_per_route", 10));
+ clientBuilder.setConnectionManager(cm);
+
+ clientBuilder.setRedirectStrategy(new LMFRedirectStrategy());
+ clientBuilder.setRetryHandler(new LMFHttpRequestRetryHandler());
- final DefaultHttpClient hc = new DefaultHttpClient(cm, httpParams);
- hc.setRedirectStrategy(new LMFRedirectStrategy());
- hc.setHttpRequestRetryHandler(new LMFHttpRequestRetryHandler());
- hc.removeRequestInterceptorByClass(org.apache.http.protocol.RequestUserAgent.class);
- hc.addRequestInterceptor(new LMFRequestUserAgent(userAgentString));
-
- if (configurationService.getBooleanConfiguration("core.http.client_cache_enable", true)) {
- CacheConfig cacheConfig = new CacheConfig();
- // FIXME: Hardcoded constants - is this useful?
- cacheConfig.setMaxCacheEntries(1000);
- cacheConfig.setMaxObjectSize(81920);
-
- final HttpCacheStorage cacheStore = new EhcacheHttpCacheStorage(ehcache.get(), cacheConfig);
-
- this.httpClient = new MonitoredHttpClient(new CachingHttpClient(hc, cacheStore, cacheConfig));
- } else {
- this.httpClient = new MonitoredHttpClient(hc);
- }
+ this.httpClient = new MonitoredHttpClient(clientBuilder.build());
bytesSent.set(0);
bytesReceived.set(0);
requestsExecuted.set(0);
- idleConnectionMonitorThread = new IdleConnectionMonitorThread(httpClient.getConnectionManager());
+ idleConnectionMonitorThread = new IdleConnectionMonitorThread(cm);
idleConnectionMonitorThread.start();
StatisticsProvider stats = new StatisticsProvider(cm);
@@ -334,41 +350,16 @@ public class HttpClientServiceImpl implements HttpClientService {
lock.writeLock().lock();
statisticsService.unregisterModule(HttpClientService.class.getSimpleName());
idleConnectionMonitorThread.shutdown();
- httpClient.getConnectionManager().shutdown();
+ try {
+ httpClient.close();
+ } catch (IOException e) {
+ log.warn("Exception while closing HttpClient: {}", e.getMessage());
+ }
} finally {
lock.writeLock().unlock();
}
}
- private static class LMFRequestUserAgent implements HttpRequestInterceptor {
-
- private final String baseUserAgent;
-
- public LMFRequestUserAgent(String baseUserAgent) {
- this.baseUserAgent = baseUserAgent;
- }
-
- private final String buildUserAgentString(String localPart) {
- if (localPart == null || localPart.length() == 0)
- return baseUserAgent;
- else if (localPart.endsWith(baseUserAgent)) return localPart;
- return localPart + " " + baseUserAgent;
- }
-
- @Override
- public void process(HttpRequest request, HttpContext context) throws HttpException, IOException {
- if (request == null) throw new IllegalArgumentException("HTTP request must not be null");
- if (!request.containsHeader(HTTP.USER_AGENT)) {
- String useragent = HttpProtocolParams.getUserAgent(request.getParams());
- request.addHeader(HTTP.USER_AGENT, buildUserAgentString(useragent));
- } else {
- String useragent = request.getFirstHeader(HTTP.USER_AGENT).getValue();
- request.setHeader(HTTP.USER_AGENT, buildUserAgentString(useragent));
- }
- }
-
- }
-
private static class LMFRedirectStrategy extends DefaultRedirectStrategy {
@Override
public boolean isRedirected(HttpRequest request, HttpResponse response, HttpContext context) throws ProtocolException {
@@ -420,10 +411,10 @@ public class HttpClientServiceImpl implements HttpClientService {
private static class IdleConnectionMonitorThread extends Thread {
- private final ClientConnectionManager connMgr;
+ private final HttpClientConnectionManager connMgr;
private volatile boolean shutdown;
- public IdleConnectionMonitorThread(ClientConnectionManager connMgr) {
+ public IdleConnectionMonitorThread(HttpClientConnectionManager connMgr) {
super("HttpClientService Idle Connection Manager");
this.connMgr = connMgr;
setDaemon(true);
@@ -459,9 +450,9 @@ public class HttpClientServiceImpl implements HttpClientService {
private class StatisticsProvider implements StatisticsModule {
private boolean enabled;
- private PoolingClientConnectionManager connectionManager;
+ private PoolingHttpClientConnectionManager connectionManager;
- public StatisticsProvider(PoolingClientConnectionManager cm) {
+ public StatisticsProvider(PoolingHttpClientConnectionManager cm) {
this.connectionManager = cm;
enabled = true;
}
@@ -519,169 +510,54 @@ public class HttpClientServiceImpl implements HttpClientService {
}
- private class ReadLockHttpClient implements HttpClient {
+ private class ReadLockHttpClient extends CloseableHttpClient {
- private HttpParams params;
+ private final CloseableHttpClient delegate;
- public ReadLockHttpClient() {
- this.params = new DefaultedHttpParams(new BasicHttpParams(), httpParams);
+ public ReadLockHttpClient(CloseableHttpClient delegate) {
+ this.delegate = delegate;
}
@Override
+ @Deprecated
public HttpParams getParams() {
- return params;
+ return delegate.getParams();
}
@Override
+ @Deprecated
public ClientConnectionManager getConnectionManager() {
- return httpClient.getConnectionManager();
- }
-
- @Override
- public HttpResponse execute(HttpUriRequest request) throws IOException, ClientProtocolException {
- lock.readLock().lock();
- try {
- return httpClient.execute(request);
- } finally {
- lock.readLock().unlock();
- }
- }
-
- @Override
- public HttpResponse execute(HttpUriRequest request, HttpContext context) throws IOException, ClientProtocolException {
- lock.readLock().lock();
- try {
- return httpClient.execute(request, context);
- } finally {
- lock.readLock().unlock();
- }
+ return delegate.getConnectionManager();
}
@Override
- public HttpResponse execute(HttpHost target, HttpRequest request) throws IOException, ClientProtocolException {
- lock.readLock().lock();
- try {
- return httpClient.execute(target, request);
- } finally {
- lock.readLock().unlock();
- }
+ public void close() throws IOException {
+ // Nop; this Client is read only!
}
@Override
- public HttpResponse execute(HttpHost target, HttpRequest request, HttpContext context) throws IOException, ClientProtocolException {
+ protected CloseableHttpResponse doExecute(HttpHost target,
+ HttpRequest request, HttpContext context) throws IOException,
+ ClientProtocolException {
lock.readLock().lock();
try {
- return httpClient.execute(target, request, context);
+ return delegate.execute(target, request, context);
} finally {
- lock.readLock().unlock();
+ lock.readLock().lock();
}
}
- @Override
- public <T> T execute(HttpUriRequest request, ResponseHandler<? extends T> responseHandler) throws IOException, ClientProtocolException {
- lock.readLock().lock();
- try {
- return httpClient.execute(request, responseHandler);
- } finally {
- lock.readLock().unlock();
- }
- }
-
- @Override
- public <T> T execute(HttpUriRequest request, ResponseHandler<? extends T> responseHandler, HttpContext context) throws IOException,
- ClientProtocolException {
- lock.readLock().lock();
- try {
- return httpClient.execute(request, responseHandler, context);
- } finally {
- lock.readLock().unlock();
- }
- }
-
- @Override
- public <T> T execute(HttpHost target, HttpRequest request, ResponseHandler<? extends T> responseHandler) throws IOException,
- ClientProtocolException {
- lock.readLock().lock();
- try {
- return httpClient.execute(target, request, responseHandler);
- } finally {
- lock.readLock().unlock();
- }
- }
-
- @Override
- public <T> T execute(HttpHost target, HttpRequest request, ResponseHandler<? extends T> responseHandler, HttpContext context)
- throws IOException, ClientProtocolException {
- lock.readLock().lock();
- try {
- return httpClient.execute(target, request, responseHandler, context);
- } finally {
- lock.readLock().unlock();
- }
- }
}
- protected class MonitoredHttpClient implements HttpClient {
+ protected class MonitoredHttpClient extends CloseableHttpClient {
- private final HttpClient delegate;
+ private final CloseableHttpClient delegate;
- public MonitoredHttpClient(HttpClient delegate) {
+ public MonitoredHttpClient(CloseableHttpClient delegate) {
this.delegate = delegate;
}
- @Override
- public HttpParams getParams() {
- return delegate.getParams();
- }
-
- @Override
- public ClientConnectionManager getConnectionManager() {
- return delegate.getConnectionManager();
- }
-
- @Override
- public HttpResponse execute(HttpUriRequest request) throws IOException, ClientProtocolException {
- final Task task = preProcess(request);
-
- final HttpResponse response;
- lock.readLock().lock();
- try {
- response = delegate.execute(request);
- } catch (ClientProtocolException cpe) {
- task.endTask();
- throw cpe;
- } catch (IOException io) {
- task.endTask();
- throw io;
- } finally {
- lock.readLock().unlock();
- }
-
- return postProcess(response, null, task);
- }
-
- @Override
- public HttpResponse execute(HttpUriRequest request, HttpContext context) throws IOException, ClientProtocolException {
- final Task task = preProcess(request);
-
- final HttpResponse response;
- lock.readLock().lock();
- try {
- response = delegate.execute(request, context);
- } catch (ClientProtocolException cpe) {
- task.endTask();
- throw cpe;
- } catch (IOException io) {
- task.endTask();
- throw io;
- } finally {
- lock.readLock().unlock();
- }
-
- return postProcess(response, context, task);
- }
-
private Task preProcess(HttpRequest request) {
final RequestLine rl = request.getRequestLine();
final String taskName = String.format("%S %s %S", rl.getMethod(), rl.getUri(), request.getProtocolVersion());
@@ -702,14 +578,15 @@ public class HttpClientServiceImpl implements HttpClientService {
return task;
}
- private HttpResponse postProcess(final HttpResponse response, HttpContext context, final Task task) {
+ private CloseableHttpResponse postProcess(final CloseableHttpResponse response, HttpContext context, final Task task) {
requestsExecuted.incrementAndGet();
task.resetProgress();
task.updateMessage("retrieving response");
if (response.getEntity() != null) {
boolean cachedResponse;
- if (context != null) {
- CacheResponseStatus cacheRespStatus = (CacheResponseStatus) context.getAttribute(CachingHttpClient.CACHE_RESPONSE_STATUS);
+ if (context != null && context instanceof HttpCacheContext) {
+ HttpCacheContext cacheContext = (HttpCacheContext) context;
+ CacheResponseStatus cacheRespStatus = cacheContext.getCacheResponseStatus();
// To report download progress, the entity is wrapped in a MonitoredHttpEntity.
cachedResponse = cacheRespStatus != null && cacheRespStatus != CacheResponseStatus.CACHE_MISS;
} else {
@@ -723,34 +600,29 @@ public class HttpClientServiceImpl implements HttpClientService {
}
@Override
- public HttpResponse execute(HttpHost target, HttpRequest request) throws IOException, ClientProtocolException {
- final Task task = preProcess(request);
+ @Deprecated
+ public HttpParams getParams() {
+ return delegate.getParams();
+ }
- final HttpResponse response;
- lock.readLock().lock();
- try {
- response = delegate.execute(target, request);
- } catch (ClientProtocolException cpe) {
- task.endTask();
- throw cpe;
- } catch (IOException io) {
- task.endTask();
- throw io;
- } finally {
- lock.readLock().unlock();
- }
+ @Override
+ @Deprecated
+ public ClientConnectionManager getConnectionManager() {
+ return delegate.getConnectionManager();
+ }
- return postProcess(response, null, task);
+ @Override
+ public void close() throws IOException {
+ delegate.close();
}
@Override
- public HttpResponse execute(HttpHost target, HttpRequest request, HttpContext context) throws IOException, ClientProtocolException {
+ protected CloseableHttpResponse doExecute(HttpHost target, HttpRequest request, HttpContext context) throws IOException, ClientProtocolException {
final Task task = preProcess(request);
- final HttpResponse response;
lock.readLock().lock();
try {
- response = delegate.execute(target, request, context);
+ return postProcess(delegate.execute(target, request, context), context, task);
} catch (ClientProtocolException cpe) {
task.endTask();
throw cpe;
@@ -760,49 +632,6 @@ public class HttpClientServiceImpl implements HttpClientService {
} finally {
lock.readLock().unlock();
}
-
- return postProcess(response, context, task);
- }
-
- @Override
- public <T> T execute(HttpUriRequest request, ResponseHandler<? extends T> responseHandler) throws IOException, ClientProtocolException {
- final HttpResponse response = execute(request);
-
- return processResponse(responseHandler, response);
- }
-
- private <T> T processResponse(ResponseHandler<? extends T> responseHandler, final HttpResponse response) throws ClientProtocolException,
- IOException {
- try {
- return responseHandler.handleResponse(response);
- } finally {
- // Make sure everything is cleaned up properly
- EntityUtils.consume(response.getEntity());
- }
- }
-
- @Override
- public <T> T execute(HttpUriRequest request, ResponseHandler<? extends T> responseHandler, HttpContext context) throws IOException,
- ClientProtocolException {
- final HttpResponse response = execute(request, context);
-
- return processResponse(responseHandler, response);
- }
-
- @Override
- public <T> T execute(HttpHost target, HttpRequest request, ResponseHandler<? extends T> responseHandler) throws IOException,
- ClientProtocolException {
- final HttpResponse response = execute(target, request);
-
- return processResponse(responseHandler, response);
- }
-
- @Override
- public <T> T execute(HttpHost target, HttpRequest request, ResponseHandler<? extends T> responseHandler, HttpContext context)
- throws IOException, ClientProtocolException {
- final HttpResponse response = execute(target, request, context);
-
- return processResponse(responseHandler, response);
}
}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/fedcc159/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/prefix/PrefixCC.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/prefix/PrefixCC.java b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/prefix/PrefixCC.java
index b231800..79272f8 100644
--- a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/prefix/PrefixCC.java
+++ b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/prefix/PrefixCC.java
@@ -101,6 +101,7 @@ public class PrefixCC implements PrefixProvider {
@Override
public String handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
+ log.error("StatusCode: {}", response.getStatusLine().getStatusCode());
if (200 == response.getStatusLine().getStatusCode()) {
HttpEntity entity = response.getEntity();
@@ -108,6 +109,7 @@ public class PrefixCC implements PrefixProvider {
try {
while (it.hasNext()) {
final String l = it.next();
+ log.error(": {}", l);
if (l.endsWith("\t" + namespace)) {
return l.substring(0, l.indexOf("\t"));
}
[2/2] git commit: MARMOTTA-406: Moved HttpClient usage to the 4.3
mode, but some tests are failing...
Posted by ja...@apache.org.
MARMOTTA-406: Moved HttpClient usage to the 4.3 mode, but some tests are failing...
Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/fedcc159
Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/fedcc159
Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/fedcc159
Branch: refs/heads/MARMOTTA-406
Commit: fedcc159aea145ad1cf7a34a5b4a52ace9f35b46
Parents: 7c1f7d7
Author: Jakob Frank <ja...@apache.org>
Authored: Fri Dec 13 23:05:40 2013 +0100
Committer: Jakob Frank <ja...@apache.org>
Committed: Fri Dec 13 23:05:40 2013 +0100
----------------------------------------------------------------------
.../repochecker/RepositoryCheckerMojo.java | 23 +-
.../marmotta/client/ClientConfiguration.java | 8 +-
.../client/clients/ConfigurationClient.java | 40 +-
.../marmotta/client/clients/ContextClient.java | 11 +-
.../marmotta/client/clients/ImportClient.java | 27 +-
.../marmotta/client/clients/LDPathClient.java | 26 +-
.../marmotta/client/clients/ResourceClient.java | 51 +--
.../marmotta/client/clients/SPARQLClient.java | 33 +-
.../apache/marmotta/client/util/HTTPUtil.java | 41 +-
commons/marmotta-commons/pom.xml | 4 +
.../response/HasStatusCodeResponseHandler.java | 28 ++
.../ldclient/api/ldclient/LDClientService.java | 8 +-
.../ldclient/model/ClientConfiguration.java | 12 +-
.../ldclient/services/ldclient/LDClient.java | 127 +++---
.../services/provider/AbstractHttpProvider.java | 35 +-
.../ldclient/test/TestLDClientTest.java | 22 +-
.../ldclient/test/helper/TestLDClient.java | 4 +-
.../src/test/resources/logback.xml | 2 +-
.../test/rdf/TestLinkedDataProvider.java | 30 +-
.../core/api/http/HttpClientService.java | 16 +-
.../services/http/HttpClientServiceImpl.java | 421 ++++++-------------
.../platform/core/services/prefix/PrefixCC.java | 2 +
22 files changed, 399 insertions(+), 572 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/marmotta/blob/fedcc159/build/plugins/repocheck-maven-plugin/src/main/java/org/apache/marmotta/maven/plugins/repochecker/RepositoryCheckerMojo.java
----------------------------------------------------------------------
diff --git a/build/plugins/repocheck-maven-plugin/src/main/java/org/apache/marmotta/maven/plugins/repochecker/RepositoryCheckerMojo.java b/build/plugins/repocheck-maven-plugin/src/main/java/org/apache/marmotta/maven/plugins/repochecker/RepositoryCheckerMojo.java
index b1fe10c..0b1e84f 100644
--- a/build/plugins/repocheck-maven-plugin/src/main/java/org/apache/marmotta/maven/plugins/repochecker/RepositoryCheckerMojo.java
+++ b/build/plugins/repocheck-maven-plugin/src/main/java/org/apache/marmotta/maven/plugins/repochecker/RepositoryCheckerMojo.java
@@ -30,9 +30,9 @@ import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpHead;
-import org.apache.http.conn.ClientConnectionManager;
-import org.apache.http.impl.client.DefaultHttpClient;
-import org.apache.http.impl.conn.PoolingClientConnectionManager;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.plugin.AbstractMojo;
@@ -101,8 +101,10 @@ public class RepositoryCheckerMojo extends AbstractMojo {
}
public void execute() throws MojoExecutionException, MojoFailureException {
- ClientConnectionManager manager = new PoolingClientConnectionManager();
- final DefaultHttpClient client = new DefaultHttpClient(manager);
+ PoolingHttpClientConnectionManager manager = new PoolingHttpClientConnectionManager();
+ final CloseableHttpClient client = HttpClients.custom()
+ .setConnectionManager(manager)
+ .build();
final MatrixPrinter printer;
if (silent) {
@@ -163,13 +165,18 @@ public class RepositoryCheckerMojo extends AbstractMojo {
throw new MojoExecutionException(
"Cannot build project dependency graph", e);
} finally {
- client.getConnectionManager().shutdown();
+ try {
+ manager.shutdown();
+ client.close();
+ } catch (IOException e) {
+ getLog().warn("IOExeption while closing the HttpClient: " + e.getMessage());
+ }
}
}
private Set<Artifact> checkDepNode(final DependencyNode rootNode,
final List<ArtifactRepository> repositories, final int level,
- DefaultHttpClient client, MatrixPrinter printer)
+ CloseableHttpClient client, MatrixPrinter printer)
throws MojoFailureException {
if (!(level < depth))
return Collections.emptySet();
@@ -206,7 +213,7 @@ public class RepositoryCheckerMojo extends AbstractMojo {
}
private Result lookupArtifact(Artifact artifact, ArtifactRepository rep,
- DefaultHttpClient client) {
+ CloseableHttpClient client) {
if (artifact.isSnapshot() && !rep.getSnapshots().isEnabled()) {
return Result.NOT_FOUND;
http://git-wip-us.apache.org/repos/asf/marmotta/blob/fedcc159/client/marmotta-client-java/src/main/java/org/apache/marmotta/client/ClientConfiguration.java
----------------------------------------------------------------------
diff --git a/client/marmotta-client-java/src/main/java/org/apache/marmotta/client/ClientConfiguration.java b/client/marmotta-client-java/src/main/java/org/apache/marmotta/client/ClientConfiguration.java
index 57ea4c3..41f9a5a 100644
--- a/client/marmotta-client-java/src/main/java/org/apache/marmotta/client/ClientConfiguration.java
+++ b/client/marmotta-client-java/src/main/java/org/apache/marmotta/client/ClientConfiguration.java
@@ -17,7 +17,7 @@
*/
package org.apache.marmotta.client;
-import org.apache.http.conn.ClientConnectionManager;
+import org.apache.http.conn.HttpClientConnectionManager;
/**
* Add file description here!
@@ -58,7 +58,7 @@ public class ClientConfiguration {
*/
private int connectionTimeout = 10000;
- private ClientConnectionManager conectionManager;
+ private HttpClientConnectionManager conectionManager;
public ClientConfiguration(String marmottaUri) {
if (marmottaUri.endsWith("/")) {
@@ -122,11 +122,11 @@ public class ClientConfiguration {
this.connectionTimeout = connectionTimeout;
}
- public ClientConnectionManager getConectionManager() {
+ public HttpClientConnectionManager getConectionManager() {
return conectionManager;
}
- public void setConectionManager(ClientConnectionManager conectionManager) {
+ public void setConectionManager(HttpClientConnectionManager conectionManager) {
this.conectionManager = conectionManager;
}
}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/fedcc159/client/marmotta-client-java/src/main/java/org/apache/marmotta/client/clients/ConfigurationClient.java
----------------------------------------------------------------------
diff --git a/client/marmotta-client-java/src/main/java/org/apache/marmotta/client/clients/ConfigurationClient.java b/client/marmotta-client-java/src/main/java/org/apache/marmotta/client/clients/ConfigurationClient.java
index 6811191..3eb8eb6 100644
--- a/client/marmotta-client-java/src/main/java/org/apache/marmotta/client/clients/ConfigurationClient.java
+++ b/client/marmotta-client-java/src/main/java/org/apache/marmotta/client/clients/ConfigurationClient.java
@@ -17,13 +17,22 @@
*/
package org.apache.marmotta.client.clients;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.net.URLEncoder;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
import org.apache.http.HttpResponse;
-import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentProducer;
import org.apache.http.entity.EntityTemplate;
+import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.marmotta.client.ClientConfiguration;
import org.apache.marmotta.client.exception.MarmottaClientException;
import org.apache.marmotta.client.exception.NotFoundException;
@@ -34,15 +43,6 @@ import org.codehaus.jackson.type.TypeReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.net.URLEncoder;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
/**
* A client that supports accessing the configuration webservice of the Apache Marmotta. May be used for
* retrieving as well as changing properties.
@@ -69,12 +69,10 @@ public class ConfigurationClient {
* @throws MarmottaClientException
*/
public Set<String> listConfigurationKeys() throws IOException, MarmottaClientException {
- HttpClient httpClient = HTTPUtil.createClient(config);
-
HttpGet get = new HttpGet(config.getMarmottaUri() + URL_CONFIG_SERVICE + "/list");
get.setHeader("Accept", "application/json");
- try {
+ try(CloseableHttpClient httpClient = HTTPUtil.createClient(config)) {
HttpResponse response = httpClient.execute(get);
@@ -102,14 +100,13 @@ public class ConfigurationClient {
* @throws MarmottaClientException
*/
public Set<Configuration> listConfigurations(String prefix) throws IOException, MarmottaClientException {
- HttpClient httpClient = HTTPUtil.createClient(config);
String serviceUrl = config.getMarmottaUri() + URL_CONFIG_SERVICE + "/list" + (prefix != null? "?prefix="+ URLEncoder.encode(prefix,"utf-8") : "");
HttpGet get = new HttpGet(serviceUrl);
get.setHeader("Accept", "application/json");
- try {
+ try(CloseableHttpClient httpClient = HTTPUtil.createClient(config)) {
HttpResponse response = httpClient.execute(get);
@@ -144,14 +141,12 @@ public class ConfigurationClient {
* @throws MarmottaClientException
*/
public Configuration getConfiguration(String key) throws IOException, MarmottaClientException {
- HttpClient httpClient = HTTPUtil.createClient(config);
-
String serviceUrl = config.getMarmottaUri() + URL_CONFIG_SERVICE + "/data/" + URLEncoder.encode(key,"utf-8");
HttpGet get = new HttpGet(serviceUrl);
get.setHeader("Accept", "application/json");
- try {
+ try(CloseableHttpClient httpClient = HTTPUtil.createClient(config)) {
HttpResponse response = httpClient.execute(get);
@@ -189,8 +184,6 @@ public class ConfigurationClient {
* @throws MarmottaClientException
*/
public void setConfiguration(String key, final Object value) throws IOException, MarmottaClientException {
- HttpClient httpClient = HTTPUtil.createClient(config);
-
String serviceUrl = config.getMarmottaUri() + URL_CONFIG_SERVICE + "/data/" + URLEncoder.encode(key,"utf-8");
HttpPost post = new HttpPost(serviceUrl);
@@ -208,8 +201,7 @@ public class ConfigurationClient {
};
post.setEntity(new EntityTemplate(cp));
- try {
-
+ try(CloseableHttpClient httpClient = HTTPUtil.createClient(config)) {
HttpResponse response = httpClient.execute(post);
switch(response.getStatusLine().getStatusCode()) {
@@ -237,13 +229,11 @@ public class ConfigurationClient {
* @throws MarmottaClientException
*/
public void deleteConfiguration(String key) throws IOException, MarmottaClientException {
- HttpClient httpClient = HTTPUtil.createClient(config);
-
String serviceUrl = config.getMarmottaUri() + URL_CONFIG_SERVICE + "/data/" + URLEncoder.encode(key,"utf-8");
HttpDelete delete = new HttpDelete(serviceUrl);
- try {
+ try(CloseableHttpClient httpClient = HTTPUtil.createClient(config)) {
HttpResponse response = httpClient.execute(delete);
switch(response.getStatusLine().getStatusCode()) {
http://git-wip-us.apache.org/repos/asf/marmotta/blob/fedcc159/client/marmotta-client-java/src/main/java/org/apache/marmotta/client/clients/ContextClient.java
----------------------------------------------------------------------
diff --git a/client/marmotta-client-java/src/main/java/org/apache/marmotta/client/clients/ContextClient.java b/client/marmotta-client-java/src/main/java/org/apache/marmotta/client/clients/ContextClient.java
index ebd42ec..276b07a 100644
--- a/client/marmotta-client-java/src/main/java/org/apache/marmotta/client/clients/ContextClient.java
+++ b/client/marmotta-client-java/src/main/java/org/apache/marmotta/client/clients/ContextClient.java
@@ -17,17 +17,17 @@
*/
package org.apache.marmotta.client.clients;
+import java.io.IOException;
+
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
-import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpDelete;
+import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.marmotta.client.ClientConfiguration;
import org.apache.marmotta.client.util.HTTPUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.io.IOException;
-
/**
* Context Client
*
@@ -44,13 +44,12 @@ public class ContextClient {
this.config = config;
}
- public boolean delete(String uri) {
+ public boolean delete(String uri) throws IOException {
boolean result = false;
- HttpClient httpClient = HTTPUtil.createClient(config);
HttpDelete delete = new HttpDelete(uri);
- try {
+ try (CloseableHttpClient httpClient = HTTPUtil.createClient(config);) {
HttpResponse response = httpClient.execute(delete);
http://git-wip-us.apache.org/repos/asf/marmotta/blob/fedcc159/client/marmotta-client-java/src/main/java/org/apache/marmotta/client/clients/ImportClient.java
----------------------------------------------------------------------
diff --git a/client/marmotta-client-java/src/main/java/org/apache/marmotta/client/clients/ImportClient.java b/client/marmotta-client-java/src/main/java/org/apache/marmotta/client/clients/ImportClient.java
index b5314a0..565cb4b 100644
--- a/client/marmotta-client-java/src/main/java/org/apache/marmotta/client/clients/ImportClient.java
+++ b/client/marmotta-client-java/src/main/java/org/apache/marmotta/client/clients/ImportClient.java
@@ -17,15 +17,21 @@
*/
package org.apache.marmotta.client.clients;
-import com.google.common.io.ByteStreams;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.HashSet;
+import java.util.Set;
+
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
-import org.apache.http.client.HttpClient;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentProducer;
import org.apache.http.entity.EntityTemplate;
+import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.util.EntityUtils;
import org.apache.marmotta.client.ClientConfiguration;
import org.apache.marmotta.client.exception.MarmottaClientException;
@@ -35,12 +41,7 @@ import org.codehaus.jackson.type.TypeReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.util.HashSet;
-import java.util.Set;
+import com.google.common.io.ByteStreams;
/**
* This client class provides support for importing ontologies in various formats into the Apache Marmotta.
@@ -78,14 +79,12 @@ public class ImportClient {
* @throws MarmottaClientException
*/
public Set<String> getSupportedTypes() throws IOException, MarmottaClientException {
- HttpClient httpClient = HTTPUtil.createClient(config);
-
String serviceUrl = config.getMarmottaUri() + URL_TYPES_SERVICE;
HttpGet get = new HttpGet(serviceUrl);
get.setHeader("Accept", "application/json");
- try {
+ try(CloseableHttpClient httpClient = HTTPUtil.createClient(config)) {
HttpResponse response = httpClient.execute(get);
switch(response.getStatusLine().getStatusCode()) {
@@ -117,8 +116,6 @@ public class ImportClient {
public void uploadDataset(final InputStream in, final String mimeType) throws IOException, MarmottaClientException {
//Preconditions.checkArgument(acceptableTypes.contains(mimeType));
- HttpClient httpClient = HTTPUtil.createClient(config);
-
HttpPost post = HTTPUtil.createPost(URL_UPLOAD_SERVICE, config);
post.setHeader("Content-Type", mimeType);
@@ -148,8 +145,8 @@ public class ImportClient {
}
};
- try {
- httpClient.execute(post, handler);
+ try(CloseableHttpClient httpClient = HTTPUtil.createClient(config)) {
+ httpClient.execute(post, handler);
} catch(IOException ex) {
post.abort();
throw ex;
http://git-wip-us.apache.org/repos/asf/marmotta/blob/fedcc159/client/marmotta-client-java/src/main/java/org/apache/marmotta/client/clients/LDPathClient.java
----------------------------------------------------------------------
diff --git a/client/marmotta-client-java/src/main/java/org/apache/marmotta/client/clients/LDPathClient.java b/client/marmotta-client-java/src/main/java/org/apache/marmotta/client/clients/LDPathClient.java
index a679860..1753127 100644
--- a/client/marmotta-client-java/src/main/java/org/apache/marmotta/client/clients/LDPathClient.java
+++ b/client/marmotta-client-java/src/main/java/org/apache/marmotta/client/clients/LDPathClient.java
@@ -17,9 +17,16 @@
*/
package org.apache.marmotta.client.clients;
+import java.io.IOException;
+import java.net.URLEncoder;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
import org.apache.http.HttpResponse;
-import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
+import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.marmotta.client.ClientConfiguration;
import org.apache.marmotta.client.exception.ContentFormatException;
import org.apache.marmotta.client.exception.MarmottaClientException;
@@ -33,13 +40,6 @@ import org.codehaus.jackson.type.TypeReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.io.IOException;
-import java.net.URLEncoder;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
/**
* Add file description here!
* <p/>
@@ -72,16 +72,13 @@ public class LDPathClient {
* @throws IOException
*/
public List<RDFNode> evaluatePath(String uri, String path) throws MarmottaClientException, IOException {
- HttpClient httpClient = HTTPUtil.createClient(config);
-
String serviceUrl = config.getMarmottaUri() + URL_PATH_SERVICE + "?path=" + URLEncoder.encode(path, "utf-8")
+ "&uri=" + URLEncoder.encode(uri, "utf-8");
HttpGet get = new HttpGet(serviceUrl);
get.setHeader("Accept", "application/json");
- try {
-
+ try(CloseableHttpClient httpClient = HTTPUtil.createClient(config)) {
HttpResponse response = httpClient.execute(get);
switch(response.getStatusLine().getStatusCode()) {
@@ -117,16 +114,13 @@ public class LDPathClient {
public Map<String,List<RDFNode>> evaluateProgram(String uri, String program) throws MarmottaClientException, IOException {
- HttpClient httpClient = HTTPUtil.createClient(config);
-
String serviceUrl = config.getMarmottaUri() + URL_PROGRAM_SERVICE + "?program=" + URLEncoder.encode(program, "utf-8")
+ "&uri=" + URLEncoder.encode(uri, "utf-8");
HttpGet get = new HttpGet(serviceUrl);
get.setHeader("Accept", "application/json");
- try {
-
+ try(CloseableHttpClient httpClient = HTTPUtil.createClient(config)) {
HttpResponse response = httpClient.execute(get);
switch(response.getStatusLine().getStatusCode()) {
http://git-wip-us.apache.org/repos/asf/marmotta/blob/fedcc159/client/marmotta-client-java/src/main/java/org/apache/marmotta/client/clients/ResourceClient.java
----------------------------------------------------------------------
diff --git a/client/marmotta-client-java/src/main/java/org/apache/marmotta/client/clients/ResourceClient.java b/client/marmotta-client-java/src/main/java/org/apache/marmotta/client/clients/ResourceClient.java
index 575757f..c3534e1 100644
--- a/client/marmotta-client-java/src/main/java/org/apache/marmotta/client/clients/ResourceClient.java
+++ b/client/marmotta-client-java/src/main/java/org/apache/marmotta/client/clients/ResourceClient.java
@@ -17,11 +17,14 @@
*/
package org.apache.marmotta.client.clients;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.io.ByteStreams;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.util.Map;
+
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
-import org.apache.http.client.HttpClient;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
@@ -30,6 +33,7 @@ import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.entity.ContentProducer;
import org.apache.http.entity.EntityTemplate;
+import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.util.EntityUtils;
import org.apache.marmotta.client.ClientConfiguration;
import org.apache.marmotta.client.exception.ContentFormatException;
@@ -43,11 +47,8 @@ import org.apache.marmotta.client.util.RDFJSONParser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.UnsupportedEncodingException;
-import java.net.URLEncoder;
-import java.util.Map;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.io.ByteStreams;
/**
* Add file description here!
@@ -74,12 +75,9 @@ public class ResourceClient {
* @throws IOException
*/
public boolean createResource(String uri) throws IOException {
- HttpClient httpClient = HTTPUtil.createClient(config);
-
HttpPost post = new HttpPost(getServiceUrl(uri));
- try {
-
+ try(CloseableHttpClient httpClient = HTTPUtil.createClient(config)) {
HttpResponse response = httpClient.execute(post);
switch(response.getStatusLine().getStatusCode()) {
@@ -112,12 +110,9 @@ public class ResourceClient {
* @throws IOException
*/
public boolean existsResource(String uri) throws IOException {
- HttpClient httpClient = HTTPUtil.createClient(config);
-
HttpOptions options = new HttpOptions(getServiceUrl(uri));
- try {
-
+ try(CloseableHttpClient httpClient = HTTPUtil.createClient(config)) {
HttpResponse response = httpClient.execute(options);
if(response.containsHeader("Access-Control-Allow-Methods") && response.getFirstHeader("Access-Control-Allow-Methods").getValue().equals("POST")) {
@@ -148,13 +143,10 @@ public class ResourceClient {
* @throws MarmottaClientException
*/
public Metadata getResourceMetadata(String uri) throws IOException, MarmottaClientException {
- HttpClient httpClient = HTTPUtil.createClient(config);
-
HttpGet get = new HttpGet(getServiceUrl(uri));
get.setHeader("Accept", "application/rdf+json; rel=meta");
- try {
-
+ try(CloseableHttpClient httpClient = HTTPUtil.createClient(config)) {
HttpResponse response = httpClient.execute(get);
switch(response.getStatusLine().getStatusCode()) {
@@ -197,8 +189,6 @@ public class ResourceClient {
* @throws MarmottaClientException
*/
public void updateResourceMetadata(final String uri, final Metadata metadata) throws IOException, MarmottaClientException {
- HttpClient httpClient = HTTPUtil.createClient(config);
-
HttpPut put = new HttpPut(getServiceUrl(uri));
put.setHeader("Content-Type", "application/rdf+json; rel=meta");
ContentProducer cp = new ContentProducer() {
@@ -209,8 +199,7 @@ public class ResourceClient {
};
put.setEntity(new EntityTemplate(cp));
- try {
-
+ try(CloseableHttpClient httpClient = HTTPUtil.createClient(config)) {
HttpResponse response = httpClient.execute(put);
switch(response.getStatusLine().getStatusCode()) {
@@ -248,13 +237,10 @@ public class ResourceClient {
* @throws MarmottaClientException
*/
public Content getResourceContent(String uri, String mimeType) throws IOException, MarmottaClientException {
- HttpClient httpClient = HTTPUtil.createClient(config);
-
HttpGet get = new HttpGet(getServiceUrl(uri));
get.setHeader("Accept", mimeType+"; rel=content");
- try {
-
+ try(CloseableHttpClient httpClient = HTTPUtil.createClient(config)) {
HttpResponse response = httpClient.execute(get);
switch(response.getStatusLine().getStatusCode()) {
@@ -292,8 +278,6 @@ public class ResourceClient {
* @throws MarmottaClientException
*/
public void updateResourceContent(final String uri, final Content content) throws IOException, MarmottaClientException {
- HttpClient httpClient = HTTPUtil.createClient(config);
-
HttpPut put = new HttpPut(getServiceUrl(uri));
put.setHeader("Content-Type", content.getMimeType()+"; rel=content");
ContentProducer cp = new ContentProducer() {
@@ -325,7 +309,7 @@ public class ResourceClient {
}
};
- try {
+ try(CloseableHttpClient httpClient = HTTPUtil.createClient(config)) {
httpClient.execute(put, handler);
} catch(IOException ex) {
put.abort();
@@ -338,12 +322,9 @@ public class ResourceClient {
public void deleteResource(String uri) throws IOException {
- HttpClient httpClient = HTTPUtil.createClient(config);
-
HttpDelete delete = new HttpDelete(getServiceUrl(uri));
- try {
-
+ try(CloseableHttpClient httpClient = HTTPUtil.createClient(config)) {
HttpResponse response = httpClient.execute(delete);
switch(response.getStatusLine().getStatusCode()) {
http://git-wip-us.apache.org/repos/asf/marmotta/blob/fedcc159/client/marmotta-client-java/src/main/java/org/apache/marmotta/client/clients/SPARQLClient.java
----------------------------------------------------------------------
diff --git a/client/marmotta-client-java/src/main/java/org/apache/marmotta/client/clients/SPARQLClient.java b/client/marmotta-client-java/src/main/java/org/apache/marmotta/client/clients/SPARQLClient.java
index ddb96fa..640e86e 100644
--- a/client/marmotta-client-java/src/main/java/org/apache/marmotta/client/clients/SPARQLClient.java
+++ b/client/marmotta-client-java/src/main/java/org/apache/marmotta/client/clients/SPARQLClient.java
@@ -17,9 +17,17 @@
*/
package org.apache.marmotta.client.clients;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URLEncoder;
+import java.util.HashMap;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+
import org.apache.http.HttpResponse;
-import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
+import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.marmotta.client.ClientConfiguration;
import org.apache.marmotta.client.exception.MarmottaClientException;
import org.apache.marmotta.client.model.rdf.BNode;
@@ -46,14 +54,6 @@ import org.openrdf.query.resultio.helpers.QueryResultCollector;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URLEncoder;
-import java.util.HashMap;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Map;
-
/**
* Add file description here!
* <p/>
@@ -81,15 +81,12 @@ public class SPARQLClient {
* @throws MarmottaClientException
*/
public SPARQLResult select(String query) throws IOException, MarmottaClientException {
- HttpClient httpClient = HTTPUtil.createClient(config);
-
String serviceUrl = config.getMarmottaUri() + URL_QUERY_SERVICE + "?query=" + URLEncoder.encode(query, "utf-8");
HttpGet get = new HttpGet(serviceUrl);
get.setHeader("Accept", TupleQueryResultFormat.JSON.getDefaultMIMEType());
- try {
-
+ try(CloseableHttpClient httpClient = HTTPUtil.createClient(config)) {
HttpResponse response = httpClient.execute(get);
switch(response.getStatusLine().getStatusCode()) {
@@ -171,15 +168,12 @@ public class SPARQLClient {
* @throws MarmottaClientException
*/
public boolean ask(String askQuery) throws IOException, MarmottaClientException {
- HttpClient httpClient = HTTPUtil.createClient(config);
-
String serviceUrl = config.getMarmottaUri() + URL_QUERY_SERVICE + "?query=" + URLEncoder.encode(askQuery, "utf-8");
HttpGet get = new HttpGet(serviceUrl);
get.setHeader("Accept", BooleanQueryResultFormat.JSON.getDefaultMIMEType());
- try {
-
+ try(CloseableHttpClient httpClient = HTTPUtil.createClient(config)) {
HttpResponse response = httpClient.execute(get);
switch(response.getStatusLine().getStatusCode()) {
@@ -224,14 +218,11 @@ public class SPARQLClient {
* @throws MarmottaClientException in case the server returned and error and did not execute the update
*/
public void update(String updateQuery) throws IOException, MarmottaClientException {
- HttpClient httpClient = HTTPUtil.createClient(config);
-
String serviceUrl = config.getMarmottaUri() + URL_UPDATE_SERVICE + "?update=" + URLEncoder.encode(updateQuery, "utf-8");
HttpGet get = new HttpGet(serviceUrl);
- try {
-
+ try(CloseableHttpClient httpClient = HTTPUtil.createClient(config)) {
HttpResponse response = httpClient.execute(get);
switch(response.getStatusLine().getStatusCode()) {
http://git-wip-us.apache.org/repos/asf/marmotta/blob/fedcc159/client/marmotta-client-java/src/main/java/org/apache/marmotta/client/util/HTTPUtil.java
----------------------------------------------------------------------
diff --git a/client/marmotta-client-java/src/main/java/org/apache/marmotta/client/util/HTTPUtil.java b/client/marmotta-client-java/src/main/java/org/apache/marmotta/client/util/HTTPUtil.java
index 39192d8..8e09dc8 100644
--- a/client/marmotta-client-java/src/main/java/org/apache/marmotta/client/util/HTTPUtil.java
+++ b/client/marmotta-client-java/src/main/java/org/apache/marmotta/client/util/HTTPUtil.java
@@ -27,16 +27,16 @@ import org.apache.http.HttpStatus;
import org.apache.http.ProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.HttpRequestRetryHandler;
+import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpHead;
import org.apache.http.client.methods.HttpPost;
-import org.apache.http.client.params.ClientPNames;
+import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.client.DefaultRedirectStrategy;
-import org.apache.http.params.BasicHttpParams;
-import org.apache.http.params.CoreConnectionPNames;
-import org.apache.http.params.CoreProtocolPNames;
-import org.apache.http.params.HttpParams;
+import org.apache.http.impl.client.HttpClientBuilder;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.impl.conn.BasicHttpClientConnectionManager;
import org.apache.http.protocol.HttpContext;
import org.apache.marmotta.client.ClientConfiguration;
@@ -50,30 +50,33 @@ public class HTTPUtil {
private static final String CONTEXT = "context";
- public static HttpClient createClient(ClientConfiguration config) {
+ public static CloseableHttpClient createClient(ClientConfiguration config) {
- HttpParams httpParams = new BasicHttpParams();
- httpParams.setParameter(CoreProtocolPNames.USER_AGENT, "Marmotta Client Library/"+ MetaUtil.getVersion());
-
- httpParams.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, config.getSoTimeout());
- httpParams.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, config.getConnectionTimeout());
+ HttpClientBuilder clientBuilder = HttpClients.custom();
+ clientBuilder.setUserAgent("Marmotta Client Library/"+ MetaUtil.getVersion());
- httpParams.setBooleanParameter(ClientPNames.HANDLE_REDIRECTS,true);
- httpParams.setIntParameter(ClientPNames.MAX_REDIRECTS,3);
+ clientBuilder.setDefaultRequestConfig(RequestConfig.custom()
+ .setSocketTimeout(config.getSoTimeout())
+ .setConnectTimeout(config.getConnectionTimeout())
+ .setRedirectsEnabled(true)
+ .setMaxRedirects(3)
+ .build());
+ /* FIXME: This should be allowed to be deleted, could not find any usage of this param.
+ HttpParams httpParams = new BasicHttpParams();
if (StringUtils.isNotBlank(config.getMarmottaContext())) {
httpParams.setParameter(CONTEXT, config.getMarmottaContext());
}
+ */
- DefaultHttpClient client;
if (config.getConectionManager() != null) {
- client = new DefaultHttpClient(config.getConectionManager(), httpParams);
+ clientBuilder.setConnectionManager(config.getConectionManager());
} else {
- client = new DefaultHttpClient(httpParams);
+ clientBuilder.setConnectionManager(new BasicHttpClientConnectionManager());
}
- client.setRedirectStrategy(new MarmottaRedirectStrategy());
- client.setHttpRequestRetryHandler(new MarmottaHttpRequestRetryHandler());
- return client;
+ clientBuilder.setRedirectStrategy(new MarmottaRedirectStrategy());
+ clientBuilder.setRetryHandler(new MarmottaHttpRequestRetryHandler());
+ return clientBuilder.build();
}
public static HttpPost createPost(String path, ClientConfiguration config) {
http://git-wip-us.apache.org/repos/asf/marmotta/blob/fedcc159/commons/marmotta-commons/pom.xml
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/pom.xml b/commons/marmotta-commons/pom.xml
index eaf49bf..3965eb4 100644
--- a/commons/marmotta-commons/pom.xml
+++ b/commons/marmotta-commons/pom.xml
@@ -87,6 +87,10 @@
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
+ <groupId>org.apache.httpcomponents</groupId>
+ <artifactId>httpclient</artifactId>
+ </dependency>
+ <dependency>
<groupId>org.openrdf.sesame</groupId>
<artifactId>sesame-model</artifactId>
</dependency>
http://git-wip-us.apache.org/repos/asf/marmotta/blob/fedcc159/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/http/response/HasStatusCodeResponseHandler.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/http/response/HasStatusCodeResponseHandler.java b/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/http/response/HasStatusCodeResponseHandler.java
new file mode 100644
index 0000000..65db2c9
--- /dev/null
+++ b/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/http/response/HasStatusCodeResponseHandler.java
@@ -0,0 +1,28 @@
+package org.apache.marmotta.commons.http.response;
+
+import java.io.IOException;
+
+import org.apache.http.HttpResponse;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.ResponseHandler;
+import org.apache.http.util.EntityUtils;
+
+
+public class HasStatusCodeResponseHandler implements ResponseHandler<Boolean> {
+
+ private final int statusCode;
+
+ public HasStatusCodeResponseHandler(int statusCode) {
+ this.statusCode = statusCode;
+ }
+
+ @Override
+ public Boolean handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
+ try {
+ return statusCode == response.getStatusLine().getStatusCode();
+ } finally {
+ EntityUtils.consumeQuietly(response.getEntity());
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/fedcc159/libraries/ldclient/ldclient-api/src/main/java/org/apache/marmotta/ldclient/api/ldclient/LDClientService.java
----------------------------------------------------------------------
diff --git a/libraries/ldclient/ldclient-api/src/main/java/org/apache/marmotta/ldclient/api/ldclient/LDClientService.java b/libraries/ldclient/ldclient-api/src/main/java/org/apache/marmotta/ldclient/api/ldclient/LDClientService.java
index 4796bd9..b1f77bb 100644
--- a/libraries/ldclient/ldclient-api/src/main/java/org/apache/marmotta/ldclient/api/ldclient/LDClientService.java
+++ b/libraries/ldclient/ldclient-api/src/main/java/org/apache/marmotta/ldclient/api/ldclient/LDClientService.java
@@ -17,15 +17,15 @@
*/
package org.apache.marmotta.ldclient.api.ldclient;
-import org.apache.http.client.HttpClient;
+import java.util.Set;
+
+import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.marmotta.ldclient.api.endpoint.Endpoint;
import org.apache.marmotta.ldclient.api.provider.DataProvider;
import org.apache.marmotta.ldclient.exception.DataRetrievalException;
import org.apache.marmotta.ldclient.model.ClientConfiguration;
import org.apache.marmotta.ldclient.model.ClientResponse;
-import java.util.Set;
-
/**
* A service offering Linked Data client functionality for retrieving Linked Data resources from the cloud.
* Implements retrieval of triples from the cloud depending on the Endpoint definitions available for a resource.
@@ -61,7 +61,7 @@ public interface LDClientService {
*
* @return
*/
- public HttpClient getClient();
+ public CloseableHttpClient getClient();
/**
http://git-wip-us.apache.org/repos/asf/marmotta/blob/fedcc159/libraries/ldclient/ldclient-api/src/main/java/org/apache/marmotta/ldclient/model/ClientConfiguration.java
----------------------------------------------------------------------
diff --git a/libraries/ldclient/ldclient-api/src/main/java/org/apache/marmotta/ldclient/model/ClientConfiguration.java b/libraries/ldclient/ldclient-api/src/main/java/org/apache/marmotta/ldclient/model/ClientConfiguration.java
index ae6e143..f028496 100644
--- a/libraries/ldclient/ldclient-api/src/main/java/org/apache/marmotta/ldclient/model/ClientConfiguration.java
+++ b/libraries/ldclient/ldclient-api/src/main/java/org/apache/marmotta/ldclient/model/ClientConfiguration.java
@@ -17,12 +17,12 @@
*/
package org.apache.marmotta.ldclient.model;
-import org.apache.http.client.HttpClient;
-import org.apache.marmotta.ldclient.api.endpoint.Endpoint;
-
import java.util.HashSet;
import java.util.Set;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.marmotta.ldclient.api.endpoint.Endpoint;
+
/**
* Configuration options for the Linked Data Client.
* <p/>
@@ -71,7 +71,7 @@ public class ClientConfiguration {
/**
* A HttpClient used for retrieving the resource data.
*/
- private HttpClient httpClient;
+ private CloseableHttpClient httpClient;
public ClientConfiguration() {
excludeUris = new HashSet<String>();
@@ -160,11 +160,11 @@ public class ClientConfiguration {
this.endpoints = endpoints;
}
- public HttpClient getHttpClient() {
+ public CloseableHttpClient getHttpClient() {
return httpClient;
}
- public void setHttpClient(HttpClient httpClient) {
+ public void setHttpClient(CloseableHttpClient httpClient) {
this.httpClient = httpClient;
}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/fedcc159/libraries/ldclient/ldclient-core/src/main/java/org/apache/marmotta/ldclient/services/ldclient/LDClient.java
----------------------------------------------------------------------
diff --git a/libraries/ldclient/ldclient-core/src/main/java/org/apache/marmotta/ldclient/services/ldclient/LDClient.java b/libraries/ldclient/ldclient-core/src/main/java/org/apache/marmotta/ldclient/services/ldclient/LDClient.java
index e57f10e..924f89b 100644
--- a/libraries/ldclient/ldclient-core/src/main/java/org/apache/marmotta/ldclient/services/ldclient/LDClient.java
+++ b/libraries/ldclient/ldclient-core/src/main/java/org/apache/marmotta/ldclient/services/ldclient/LDClient.java
@@ -17,25 +17,33 @@
*/
package org.apache.marmotta.ldclient.services.ldclient;
-import org.apache.http.*;
-import org.apache.http.client.HttpClient;
-import org.apache.http.client.HttpRequestRetryHandler;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.ServiceLoader;
+import java.util.Set;
+import java.util.concurrent.Semaphore;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.http.Header;
+import org.apache.http.HttpRequest;
+import org.apache.http.HttpResponse;
+import org.apache.http.HttpStatus;
+import org.apache.http.ProtocolException;
+import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpHead;
-import org.apache.http.client.params.ClientPNames;
-import org.apache.http.conn.ClientConnectionManager;
-import org.apache.http.conn.scheme.PlainSocketFactory;
-import org.apache.http.conn.scheme.Scheme;
-import org.apache.http.conn.scheme.SchemeRegistry;
-import org.apache.http.conn.ssl.SSLSocketFactory;
-import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.conn.HttpClientConnectionManager;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.DefaultHttpRequestRetryHandler;
import org.apache.http.impl.client.DefaultRedirectStrategy;
-import org.apache.http.impl.conn.PoolingClientConnectionManager;
-import org.apache.http.params.BasicHttpParams;
-import org.apache.http.params.CoreConnectionPNames;
-import org.apache.http.params.CoreProtocolPNames;
-import org.apache.http.params.HttpParams;
+import org.apache.http.impl.client.HttpClientBuilder;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.http.protocol.HttpContext;
+import org.apache.marmotta.commons.http.response.HasStatusCodeResponseHandler;
import org.apache.marmotta.ldclient.api.endpoint.Endpoint;
import org.apache.marmotta.ldclient.api.ldclient.LDClientService;
import org.apache.marmotta.ldclient.api.provider.DataProvider;
@@ -45,14 +53,6 @@ import org.apache.marmotta.ldclient.model.ClientResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import javax.net.ssl.SSLContext;
-import java.io.IOException;
-import java.security.KeyManagementException;
-import java.security.NoSuchAlgorithmException;
-import java.util.*;
-import java.util.concurrent.Semaphore;
-import java.util.concurrent.TimeUnit;
-
/**
* Add file description here!
* <p/>
@@ -72,7 +72,7 @@ public final class LDClient implements LDClientService {
*/
private static ServiceLoader<Endpoint> defaultEndpoints = ServiceLoader.load(Endpoint.class);
- private HttpClient client;
+ private CloseableHttpClient client;
private IdleConnectionMonitorThread idleConnectionMonitorThread;
@@ -113,41 +113,28 @@ public final class LDClient implements LDClientService {
} else {
log.debug("Creating default HttpClient based on the configuration");
- HttpParams httpParams = new BasicHttpParams();
- httpParams.setParameter(CoreProtocolPNames.USER_AGENT, "Apache Marmotta LDClient");
-
- httpParams.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, config.getSocketTimeout());
- httpParams.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, config.getConnectionTimeout());
-
- httpParams.setBooleanParameter(ClientPNames.HANDLE_REDIRECTS,true);
- httpParams.setIntParameter(ClientPNames.MAX_REDIRECTS,3);
+ HttpClientBuilder clientBuilder = HttpClients.custom();
+ clientBuilder.setUserAgent("Apache Marmotta LDClient");
- SchemeRegistry schemeRegistry = new SchemeRegistry();
- schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
+ clientBuilder.setDefaultRequestConfig(RequestConfig.custom()
+ .setSocketTimeout(config.getSocketTimeout())
+ .setConnectTimeout(config.getConnectionTimeout())
+ .setRedirectsEnabled(true)
+ .setMaxRedirects(3)
+ .build());
- try {
- SSLContext sslcontext = SSLContext.getInstance("TLS");
- sslcontext.init(null, null, null);
- SSLSocketFactory sf = new SSLSocketFactory(sslcontext, SSLSocketFactory.STRICT_HOSTNAME_VERIFIER);
-
- schemeRegistry.register(new Scheme("https", 443, sf));
- } catch (NoSuchAlgorithmException e) {
- e.printStackTrace();
- } catch (KeyManagementException e) {
- e.printStackTrace();
- }
-
- PoolingClientConnectionManager cm = new PoolingClientConnectionManager(schemeRegistry);
+ PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
cm.setMaxTotal(20);
cm.setDefaultMaxPerRoute(10);
+ clientBuilder.setConnectionManager(cm);
- DefaultHttpClient client = new DefaultHttpClient(cm,httpParams);
- client.setRedirectStrategy(new LMFRedirectStrategy());
- client.setHttpRequestRetryHandler(new LMFHttpRequestRetryHandler());
- idleConnectionMonitorThread = new IdleConnectionMonitorThread(client.getConnectionManager());
+ clientBuilder.setRedirectStrategy(new MarmottaRedirectStrategy());
+ clientBuilder.setRetryHandler(new DefaultHttpRequestRetryHandler(0, false));
+
+ idleConnectionMonitorThread = new IdleConnectionMonitorThread(cm);
idleConnectionMonitorThread.start();
-
- this.client = client;
+
+ this.client = clientBuilder.build();
}
for(DataProvider provider : providers) {
@@ -160,7 +147,7 @@ public final class LDClient implements LDClientService {
//crappy implementation only for http
if (resource.startsWith("http://") || resource.startsWith("https://")) {
try {
- return (200 == client.execute(new HttpHead(resource)).getStatusLine().getStatusCode());
+ return client.execute(new HttpHead(resource), new HasStatusCodeResponseHandler(200));
} catch (Exception e) {
log.error(e.getMessage());
return false;
@@ -208,7 +195,11 @@ public final class LDClient implements LDClientService {
// we manage our own connection pool
if (idleConnectionMonitorThread != null)
idleConnectionMonitorThread.shutdown();
- client.getConnectionManager().shutdown();
+ try {
+ client.close();
+ } catch (IOException e) {
+ log.warn("Error while closing HttpClient: {}", e.getMessage());
+ }
}
}
@@ -264,7 +255,7 @@ public final class LDClient implements LDClientService {
* @return
*/
@Override
- public HttpClient getClient() {
+ public CloseableHttpClient getClient() {
return client;
}
@@ -331,7 +322,7 @@ public final class LDClient implements LDClientService {
return null;
}
- private static class LMFRedirectStrategy extends DefaultRedirectStrategy {
+ private static class MarmottaRedirectStrategy extends DefaultRedirectStrategy {
@Override
public boolean isRedirected(HttpRequest request, HttpResponse response, HttpContext context) throws ProtocolException {
if (response == null) throw new IllegalArgumentException("HTTP response may not be null");
@@ -357,30 +348,12 @@ public final class LDClient implements LDClientService {
}
}
- private static class LMFHttpRequestRetryHandler implements HttpRequestRetryHandler {
- /**
- * Determines if a method should be retried after an IOException
- * occurs during execution.
- *
- * @param exception the exception that occurred
- * @param executionCount the number of times this method has been
- * unsuccessfully executed
- * @param context the context for the request execution
- * @return <code>true</code> if the method should be retried, <code>false</code>
- * otherwise
- */
- @Override
- public boolean retryRequest(IOException exception, int executionCount, HttpContext context) {
- return false;
- }
- }
-
private static class IdleConnectionMonitorThread extends Thread {
- private final ClientConnectionManager connMgr;
+ private final HttpClientConnectionManager connMgr;
private volatile boolean shutdown;
- public IdleConnectionMonitorThread(ClientConnectionManager connMgr) {
+ public IdleConnectionMonitorThread(HttpClientConnectionManager connMgr) {
super("LD HTTP Client Idle Connection Manager");
this.connMgr = connMgr;
setDaemon(true);
http://git-wip-us.apache.org/repos/asf/marmotta/blob/fedcc159/libraries/ldclient/ldclient-core/src/main/java/org/apache/marmotta/ldclient/services/provider/AbstractHttpProvider.java
----------------------------------------------------------------------
diff --git a/libraries/ldclient/ldclient-core/src/main/java/org/apache/marmotta/ldclient/services/provider/AbstractHttpProvider.java b/libraries/ldclient/ldclient-core/src/main/java/org/apache/marmotta/ldclient/services/provider/AbstractHttpProvider.java
index 8f45da0..e4b26b9 100644
--- a/libraries/ldclient/ldclient-core/src/main/java/org/apache/marmotta/ldclient/services/provider/AbstractHttpProvider.java
+++ b/libraries/ldclient/ldclient-core/src/main/java/org/apache/marmotta/ldclient/services/provider/AbstractHttpProvider.java
@@ -17,13 +17,25 @@
*/
package org.apache.marmotta.ldclient.services.provider;
+import static org.apache.marmotta.commons.http.MarmottaHttpUtils.parseContentType;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Queue;
+import java.util.Set;
+
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpGet;
-import org.apache.http.impl.cookie.DateParseException;
-import org.apache.http.impl.cookie.DateUtils;
+import org.apache.http.client.utils.DateUtils;
import org.apache.http.util.EntityUtils;
import org.apache.marmotta.commons.collections.CollectionUtils;
import org.apache.marmotta.commons.http.ContentType;
@@ -40,19 +52,6 @@ import org.openrdf.sail.memory.MemoryStore;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Date;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Queue;
-import java.util.Set;
-
-import static org.apache.marmotta.commons.http.MarmottaHttpUtils.parseContentType;
-
/**
* Add file description here!
* <p/>
@@ -273,11 +272,7 @@ public abstract class AbstractHttpProvider implements DataProvider {
if (expiresDate == null) {
Header expires = response.getFirstHeader("Expires");
if (expires != null) {
- try {
- expiresDate = DateUtils.parseDate(expires.getValue());
- } catch (DateParseException e) {
- log.debug("error parsing Expires: header");
- }
+ expiresDate = DateUtils.parseDate(expires.getValue());
}
}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/fedcc159/libraries/ldclient/ldclient-core/src/test/java/org/apache/marmotta/ldclient/test/TestLDClientTest.java
----------------------------------------------------------------------
diff --git a/libraries/ldclient/ldclient-core/src/test/java/org/apache/marmotta/ldclient/test/TestLDClientTest.java b/libraries/ldclient/ldclient-core/src/test/java/org/apache/marmotta/ldclient/test/TestLDClientTest.java
index 4570c08..32ab98f 100644
--- a/libraries/ldclient/ldclient-core/src/test/java/org/apache/marmotta/ldclient/test/TestLDClientTest.java
+++ b/libraries/ldclient/ldclient-core/src/test/java/org/apache/marmotta/ldclient/test/TestLDClientTest.java
@@ -17,11 +17,13 @@
*/
package org.apache.marmotta.ldclient.test;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
import org.apache.marmotta.ldclient.exception.DataRetrievalException;
import org.apache.marmotta.ldclient.services.ldclient.LDClient;
import org.apache.marmotta.ldclient.test.helper.TestLDClient;
import org.junit.After;
-import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@@ -30,8 +32,6 @@ import org.junit.runner.Description;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.net.URI;
-
public class TestLDClientTest {
private TestLDClient client;
@@ -64,19 +64,29 @@ public class TestLDClientTest {
@Test(expected = UnsupportedOperationException.class)
public void testConnectionRefused() throws Exception {
client.retrieveResource("http://no.host.for/this/url");
- Assert.fail();
+ fail();
}
@Test(expected = DataRetrievalException.class)
public void testLocalhostInvalidPort() throws Exception {
client.retrieveResource("http://127.1.2.3:66000/");
- Assert.fail();
+ fail();
}
@Test(expected = UnsupportedOperationException.class)
public void testMissingProvider() throws Exception {
client.retrieveResource("ftp://no.provider.for/this/url");
- Assert.fail();
+ fail();
+ }
+
+ @Test
+ public void testPingHttpConnection() {
+ assertTrue("Ping http://www.google.com/", client.ping("http://www.google.com/"));
+ }
+
+ @Test
+ public void testPingHttpsConnection() {
+ assertTrue("Ping https://www.google.com/", client.ping("https://www.google.com/"));
}
}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/fedcc159/libraries/ldclient/ldclient-core/src/test/java/org/apache/marmotta/ldclient/test/helper/TestLDClient.java
----------------------------------------------------------------------
diff --git a/libraries/ldclient/ldclient-core/src/test/java/org/apache/marmotta/ldclient/test/helper/TestLDClient.java b/libraries/ldclient/ldclient-core/src/test/java/org/apache/marmotta/ldclient/test/helper/TestLDClient.java
index e6d4d94..a38a88d 100644
--- a/libraries/ldclient/ldclient-core/src/test/java/org/apache/marmotta/ldclient/test/helper/TestLDClient.java
+++ b/libraries/ldclient/ldclient-core/src/test/java/org/apache/marmotta/ldclient/test/helper/TestLDClient.java
@@ -28,7 +28,7 @@ import java.util.List;
import java.util.Set;
import java.util.regex.Pattern;
-import org.apache.http.client.HttpClient;
+import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.marmotta.ldclient.api.endpoint.Endpoint;
import org.apache.marmotta.ldclient.api.ldclient.LDClientService;
import org.apache.marmotta.ldclient.api.provider.DataProvider;
@@ -112,7 +112,7 @@ public class TestLDClient implements LDClientService {
}
@Override
- public HttpClient getClient() {
+ public CloseableHttpClient getClient() {
return delegate.getClient();
}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/fedcc159/libraries/ldclient/ldclient-core/src/test/resources/logback.xml
----------------------------------------------------------------------
diff --git a/libraries/ldclient/ldclient-core/src/test/resources/logback.xml b/libraries/ldclient/ldclient-core/src/test/resources/logback.xml
index 1bfecff..6a80ab4 100644
--- a/libraries/ldclient/ldclient-core/src/test/resources/logback.xml
+++ b/libraries/ldclient/ldclient-core/src/test/resources/logback.xml
@@ -24,4 +24,4 @@
<root level="${root-level:-INFO}">
<appender-ref ref="CONSOLE"/>
</root>
-</configuration>
\ No newline at end of file
+</configuration>
http://git-wip-us.apache.org/repos/asf/marmotta/blob/fedcc159/libraries/ldclient/ldclient-provider-rdf/src/test/java/org/apache/marmotta/ldclient/test/rdf/TestLinkedDataProvider.java
----------------------------------------------------------------------
diff --git a/libraries/ldclient/ldclient-provider-rdf/src/test/java/org/apache/marmotta/ldclient/test/rdf/TestLinkedDataProvider.java b/libraries/ldclient/ldclient-provider-rdf/src/test/java/org/apache/marmotta/ldclient/test/rdf/TestLinkedDataProvider.java
index f6fa7cf..281f87e 100644
--- a/libraries/ldclient/ldclient-provider-rdf/src/test/java/org/apache/marmotta/ldclient/test/rdf/TestLinkedDataProvider.java
+++ b/libraries/ldclient/ldclient-provider-rdf/src/test/java/org/apache/marmotta/ldclient/test/rdf/TestLinkedDataProvider.java
@@ -17,18 +17,28 @@
*/
package org.apache.marmotta.ldclient.test.rdf;
+import java.io.InputStream;
+
import org.apache.commons.io.IOUtils;
import org.apache.marmotta.ldclient.api.ldclient.LDClientService;
import org.apache.marmotta.ldclient.exception.DataRetrievalException;
import org.apache.marmotta.ldclient.model.ClientResponse;
import org.apache.marmotta.ldclient.services.ldclient.LDClient;
import org.apache.marmotta.ldclient.test.helper.TestLDClient;
-import org.junit.*;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Assume;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TestWatcher;
+import org.junit.runner.Description;
import org.openrdf.query.BooleanQuery;
import org.openrdf.query.QueryLanguage;
import org.openrdf.repository.RepositoryConnection;
-
-import java.io.InputStream;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Test if the LinkedDataProvider is working properly.
@@ -45,6 +55,9 @@ public class TestLinkedDataProvider {
private static final String EXAMPLE = "http://example.org/foo";
private static final String SSL = "https://example.org/foo";
+ private final Logger logger =
+ LoggerFactory.getLogger(this.getClass());
+
private LDClientService ldclient;
@Before
@@ -56,6 +69,17 @@ public class TestLinkedDataProvider {
public void shutdownClient() {
ldclient.shutdown();
}
+
+ @Rule
+ public TestWatcher watchman = new TestWatcher() {
+ /**
+ * Invoked when a test is about to start
+ */
+ @Override
+ protected void starting(Description description) {
+ logger.info("{} being run...", description.getMethodName());
+ }
+ };
/**
* This method tests accessing the DBPedia Linked Data service, which uses Virtuoso and delivers RDF/XML as
http://git-wip-us.apache.org/repos/asf/marmotta/blob/fedcc159/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/api/http/HttpClientService.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/api/http/HttpClientService.java b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/api/http/HttpClientService.java
index 37cd215..b3ca4be 100644
--- a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/api/http/HttpClientService.java
+++ b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/api/http/HttpClientService.java
@@ -17,17 +17,17 @@
*/
package org.apache.marmotta.platform.core.api.http;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Date;
+
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
-import org.apache.http.client.HttpClient;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.client.methods.HttpUriRequest;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Date;
+import org.apache.http.impl.client.CloseableHttpClient;
public interface HttpClientService {
@@ -39,7 +39,7 @@ public interface HttpClientService {
* @param handler the {@link ResponseHandler} for the response
* @return whatever the {@link ResponseHandler} builds.
*
- * @see HttpClient#execute(HttpUriRequest, ResponseHandler)
+ * @see CloseableHttpClient#execute(HttpUriRequest, ResponseHandler)
*/
public <T> T execute(HttpRequestBase request, ResponseHandler<? extends T> handler) throws ClientProtocolException, IOException;
@@ -161,8 +161,8 @@ public interface HttpClientService {
public Date doHead(String url) throws IOException;
/**
- * Get a ready-to-use {@link HttpClient}.
+ * Get a ready-to-use {@link CloseableHttpClient}.
*/
- public HttpClient getHttpClient();
+ public CloseableHttpClient getHttpClient();
}