本文整理汇总了Java中org.apache.jena.sparql.engine.http.QueryExceptionHTTP类的典型用法代码示例。如果您正苦于以下问题:Java QueryExceptionHTTP类的具体用法?Java QueryExceptionHTTP怎么用?Java QueryExceptionHTTP使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
QueryExceptionHTTP类属于org.apache.jena.sparql.engine.http包,在下文中一共展示了QueryExceptionHTTP类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isPerson
import org.apache.jena.sparql.engine.http.QueryExceptionHTTP; //导入依赖的package包/类
private boolean isPerson(String uri){
if(personTypes.isEmpty()){
return true;
} else {
//g et types of URI
Set<String> types = new HashSet<>();
try {
String query = "SELECT ?type WHERE {<" + uri + "> a ?type.}";
try(QueryExecution qe = qef.createQueryExecution(query)) {
ResultSet rs = qe.execSelect();
while(rs.hasNext()){
types.add(rs.next().getResource("type").getURI());
}
}
} catch (Exception e) {
int code = ((QueryExceptionHTTP)e.getCause()).getResponseCode();
logger.warn("SPARQL query execution failed: " + code + " - " + HttpSC.getCode(code).getMessage());
}
// check for overlap between types of entity and person types
return !Sets.intersection(personTypes, types).isEmpty();
}
}
示例2: isPerson
import org.apache.jena.sparql.engine.http.QueryExceptionHTTP; //导入依赖的package包/类
private boolean isPerson(String uri) {
if (personTypes.isEmpty()) {
return true;
} else {
// g et types of URI
Set<String> types = new HashSet<>();
try {
String query = "SELECT ?type WHERE {<" + uri + "> a ?type.}";
try (QueryExecution qe = qef.createQueryExecution(query)) {
ResultSet rs = qe.execSelect();
while (rs.hasNext()) {
types.add(rs.next().getResource("type").getURI());
}
}
} catch (Exception e) {
int code = ((QueryExceptionHTTP) e.getCause()).getResponseCode();
logger.warn("SPARQL query execution failed: " + code + " - " + HttpSC.getCode(code).getMessage());
}
// check for overlap between types of entity and person types
return !Sets.intersection(personTypes, types).isEmpty();
}
}
示例3: fuseki_stop_start
import org.apache.jena.sparql.engine.http.QueryExceptionHTTP; //导入依赖的package包/类
@Test
public void fuseki_stop_start() {
PatchLogServer patchLogServer = patchLogServer();
FusekiServer server1 = fuseki1();
try {
server1.stop();
RDFConnection conn1 = RDFConnectionFactory.connect("http://localhost:"+F1_PORT+ds1) ;
QueryExecution qExec = conn1.query("ASK{}");
try { qExec.execAsk(); fail(); } catch(QueryExceptionHTTP ex) {}
// Restart, same port.
server1 = fuseki1();
QueryExecution qExec1 = conn1.query("ASK{}");
qExec1.execAsk();
} finally {
server1.stop();
patchLogServer.stop();
}
}
示例4: toResponse
import org.apache.jena.sparql.engine.http.QueryExceptionHTTP; //导入依赖的package包/类
@Override
public Response toResponse(QueryExceptionHTTP ex)
{
if (ex.getResponseCode() > 0)
return com.atomgraph.core.model.impl.Response.fromRequest(getRequest()).
getResponseBuilder(toResource(ex, Response.Status.fromStatusCode(ex.getResponseCode()),
ResourceFactory.createResource("http://www.w3.org/2011/http-statusCodes#InternalServerError")).
getModel(), getVariants()).
status(ex.getResponseCode()).
build();
else
return com.atomgraph.core.model.impl.Response.fromRequest(getRequest()).
getResponseBuilder(toResource(ex, Response.Status.INTERNAL_SERVER_ERROR,
ResourceFactory.createResource("http://www.w3.org/2011/http-statusCodes#InternalServerError")).
getModel(), getVariants()).
status(Response.Status.INTERNAL_SERVER_ERROR).
build();
}
示例5: executeQuery
import org.apache.jena.sparql.engine.http.QueryExceptionHTTP; //导入依赖的package包/类
private void executeQuery() throws Exception {
query = getSparqlQuery(offset, limit);
final AtomicInteger found = new AtomicInteger();
Exception currentException = null;
for (int i = 0; i <= retry; i++) {
try {
getSparqlClient().select(query, new ResultSetConsumer() {
public void useResultSet(ResultSet rs) {
while (rs.hasNext()) {
currentResearcherProcessors.add(getResearcherProcessor(rs.next()));
found.incrementAndGet();
}
}
});
offset += found.get();
return;
}
catch (QueryExceptionHTTP e) {
currentException = e;
LOG.log(Level.WARNING, "Try #" + i, e);
}
}
if (currentException != null) {
throw currentException;
}
}
示例6: getLabelFromKnowledgebase
import org.apache.jena.sparql.engine.http.QueryExceptionHTTP; //导入依赖的package包/类
private String getLabelFromKnowledgebase(String iri){
ParameterizedSparqlString query = new ParameterizedSparqlString(
"SELECT ?label WHERE {" +
"?s ?p1 ?o ." +
"optional {" +
" ?s ?p ?label. " +
" FILTER (LANGMATCHES(LANG(?label),'" + language + "' ))" +
" }" +
"optional {" +
" ?s ?p ?label" +
" }" +
"} " +
"ORDER BY DESC(?label) LIMIT 1");
query.setIri("s", iri);
// for each label property
for (String labelProperty : labelProperties) {
query.setIri("p", labelProperty);
try (QueryExecution qe = qef.createQueryExecution(query.toString())){
ResultSet rs = qe.execSelect();
if(rs.hasNext()){
return rs.next().getLiteral("label").getLexicalForm();
}
} catch (Exception e) {
e.printStackTrace();
int code = -1;
//cached exception is wrapped in a RuntimeException
if(e.getCause() instanceof QueryExceptionHTTP){
code = ((QueryExceptionHTTP)e.getCause()).getResponseCode();
} else if(e instanceof QueryExceptionHTTP){
code = ((QueryExceptionHTTP) e).getResponseCode();
}
logger.warn("Getting label of " + iri + " from SPARQL endpoint failed: " + code + " - " + HttpSC.getCode(code).getMessage());
}
}
return null;
}
示例7: getLabelFromKnowledgebase
import org.apache.jena.sparql.engine.http.QueryExceptionHTTP; //导入依赖的package包/类
private String getLabelFromKnowledgebase(String iri) {
ParameterizedSparqlString query = new ParameterizedSparqlString("SELECT ?label WHERE {" + "?s ?p1 ?o ."
+ "optional {" + " ?s ?p ?label. " + " FILTER (LANGMATCHES(LANG(?label),'" + language + "' ))"
+ " }" + "optional {" + " ?s ?p ?label" + " }" + "} " + "ORDER BY DESC(?label) LIMIT 1");
query.setIri("s", iri);
// for each label property
for (String labelProperty : labelProperties) {
query.setIri("p", labelProperty);
try (QueryExecution qe = qef.createQueryExecution(query.toString())) {
ResultSet rs = qe.execSelect();
if (rs.hasNext()) {
return rs.next().getLiteral("label").getLexicalForm();
}
} catch (Exception e) {
e.printStackTrace();
int code = -1;
// cached exception is wrapped in a RuntimeException
if (e.getCause() instanceof QueryExceptionHTTP) {
code = ((QueryExceptionHTTP) e.getCause()).getResponseCode();
} else if (e instanceof QueryExceptionHTTP) {
code = ((QueryExceptionHTTP) e).getResponseCode();
}
logger.warn("Getting label of " + iri + " from SPARQL endpoint failed: " + code + " - "
+ HttpSC.getCode(code).getMessage());
}
}
return null;
}
示例8: getLabelFromKnowledgebase
import org.apache.jena.sparql.engine.http.QueryExceptionHTTP; //导入依赖的package包/类
private String getLabelFromKnowledgebase(String iri) {
ParameterizedSparqlString query = new ParameterizedSparqlString("SELECT ?label WHERE {" + "?s ?p1 ?o ."
+ "optional {" + " ?s ?p ?label. " + " FILTER (LANGMATCHES(LANG(?label),'" + language + "' ))"
+ " }" + "optional {" + " ?s ?p ?label" + " }" + "} " + "ORDER BY DESC(?label) LIMIT 1");
query.setIri("s", iri);
// for each label property
for (String labelProperty : labelProperties) {
query.setIri("p", labelProperty);
try (QueryExecution qe = qef.createQueryExecution(query.toString())) {
ResultSet rs = qe.execSelect();
if (rs.hasNext()) {
return rs.next().getLiteral("label").getLexicalForm();
}
} catch (Exception e) {
//e.printStackTrace();
int code = -1;
// cached exception is wrapped in a RuntimeException
if (e.getCause() instanceof QueryExceptionHTTP) {
code = ((QueryExceptionHTTP) e.getCause()).getResponseCode();
} else if (e instanceof QueryExceptionHTTP) {
code = ((QueryExceptionHTTP) e).getResponseCode();
}
logger.debug("Getting label of " + iri + " from SPARQL endpoint failed: " + code + " - "
+ HttpSC.getCode(code).getMessage());
}
}
return null;
}
示例9: fuseki_stop
import org.apache.jena.sparql.engine.http.QueryExceptionHTTP; //导入依赖的package包/类
@Test(expected=QueryExceptionHTTP.class)
public void fuseki_stop() {
PatchLogServer patchLogServer = patchLogServer();
FusekiServer server1 = fuseki1();
try {
server1.stop();
RDFConnection conn1 = RDFConnectionFactory.connect("http://localhost:"+F1_PORT+ds1) ;
QueryExecution qExec = conn1.query("ASK{}");
qExec.execAsk();
} finally {
patchLogServer.stop();
}
}
示例10: categorizeHttpError
import org.apache.jena.sparql.engine.http.QueryExceptionHTTP; //导入依赖的package包/类
/**
* Categorizes a HTTP error based on the status code
* <p>
* Where possible this will use specific error categories such as
* {@link #AUTHENTICATION} or {@link #HTTP_NOT_FOUND} however many possible
* HTTP status codes are not specifically categorized and will be bucketed
* into {@link #HTTP_CLIENT_ERROR} or {@link #HTTP_SERVER_ERROR} as
* appropriate.
* </p>
*
* @param status
* Status Code
* @return Most appropriate error category
*/
public static int categorizeHttpError(int status) {
// Specific categories
switch (status) {
case -1:
case QueryExceptionHTTP.noResponseCode:
// Unknown HTTP status so categorize as an Execution error
return EXECUTION;
case HttpStatus.SC_UNAUTHORIZED:
case HttpStatus.SC_PAYMENT_REQUIRED:
case HttpStatus.SC_FORBIDDEN:
case HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED:
case 419: // 419 - Authentication Timeout - Non-standard
case 440: // 440 - Login Timeout - Non-standard
// These are all authentication specific errors
return AUTHENTICATION;
case HttpStatus.SC_REQUEST_TIMEOUT:
// Request timed out
return TIMEOUT;
case HttpStatus.SC_NOT_FOUND:
case HttpStatus.SC_GONE:
// Resource not found
return HTTP_NOT_FOUND;
}
// General categories
if (status >= 400 && status < 500) {
return HTTP_CLIENT_ERROR;
} else if (status >= 500 && status < 600) {
return HTTP_SERVER_ERROR;
} else {
// Assume some other execution error
return EXECUTION;
}
}
示例11: executeSingleTest
import org.apache.jena.sparql.engine.http.QueryExceptionHTTP; //导入依赖的package包/类
@Override
protected Collection<TestCaseResult> executeSingleTest(TestSource testSource, TestCase testCase) {
TestCaseResultStatus status = TestCaseResultStatus.Error;
try (QueryExecution qe = testSource.getExecutionFactory().createQueryExecution(queryGenerationFactory.getSparqlQuery(testCase))) {
boolean fail = qe.execAsk();
if (fail) {
status = TestCaseResultStatus.Fail;
} else {
status = TestCaseResultStatus.Success;
}
} catch (QueryExceptionHTTP e) {
// No need to throw exception here, class supports status
if (SparqlUtils.checkStatusForTimeout(e)) {
status = TestCaseResultStatus.Timeout;
} else {
status = TestCaseResultStatus.Error;
}
}
return Collections.singletonList(new StatusTestCaseResultImpl(testCase, status));
}
示例12: executeSingleTest
import org.apache.jena.sparql.engine.http.QueryExceptionHTTP; //导入依赖的package包/类
@Override
protected Collection<TestCaseResult> executeSingleTest(TestSource testSource, TestCase testCase) throws TestCaseExecutionException {
Collection<TestCaseResult> testCaseResults = new ArrayList<>();
try (QueryExecution qe = testSource.getExecutionFactory().createQueryExecution(queryGenerationFactory.getSparqlQuery(testCase)))
{
qe.execSelect().forEachRemaining( qs -> {
RDFNode focusNode = qs.get("this");
String message = testCase.getResultMessage();
if (qs.contains("message")) {
message = qs.get("message").toString();
}
RLOGLevel logLevel = testCase.getLogLevel();
testCaseResults.add(new ShaclLiteTestCaseResultImpl(testCase.getTestURI(), logLevel, message, focusNode));
});
} catch (QueryExceptionHTTP e) {
checkQueryResultStatus(e);
}
return testCaseResults;
}
示例13: checkQueryResultStatus
import org.apache.jena.sparql.engine.http.QueryExceptionHTTP; //导入依赖的package包/类
protected void checkQueryResultStatus(QueryExceptionHTTP e) throws TestCaseExecutionException {
if (SparqlUtils.checkStatusForTimeout(e)) {
throw new TestCaseExecutionException(TestCaseResultStatus.Timeout, e);
} else {
throw new TestCaseExecutionException(TestCaseResultStatus.Error, e);
}
}
示例14: checkStatusForTimeout
import org.apache.jena.sparql.engine.http.QueryExceptionHTTP; //导入依赖的package包/类
public static boolean checkStatusForTimeout(QueryExceptionHTTP e) {
int httpCode = e.getResponseCode();
// 408,504,524 timeout codes from http://en.wikipedia.org/wiki/List_of_HTTP_status_codes
return httpCode == 408 || httpCode == 504 || httpCode == 524;
}