Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Only ping dedicated sessions, and WIP resolving a blankNode issue.

  • Loading branch information...
commit 2be8f4d727ca82873a1d9a7f7ef2709b1d7d2730 1 parent 90bcecb
Bill Millar authored
View
115 src/com/franz/agraph/http/AGHttpRepoClient.java
@@ -207,6 +207,38 @@ public void getStatements(Resource subj, URI pred, Value obj,
}
}
+ public void addStatements(Resource subj, URI pred, Value obj,
+ Resource... contexts) throws IOException, RepositoryException,
+ UnauthorizedException {
+ String uri = Protocol.getStatementsLocation(getSessionRoot());
+ Header[] headers = { new Header("Content-Type", RDFFormat.NTRIPLES
+ .getDefaultMIMEType()) };
+ List<NameValuePair> params = new ArrayList<NameValuePair>(5);
+ if (subj != null) {
+ params.add(new NameValuePair(Protocol.SUBJECT_PARAM_NAME, Protocol
+ .encodeValue(subj)));
+ }
+ if (pred != null) {
+ params.add(new NameValuePair(Protocol.PREDICATE_PARAM_NAME,
+ Protocol.encodeValue(pred)));
+ }
+ if (obj != null) {
+ params.add(new NameValuePair(Protocol.OBJECT_PARAM_NAME, Protocol
+ .encodeValue(obj)));
+ }
+ for (String encodedContext : Protocol.encodeContexts(contexts)) {
+ params.add(new NameValuePair(Protocol.CONTEXT_PARAM_NAME,
+ encodedContext));
+ }
+ try {
+ getHTTPClient().post(uri, headers,
+ params.toArray(new NameValuePair[params.size()]), null,
+ null);
+ } catch (RDFParseException e) {
+ throw new RepositoryException(e);
+ }
+ }
+
public void deleteStatements(Resource subj, URI pred, Value obj,
Resource... contexts) throws RepositoryException {
String url = Protocol.getStatementsLocation(getSessionRoot());
@@ -260,9 +292,9 @@ public void setAutoCommit(boolean autoCommit) throws RepositoryException {
}
public boolean isAutoCommit() throws RepositoryException {
- return autoCommit; // TODO: let the server track this?
+ return autoCommit; // TODO: let the server track this?
}
-
+
public void commit() throws RepositoryException {
String url = getSessionRoot() + "/" + AGProtocol.COMMIT;
Header[] headers = {};
@@ -349,26 +381,29 @@ public void upload(InputStream contents, String baseURI,
upload(entity, baseURI, overwrite, null, null, null, contexts);
}
- public void load(URI source, String baseURI, RDFFormat dataFormat,
- Resource... contexts) throws IOException,
- RDFParseException, RepositoryException, UnauthorizedException {
+ public void load(URI source, String baseURI, RDFFormat dataFormat,
+ Resource... contexts) throws IOException, RDFParseException,
+ RepositoryException, UnauthorizedException {
upload(null, baseURI, false, null, source, dataFormat, contexts);
}
-
- public void load(String serverAbsolutePath, String baseURI, RDFFormat dataFormat,
- Resource... contexts) throws IOException,
+
+ public void load(String serverAbsolutePath, String baseURI,
+ RDFFormat dataFormat, Resource... contexts) throws IOException,
RDFParseException, RepositoryException, UnauthorizedException {
- upload(null, baseURI, false, serverAbsolutePath, null, dataFormat, contexts);
+ upload(null, baseURI, false, serverAbsolutePath, null, dataFormat,
+ contexts);
}
-
+
protected void upload(RequestEntity reqEntity, String baseURI,
- boolean overwrite, String serverSideFile, URI serverSideURL, RDFFormat dataFormat, Resource... contexts) throws IOException,
+ boolean overwrite, String serverSideFile, URI serverSideURL,
+ RDFFormat dataFormat, Resource... contexts) throws IOException,
RDFParseException, RepositoryException, UnauthorizedException {
OpenRDFUtil.verifyContextNotNull(contexts);
String url = Protocol.getStatementsLocation(getSessionRoot());
List<Header> headers = new ArrayList<Header>(1);
- if (dataFormat!=null) {
- headers.add(new Header("Content-Type", dataFormat.getDefaultMIMEType()));
+ if (dataFormat != null) {
+ headers.add(new Header("Content-Type", dataFormat
+ .getDefaultMIMEType()));
}
List<NameValuePair> params = new ArrayList<NameValuePair>(5);
for (String encodedContext : Protocol.encodeContexts(contexts)) {
@@ -381,13 +416,16 @@ protected void upload(RequestEntity reqEntity, String baseURI,
encodedBaseURI));
}
if (serverSideFile != null && serverSideFile.trim().length() != 0) {
- params.add(new NameValuePair(AGProtocol.FILE_PARAM_NAME, serverSideFile));
+ params.add(new NameValuePair(AGProtocol.FILE_PARAM_NAME,
+ serverSideFile));
}
if (serverSideURL != null) {
- params.add(new NameValuePair(AGProtocol.URL_PARAM_NAME,serverSideURL.stringValue()));
+ params.add(new NameValuePair(AGProtocol.URL_PARAM_NAME,
+ serverSideURL.stringValue()));
}
if (!overwrite) {
- getHTTPClient().post(url, headers.toArray(new Header[headers.size()]),
+ getHTTPClient().post(url,
+ headers.toArray(new Header[headers.size()]),
params.toArray(new NameValuePair[params.size()]),
reqEntity, null);
} else {
@@ -521,9 +559,9 @@ public void removeNamespacePrefix(String prefix) throws RepositoryException {
}
public void query(AGResponseHandler handler, QueryLanguage ql,
- String query, Dataset dataset, boolean includeInferred, String planner,
- Binding... bindings) throws HttpException, RepositoryException,
- RDFParseException, IOException {
+ String query, Dataset dataset, boolean includeInferred,
+ String planner, Binding... bindings) throws HttpException,
+ RepositoryException, RDFParseException, IOException {
String url = getSessionRoot();
List<Header> headers = new ArrayList<Header>(5);
headers.add(new Header("Content-Type", Protocol.FORM_MIME_TYPE
@@ -540,8 +578,8 @@ public void query(AGResponseHandler handler, QueryLanguage ql,
}
protected List<NameValuePair> getQueryMethodParameters(QueryLanguage ql,
- String query, Dataset dataset, boolean includeInferred, String planner,
- Binding... bindings) {
+ String query, Dataset dataset, boolean includeInferred,
+ String planner, Binding... bindings) {
List<NameValuePair> queryParams = new ArrayList<NameValuePair>(
bindings.length + 10);
@@ -550,8 +588,9 @@ public void query(AGResponseHandler handler, QueryLanguage ql,
queryParams.add(new NameValuePair(Protocol.QUERY_PARAM_NAME, query));
queryParams.add(new NameValuePair(Protocol.INCLUDE_INFERRED_PARAM_NAME,
Boolean.toString(includeInferred)));
- if (planner!=null) {
- queryParams.add(new NameValuePair(AGProtocol.PLANNER_PARAM_NAME, planner));
+ if (planner != null) {
+ queryParams.add(new NameValuePair(AGProtocol.PLANNER_PARAM_NAME,
+ planner));
}
if (dataset != null) {
@@ -572,7 +611,7 @@ public void query(AGResponseHandler handler, QueryLanguage ql,
.toString()));
}
} // TODO: no else clause here assumes AG's default dataset matches
- // Sesame's, confirm this.
+ // Sesame's, confirm this.
for (int i = 0; i < bindings.length; i++) {
String paramName = Protocol.BINDING_PREFIX + bindings[i].getName();
@@ -773,14 +812,15 @@ public void addRules(InputStream rulestream) throws RepositoryException {
public String evalInServer(String lispForm) throws RepositoryException {
String result;
try {
- InputStream stream = new ByteArrayInputStream(lispForm.getBytes("UTF-8"));
+ InputStream stream = new ByteArrayInputStream(lispForm
+ .getBytes("UTF-8"));
result = evalInServer(stream);
} catch (IOException e) {
throw new RepositoryException(e);
}
return result;
}
-
+
public String evalInServer(InputStream stream) throws RepositoryException {
String url = AGProtocol.getEvalLocation(getSessionRoot());
Header[] headers = {};
@@ -799,17 +839,18 @@ public String evalInServer(InputStream stream) throws RepositoryException {
}
public void ping() throws RepositoryException {
- String url = AGProtocol.getSessionPingLocation(getSessionRoot());
- Header[] headers = {};
- try {
- getHTTPClient().get(url, headers, new NameValuePair[0],
- null);
- } catch (HttpException e) {
- throw new RepositoryException(e);
- } catch (IOException e) {
- throw new RepositoryException(e);
- } catch (AGHttpException e) {
- throw new RepositoryException(e);
+ if (usingDedicatedSession) {
+ String url = AGProtocol.getSessionPingLocation(getSessionRoot());
+ Header[] headers = {};
+ try {
+ getHTTPClient().get(url, headers, new NameValuePair[0], null);
+ } catch (HttpException e) {
+ throw new RepositoryException(e);
+ } catch (IOException e) {
+ throw new RepositoryException(e);
+ } catch (AGHttpException e) {
+ throw new RepositoryException(e);
+ }
}
}
View
5 src/com/franz/agraph/repository/AGRepositoryConnection.java
@@ -75,6 +75,11 @@ public AGHttpRepoClient getHttpRepoClient() {
@Override
protected void addWithoutCommit(Resource subject, URI predicate,
Value object, Resource... contexts) throws RepositoryException {
+ /*try {
+ getHttpRepoClient().addStatements(subject, predicate, object, contexts);
+ } catch (IOException e) {
+ throw new RepositoryException(e);
+ }*/
ByteArrayOutputStream out = new ByteArrayOutputStream();
NTriplesWriter writer = new NTriplesWriter(out);
try {
Please sign in to comment.
Something went wrong with that request. Please try again.