You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2018/11/17 17:20:48 UTC
[22/34] jena git commit: Use FileEntity. It is repeatable and works
with auth 401 challenge.
Use FileEntity. It is repeatable and works with auth 401 challenge.
Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/6da6a8c2
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/6da6a8c2
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/6da6a8c2
Branch: refs/heads/master
Commit: 6da6a8c296959d535817a0a9cfce28e93bd6d25f
Parents: 1b0a78c
Author: Andy Seaborne <an...@apache.org>
Authored: Mon Nov 5 15:29:42 2018 +0000
Committer: Andy Seaborne <an...@apache.org>
Committed: Tue Nov 13 15:39:14 2018 +0000
----------------------------------------------------------------------
.../jena/rdfconnection/RDFConnectionRemote.java | 47 +++++++++++++++-----
1 file changed, 36 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jena/blob/6da6a8c2/jena-rdfconnection/src/main/java/org/apache/jena/rdfconnection/RDFConnectionRemote.java
----------------------------------------------------------------------
diff --git a/jena-rdfconnection/src/main/java/org/apache/jena/rdfconnection/RDFConnectionRemote.java b/jena-rdfconnection/src/main/java/org/apache/jena/rdfconnection/RDFConnectionRemote.java
index cb38355..44b00a5 100644
--- a/jena-rdfconnection/src/main/java/org/apache/jena/rdfconnection/RDFConnectionRemote.java
+++ b/jena-rdfconnection/src/main/java/org/apache/jena/rdfconnection/RDFConnectionRemote.java
@@ -19,15 +19,15 @@
package org.apache.jena.rdfconnection;
import java.io.File;
-import java.io.InputStream;
import java.util.Objects;
import java.util.function.Supplier;
import org.apache.http.HttpEntity;
import org.apache.http.client.HttpClient;
+import org.apache.http.entity.ContentType;
import org.apache.http.entity.EntityTemplate;
+import org.apache.http.entity.FileEntity;
import org.apache.http.protocol.HttpContext;
-import org.apache.jena.atlas.io.IO;
import org.apache.jena.atlas.lib.InternalErrorException;
import org.apache.jena.atlas.web.HttpException;
import org.apache.jena.atlas.web.TypedInputStream;
@@ -305,14 +305,30 @@ public class RDFConnectionRemote implements RDFConnection {
protected void doPutPost(String url, String file, Lang lang, boolean replace) {
File f = new File(file);
long length = f.length();
- InputStream source = IO.openFile(file);
- // Charset.
+
+ // Leave RDF/XML to the XML parse, else it's UTF-8.
+ String charset = (lang.equals(Lang.RDFXML) ? null : WebContent.charsetUTF8);
+ // HttpClient Content type.
+ ContentType ct = ContentType.create(lang.getContentType().getContentType(), charset);
+
exec(()->{
+ HttpEntity entity = fileToHttpEntity(file, lang);
if ( replace )
- HttpOp.execHttpPut(url, lang.getContentType().getContentType(), source, length, httpClient, this.httpContext);
+ HttpOp.execHttpPut(url, entity, httpClient, httpContext);
else
- HttpOp.execHttpPost(url, lang.getContentType().getContentType(), source, length, null, null, httpClient, this.httpContext);
+ HttpOp.execHttpPost(url, entity, httpClient, httpContext);
});
+
+ // This is non-repeatable so does not work with authentication.
+// InputStream source = IO.openFile(file);
+// exec(()->{
+// HttpOp.execHttpPost(url, null);
+//
+// if ( replace )
+// HttpOp.execHttpPut(url, lang.getContentType().getContentType(), source, length, httpClient, this.httpContext);
+// else
+// HttpOp.execHttpPost(url, lang.getContentType().getContentType(), source, length, null, null, httpClient, this.httpContext);
+// });
}
/** Send a model to named graph (or "default" or null for the defaultl graph).
@@ -326,9 +342,9 @@ public class RDFConnectionRemote implements RDFConnection {
exec(()->{
Graph graph = model.getGraph();
if ( replace )
- HttpOp.execHttpPut(url, graphToHttpEntity(graph), httpClient, this.httpContext);
+ HttpOp.execHttpPut(url, graphToHttpEntity(graph), httpClient, httpContext);
else
- HttpOp.execHttpPost(url, graphToHttpEntity(graph), null, null, httpClient, this.httpContext);
+ HttpOp.execHttpPost(url, graphToHttpEntity(graph), null, null, httpClient, httpContext);
});
}
@@ -397,11 +413,11 @@ public class RDFConnectionRemote implements RDFConnection {
File f = new File(file);
long length = f.length();
exec(()->{
- InputStream source = IO.openFile(file);
+ HttpEntity entity = fileToHttpEntity(file, lang);
if ( replace )
- HttpOp.execHttpPut(destination, lang.getContentType().getContentType(), source, length, httpClient, httpContext);
+ HttpOp.execHttpPut(destination, entity, httpClient, httpContext);
else
- HttpOp.execHttpPost(destination, lang.getContentType().getContentType(), source, length, null, null, httpClient, httpContext);
+ HttpOp.execHttpPost(destination, entity, httpClient, httpContext);
});
}
@@ -459,6 +475,15 @@ public class RDFConnectionRemote implements RDFConnection {
return ! isOpen;
}
+ protected HttpEntity fileToHttpEntity(String filename, Lang lang) {
+ // Leave RDF/XML to the XML parse, else it's UTF-8.
+ String charset = (lang.equals(Lang.RDFXML) ? null : WebContent.charsetUTF8);
+ // HttpClient Content type.
+ ContentType ct = ContentType.create(lang.getContentType().getContentType(), charset);
+ // Repeatable.
+ return new FileEntity(new File(filename), ct);
+ }
+
/** Create an HttpEntity for the graph */
protected HttpEntity graphToHttpEntity(Graph graph) {
return graphToHttpEntity(graph, outputTriples);