【问题标题】:HttpException: 500 when running a SPARQL query on remote endpointHttpException:在远程端点上运行 SPARQL 查询时出现 500
【发布时间】:2015-03-17 20:37:30
【问题描述】:

我对语义 Web 编程非常陌生。我正在学习如何编写 Java 代码以使用 Jena API 查询 SPARQL 端点。

这是我的 Java 代码:

public class TestJena 
{
public static void main (String[] args)
{
    String queryString = "prefix owl: <http://www.w3.org/2002/07/owl#>" +
                        "select ?class where { " + 
                        " ?class a owl:Class } ";
    String endpoint = "http://localhost:8890/sparql";

    Query query = QueryFactory.create(queryString, Syntax.syntaxARQ);

    query.setOffset(1);

    QueryExecution qe = QueryExecutionFactory.sparqlService(endpoint, query);

    try
    {
        ResultSet resultSet = qe.execSelect();
        StringBuffer results = new StringBuffer();
        List<String> columnNames = resultSet.getResultVars();

        while(resultSet.hasNext())
        {
            QuerySolution solution = resultSet.next();

            for(String var : columnNames)
            {
                results.append(var + ":");

                if (solution.get(var) == null)
                    results.append("{null}");
                else if (solution.get(var).isLiteral())
                    results.append(solution.getLiteral(var).toString());
                else
                    results.append(solution.getResource(var).getURI());
                results.append('\n');
            }
            results.append("----------\n");
        }
        System.out.print("Results are : "+results.toString());
    }
    finally
    {
        qe.close();
    }
}
}

当我运行查询时,我得到以下异常:

Exception in thread "main" HttpException: 500
at com.hp.hpl.jena.sparql.engine.http.HttpQuery.rewrap(HttpQuery.java:414)
at com.hp.hpl.jena.sparql.engine.http.HttpQuery.execGet(HttpQuery.java:358)
at com.hp.hpl.jena.sparql.engine.http.HttpQuery.exec(HttpQuery.java:295)
at com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP.execResultSetInner(QueryEngineHTTP.java:346)
at com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP.execSelect(QueryEngineHTTP.java:338)
at com.TestJena.example.TestJena.main(TestJena.java:31)

当我在端点http://localhost:8890/sparql 上运行上述查询时,它运行良好。

谁能告诉我问题出在哪里?为什么会抛出 HttpException: 500

【问题讨论】:

    标签: java sparql jena endpoint


    【解决方案1】:

    端点返回 HTTP 错误代码 500(内部服务器故障)。客户端代码看起来不错,可能运行的是旧版本的 Jena,因为它通常会打印更多详细信息(如果远程端提供任何信息)。

    当您使用http://localhost:8890/sparql 时,它可能是一个 HTML 表单,而不是 SPARQL 端点。它可能需要额外的参数 - 请参阅该服务器的文档。

    【讨论】:

    • 我是语义网的新手。我不明白你说了什么。为什么会出现 HttpException?
    • 因为您正在查询的系统正在返回 HTTP 500 错误。您显示的代码只是报告这一点。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多