You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by aj...@apache.org on 2016/12/08 14:23:28 UTC

[2/2] jena git commit: JENA-1263: Recommended redirect behavior

JENA-1263: Recommended redirect behavior


Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/183bfa49
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/183bfa49
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/183bfa49

Branch: refs/heads/master
Commit: 183bfa4923adec6560aed793bc01d921f44f6d33
Parents: fb9c4f9
Author: ajs6f <aj...@virginia.edu>
Authored: Thu Nov 17 11:59:29 2016 -0500
Committer: ajs6f <aj...@virginia.edu>
Committed: Thu Dec 8 09:23:00 2016 -0500

----------------------------------------------------------------------
 .../src/main/java/org/apache/jena/riot/web/HttpOp.java | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/183bfa49/jena-arq/src/main/java/org/apache/jena/riot/web/HttpOp.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/riot/web/HttpOp.java b/jena-arq/src/main/java/org/apache/jena/riot/web/HttpOp.java
index 7830f9a..7bf511c 100644
--- a/jena-arq/src/main/java/org/apache/jena/riot/web/HttpOp.java
+++ b/jena-arq/src/main/java/org/apache/jena/riot/web/HttpOp.java
@@ -36,7 +36,7 @@ import org.apache.http.entity.InputStreamEntity ;
 import org.apache.http.entity.StringEntity ;
 import org.apache.http.impl.client.CloseableHttpClient;
 import org.apache.http.impl.client.HttpClientBuilder ;
-import org.apache.http.impl.client.HttpClients;
+import org.apache.http.impl.client.LaxRedirectStrategy;
 import org.apache.http.impl.client.cache.CachingHttpClientBuilder;
 import org.apache.http.message.BasicNameValuePair ;
 import org.apache.http.protocol.HttpContext ;
@@ -115,6 +115,8 @@ public class HttpOp {
      */
     static private HttpResponseHandler nullHandler = HttpResponseLib.nullResponse;
 
+    private static final LaxRedirectStrategy laxRedirectStrategy = new LaxRedirectStrategy();
+
     /** Capture response as a string (UTF-8 assumed) */
     public static class CaptureString implements HttpCaptureResponse<String> {
         String result;
@@ -1059,7 +1061,7 @@ public class HttpOp {
         boolean closeClient = false;
         if (httpClient == null) {
             if (getDefaultHttpClient() == null ) {
-                httpClient = HttpClients.createMinimal();
+                httpClient = makeOneUseClient();
                 closeClient = true;
             }
             else httpClient = getDefaultHttpClient();
@@ -1103,6 +1105,13 @@ public class HttpOp {
         }
     }
 
+    /**
+     * @return a "default" HttpClient for use with one request
+     */
+    private static CloseableHttpClient makeOneUseClient() {
+        return HttpClientBuilder.create().setRedirectStrategy(laxRedirectStrategy).build();
+    }
+
 	public static String readPayload(HttpEntity entity) throws IOException {
         return entity == null ? null : EntityUtils.toString(entity, ContentType.getOrDefault(entity).getCharset());
 	}