Merge branch 'maint-rel-1.6' into develop
This commit is contained in:
commit
eedc6215f4
2 changed files with 35 additions and 14 deletions
|
@ -4,6 +4,7 @@ package edu.cornell.mannlib.vitro.webapp.rdfservice.impl.sparql;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -14,7 +15,9 @@ import java.util.concurrent.ConcurrentLinkedQueue;
|
||||||
import org.apache.commons.httpclient.HttpClient;
|
import org.apache.commons.httpclient.HttpClient;
|
||||||
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
|
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
|
||||||
import org.apache.commons.httpclient.NameValuePair;
|
import org.apache.commons.httpclient.NameValuePair;
|
||||||
|
import org.apache.commons.httpclient.methods.GetMethod;
|
||||||
import org.apache.commons.httpclient.methods.PostMethod;
|
import org.apache.commons.httpclient.methods.PostMethod;
|
||||||
|
import org.apache.commons.httpclient.params.HttpMethodParams;
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
@ -38,6 +41,7 @@ import com.hp.hpl.jena.rdf.model.ModelFactory;
|
||||||
import com.hp.hpl.jena.rdf.model.RDFNode;
|
import com.hp.hpl.jena.rdf.model.RDFNode;
|
||||||
import com.hp.hpl.jena.rdf.model.Statement;
|
import com.hp.hpl.jena.rdf.model.Statement;
|
||||||
import com.hp.hpl.jena.rdf.model.StmtIterator;
|
import com.hp.hpl.jena.rdf.model.StmtIterator;
|
||||||
|
import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.SparqlGraph;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.SparqlGraph;
|
||||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.ChangeListener;
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.ChangeListener;
|
||||||
|
@ -84,11 +88,11 @@ public class RDFServiceSparql extends RDFServiceImpl implements RDFService {
|
||||||
this.readRepository = new HTTPRepository(readEndpointURI);
|
this.readRepository = new HTTPRepository(readEndpointURI);
|
||||||
this.updateRepository = new HTTPRepository(updateEndpointURI);
|
this.updateRepository = new HTTPRepository(updateEndpointURI);
|
||||||
|
|
||||||
testConnection();
|
|
||||||
|
|
||||||
MultiThreadedHttpConnectionManager mgr = new MultiThreadedHttpConnectionManager();
|
MultiThreadedHttpConnectionManager mgr = new MultiThreadedHttpConnectionManager();
|
||||||
mgr.getParams().setDefaultMaxConnectionsPerHost(10);
|
mgr.getParams().setDefaultMaxConnectionsPerHost(50);
|
||||||
this.httpClient = new HttpClient(mgr);
|
this.httpClient = new HttpClient(mgr);
|
||||||
|
|
||||||
|
testConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void testConnection() {
|
private void testConnection() {
|
||||||
|
@ -279,11 +283,26 @@ public class RDFServiceSparql extends RDFServiceImpl implements RDFService {
|
||||||
@Override
|
@Override
|
||||||
public InputStream sparqlSelectQuery(String queryStr, RDFService.ResultFormat resultFormat) throws RDFServiceException {
|
public InputStream sparqlSelectQuery(String queryStr, RDFService.ResultFormat resultFormat) throws RDFServiceException {
|
||||||
|
|
||||||
Query query = createQuery(queryStr);
|
//QueryEngineHTTP qh = new QueryEngineHTTP(readEndpointURI, queryStr);
|
||||||
QueryExecution qe = QueryExecutionFactory.sparqlService(readEndpointURI, query);
|
|
||||||
|
|
||||||
|
GetMethod meth = new GetMethod(readEndpointURI);
|
||||||
try {
|
try {
|
||||||
ResultSet resultSet = qe.execSelect();
|
meth.addRequestHeader("Accept", "application/sparql-results+xml");
|
||||||
|
NameValuePair param = new NameValuePair();
|
||||||
|
param.setName("query");
|
||||||
|
param.setValue(queryStr);
|
||||||
|
NameValuePair[] params = new NameValuePair[1];
|
||||||
|
params[0] = param;
|
||||||
|
meth.setQueryString(params);
|
||||||
|
int response = httpClient.executeMethod(meth);
|
||||||
|
if (response > 399) {
|
||||||
|
log.error("response " + response + " to query. \n");
|
||||||
|
log.debug("update string: \n" + queryStr);
|
||||||
|
throw new RDFServiceException("Unable to perform SPARQL UPDATE");
|
||||||
|
}
|
||||||
|
|
||||||
|
InputStream in = meth.getResponseBodyAsStream();
|
||||||
|
ResultSet resultSet = ResultSetFactory.fromXML(in);
|
||||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||||
|
|
||||||
switch (resultFormat) {
|
switch (resultFormat) {
|
||||||
|
@ -302,11 +321,13 @@ public class RDFServiceSparql extends RDFServiceImpl implements RDFService {
|
||||||
default:
|
default:
|
||||||
throw new RDFServiceException("unrecognized result format");
|
throw new RDFServiceException("unrecognized result format");
|
||||||
}
|
}
|
||||||
|
|
||||||
InputStream result = new ByteArrayInputStream(outputStream.toByteArray());
|
InputStream result = new ByteArrayInputStream(outputStream.toByteArray());
|
||||||
return result;
|
return result;
|
||||||
|
} catch (IOException ioe) {
|
||||||
|
throw new RuntimeException(ioe);
|
||||||
} finally {
|
} finally {
|
||||||
qe.close();
|
//qh.close();
|
||||||
|
meth.releaseConnection();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -474,7 +495,7 @@ public class RDFServiceSparql extends RDFServiceImpl implements RDFService {
|
||||||
int response = httpClient.executeMethod(meth);
|
int response = httpClient.executeMethod(meth);
|
||||||
if (response > 399) {
|
if (response > 399) {
|
||||||
log.error("response " + response + " to update. \n");
|
log.error("response " + response + " to update. \n");
|
||||||
log.debug("update string: \n" + updateString);
|
//log.debug("update string: \n" + updateString);
|
||||||
throw new RDFServiceException("Unable to perform SPARQL UPDATE");
|
throw new RDFServiceException("Unable to perform SPARQL UPDATE");
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
|
|
|
@ -142,7 +142,7 @@ name will be used as the label. -->
|
||||||
</#macro>
|
</#macro>
|
||||||
|
|
||||||
<#macro showAddLink propertyLocalName label url rangeUri domainUri="">
|
<#macro showAddLink propertyLocalName label url rangeUri domainUri="">
|
||||||
<#if (rangeUri?contains("Authorship") && domainUri?contains("IAO_0000030")) || (rangeUri?contains("Editorship") && domainUri?contains("IAO_0000030"))|| rangeUri?contains("URL") || label == "hasResearchArea">
|
<#if (rangeUri?contains("Authorship") && domainUri?contains("IAO_0000030")) || (rangeUri?contains("Editorship") && domainUri?contains("IAO_0000030"))|| rangeUri?contains("URL") || propertyLocalName == "hasResearchArea">
|
||||||
<a class="add-${propertyLocalName}" href="${url}" title="${i18n().manage_list_of} ${label?lower_case}">
|
<a class="add-${propertyLocalName}" href="${url}" title="${i18n().manage_list_of} ${label?lower_case}">
|
||||||
<img class="add-individual" src="${urls.images}/individual/manage-icon.png" alt="${i18n().manage}" /></a>
|
<img class="add-individual" src="${urls.images}/individual/manage-icon.png" alt="${i18n().manage}" /></a>
|
||||||
<#else>
|
<#else>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue