org.apache.jena.sparql.engine.http.QueryExceptionHTTP Java Examples

The following examples show how to use org.apache.jena.sparql.engine.http.QueryExceptionHTTP. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestDeltaFusekiBad.java    From rdf-delta with Apache License 2.0 6 votes vote down vote up
@Test
public void fuseki_stop_start() {
    DeltaServer deltaServer = deltaServer();
    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(Start.RESTART);
        QueryExecution qExec1 = conn1.query("ASK{}");
        qExec1.execAsk();
    } finally {
        server1.stop();
        deltaServer.stop();
    }
}
 
Example #2
Source File: QueryExceptionHTTPMapper.java    From Processor with Apache License 2.0 6 votes vote down vote up
@Override
public Response toResponse(QueryExceptionHTTP ex)
{        
    if (ex.getResponseCode() > 0)
        return getResponseBuilder(DatasetFactory.create(toResource(ex, Response.Status.fromStatusCode(ex.getResponseCode()),
                    ResourceFactory.createResource("http://www.w3.org/2011/http-statusCodes#InternalServerError")).
                getModel())).
            status(ex.getResponseCode()).
            build();
    else
        return getResponseBuilder(DatasetFactory.create(toResource(ex, Response.Status.INTERNAL_SERVER_ERROR,
                    ResourceFactory.createResource("http://www.w3.org/2011/http-statusCodes#InternalServerError")).
                getModel())).
            status(Response.Status.INTERNAL_SERVER_ERROR).
            build();
}
 
Example #3
Source File: TestDeltaFusekiBad.java    From rdf-delta with Apache License 2.0 5 votes vote down vote up
@Test(expected=QueryExceptionHTTP.class)
public void fuseki_stop() {
    DeltaServer deltaServer = deltaServer(CLEAN);
    FusekiServer server1 = fuseki1(CLEAN);
    try {
        server1.stop();
        RDFConnection conn1 = RDFConnectionFactory.connect("http://localhost:"+F1_PORT+ds1) ;
        QueryExecution qExec = conn1.query("ASK{}");
        qExec.execAsk();
    } finally {
        deltaServer.stop();
    }
}
 
Example #4
Source File: StatusTestExecutor.java    From RDFUnit with Apache License 2.0 5 votes vote down vote up
@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));
}
 
Example #5
Source File: ShaclSimpleTestExecutor.java    From RDFUnit with Apache License 2.0 5 votes vote down vote up
@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 = testCase.getFocusNode(qs);
            assert(focusNode != null);

            String message = testCase.getResultMessage();
            if (qs.contains("message")) {
                message = qs.get("message").toString();
            }
            RLOGLevel logLevel = testCase.getLogLevel();

            testCaseResults.add(new ShaclLiteTestCaseResultImpl(testCase.getElement(), logLevel, message, focusNode));
        });
    } catch (QueryExceptionHTTP e) {
        checkQueryResultStatus(e);
    }

    return testCaseResults;

}
 
Example #6
Source File: ShaclSimpleTestExecutor.java    From RDFUnit with Apache License 2.0 5 votes vote down vote up
protected void checkQueryResultStatus(QueryExceptionHTTP e) throws TestCaseExecutionException {
    if (SparqlUtils.checkStatusForTimeout(e)) {
        throw new TestCaseExecutionException(TestCaseResultStatus.Timeout, e);
    } else {
        throw new TestCaseExecutionException(TestCaseResultStatus.Error, e);
    }
}
 
Example #7
Source File: SparqlUtils.java    From RDFUnit with Apache License 2.0 4 votes vote down vote up
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;
}