diff --git a/src/main/java/org/nanopub/NanopubImpl.java b/src/main/java/org/nanopub/NanopubImpl.java index 963d362..8f53dd3 100644 --- a/src/main/java/org/nanopub/NanopubImpl.java +++ b/src/main/java/org/nanopub/NanopubImpl.java @@ -27,6 +27,8 @@ import org.apache.commons.lang3.tuple.Pair; import org.apache.http.Header; import org.apache.http.HttpResponse; +import org.apache.http.client.config.CookieSpecs; +import org.apache.http.client.config.RequestConfig; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.HttpClientBuilder; import org.eclipse.rdf4j.RDF4JException; @@ -237,7 +239,8 @@ public NanopubImpl(URL url) throws MalformedNanopubException, RDF4JException, IO private HttpResponse getNanopub(URL url) throws IOException { HttpGet get = new HttpGet(url.toString()); get.setHeader("Accept", "application/trig; q=1, application/x-trig; q=1, text/x-nquads; q=0.1, application/trix; q=0.1"); - HttpResponse response = HttpClientBuilder.create().build().execute(get); + RequestConfig requestConfig = RequestConfig.custom().setCookieSpec(CookieSpecs.STANDARD).build(); + HttpResponse response = HttpClientBuilder.create().setDefaultRequestConfig(requestConfig).build().execute(get); int statusCode = response.getStatusLine().getStatusCode(); if (statusCode == 404 || statusCode == 410) { throw new FileNotFoundException(response.getStatusLine().getReasonPhrase()); diff --git a/src/main/java/org/nanopub/extra/security/IntroNanopub.java b/src/main/java/org/nanopub/extra/security/IntroNanopub.java index dd5b0dc..eb139ce 100644 --- a/src/main/java/org/nanopub/extra/security/IntroNanopub.java +++ b/src/main/java/org/nanopub/extra/security/IntroNanopub.java @@ -9,6 +9,7 @@ import org.apache.http.HttpResponse; 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.HttpGet; import org.apache.http.impl.client.HttpClientBuilder; @@ -35,7 +36,8 @@ public class IntroNanopub { static { RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(1000) - .setConnectionRequestTimeout(100).setSocketTimeout(1000).build(); + .setConnectionRequestTimeout(100).setSocketTimeout(1000) + .setCookieSpec(CookieSpecs.STANDARD).build(); defaultHttpClient = HttpClientBuilder.create().setDefaultRequestConfig(requestConfig).build(); } diff --git a/src/main/java/org/nanopub/extra/server/FetchIndex.java b/src/main/java/org/nanopub/extra/server/FetchIndex.java index 35c40dc..f488198 100644 --- a/src/main/java/org/nanopub/extra/server/FetchIndex.java +++ b/src/main/java/org/nanopub/extra/server/FetchIndex.java @@ -11,6 +11,7 @@ import java.util.Set; import org.apache.http.client.HttpClient; +import org.apache.http.client.config.CookieSpecs; import org.apache.http.client.config.RequestConfig; import org.apache.http.conn.ConnectionPoolTimeoutException; import org.apache.http.impl.client.HttpClientBuilder; @@ -83,7 +84,8 @@ public FetchIndex(String indexUri, OutputStream out, RDFFormat format, boolean w } nanopubCount = 0; RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(2000) - .setConnectionRequestTimeout(100).setSocketTimeout(2000).build(); + .setConnectionRequestTimeout(100).setSocketTimeout(2000) + .setCookieSpec(CookieSpecs.STANDARD).build(); PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager(); connManager.setDefaultMaxPerRoute(10); connManager.setMaxTotal(1000); diff --git a/src/main/java/org/nanopub/extra/server/GetNanopub.java b/src/main/java/org/nanopub/extra/server/GetNanopub.java index acdb78f..06e809b 100644 --- a/src/main/java/org/nanopub/extra/server/GetNanopub.java +++ b/src/main/java/org/nanopub/extra/server/GetNanopub.java @@ -14,6 +14,7 @@ import org.apache.http.HttpResponse; 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.HttpGet; import org.apache.http.impl.client.HttpClientBuilder; @@ -142,7 +143,8 @@ public static Nanopub get(String artifactCode, ServerInfo serverInfo) public static Nanopub get(String artifactCode, String serverUrl) throws IOException, RDF4JException, MalformedNanopubException { RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(1000) - .setConnectionRequestTimeout(100).setSocketTimeout(1000).build(); + .setConnectionRequestTimeout(100).setSocketTimeout(1000) + .setCookieSpec(CookieSpecs.STANDARD).build(); HttpClient c = HttpClientBuilder.create().setDefaultRequestConfig(requestConfig).build(); return get(artifactCode, serverUrl, c); } diff --git a/src/main/java/org/nanopub/extra/server/NanopubServerUtils.java b/src/main/java/org/nanopub/extra/server/NanopubServerUtils.java index 68f06f2..97ccf5a 100644 --- a/src/main/java/org/nanopub/extra/server/NanopubServerUtils.java +++ b/src/main/java/org/nanopub/extra/server/NanopubServerUtils.java @@ -10,6 +10,7 @@ import org.apache.http.HttpResponse; 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.HttpGet; import org.apache.http.impl.client.HttpClientBuilder; @@ -57,7 +58,8 @@ public static List loadList(String url) throws IOException { try { if (httpClient == null) { RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(2000) - .setConnectionRequestTimeout(100).setSocketTimeout(2000).build(); + .setConnectionRequestTimeout(100).setSocketTimeout(2000) + .setCookieSpec(CookieSpecs.STANDARD).build(); PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager(); connManager.setDefaultMaxPerRoute(10); connManager.setMaxTotal(1000); diff --git a/src/main/java/org/nanopub/extra/server/PublishNanopub.java b/src/main/java/org/nanopub/extra/server/PublishNanopub.java index 7a73b99..3ae09be 100644 --- a/src/main/java/org/nanopub/extra/server/PublishNanopub.java +++ b/src/main/java/org/nanopub/extra/server/PublishNanopub.java @@ -8,6 +8,8 @@ import java.util.Map; import org.apache.http.HttpResponse; +import org.apache.http.client.config.CookieSpecs; +import org.apache.http.client.config.RequestConfig; import org.apache.http.client.methods.HttpPost; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.HttpClientBuilder; @@ -185,7 +187,8 @@ public void publishNanopub(Nanopub nanopub) throws IOException { String nanopubString = NanopubUtils.writeToString(nanopub, RDFFormat.TRIG); post.setEntity(new StringEntity(nanopubString, "UTF-8")); post.setHeader("Content-Type", RDFFormat.TRIG.getDefaultMIMEType()); - HttpResponse response = HttpClientBuilder.create().build().execute(post); + RequestConfig requestConfig = RequestConfig.custom().setCookieSpec(CookieSpecs.STANDARD).build(); + HttpResponse response = HttpClientBuilder.create().setDefaultRequestConfig(requestConfig).build().execute(post); int code = response.getStatusLine().getStatusCode(); if (code >= 200 && code < 300) { if (usedServers.containsKey(serverUrl)) { diff --git a/src/main/java/org/nanopub/extra/server/ServerInfo.java b/src/main/java/org/nanopub/extra/server/ServerInfo.java index 447ae98..928ab13 100644 --- a/src/main/java/org/nanopub/extra/server/ServerInfo.java +++ b/src/main/java/org/nanopub/extra/server/ServerInfo.java @@ -7,6 +7,7 @@ import java.nio.charset.Charset; 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.HttpGet; import org.apache.http.impl.client.HttpClientBuilder; @@ -38,7 +39,8 @@ protected static ServerInfo load(String serverUrl, Class s InputStream in = null; try { RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(1000) - .setConnectionRequestTimeout(100).setSocketTimeout(1000).build(); + .setConnectionRequestTimeout(100).setSocketTimeout(1000) + .setCookieSpec(CookieSpecs.STANDARD).build(); HttpClient c = HttpClientBuilder.create().setDefaultRequestConfig(requestConfig).build(); in = c.execute(get).getEntity().getContent(); si = new Gson().fromJson(new InputStreamReader(in, Charset.forName("UTF-8")), serverInfoClass);