Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/393.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java HttpException:在远程端点上运行SPARQL查询时为500_Java_Sparql_Jena_Endpoint - Fatal编程技术网

Java HttpException:在远程端点上运行SPARQL查询时为500

Java HttpException:在远程端点上运行SPARQL查询时为500,java,sparql,jena,endpoint,Java,Sparql,Jena,Endpoint,我对语义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

我对语义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();
    }
}
}
当我在端点
http://localhost:8890/sparql
,运行正常


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

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


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

我对语义网非常陌生。我不明白你说的话。为什么会给出HttpException?因为您正在查询的系统正在返回HTTP 500错误。您显示的代码只是简单地报告了这一点。
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)