HttpException:500运行在远程端点的SPARQL查询时 [英] HttpException: 500 when running a SPARQL query on remote endpoint

查看:366
本文介绍了HttpException:500运行在远程端点的SPARQL查询时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很新的语义Web编程。我正在学习如何编写Java code。使用耶拿API来查询SPARQL端点。

I'm very new to Semantic Web programming. I'm learning about how to write Java code to query a SPARQL endpoint using the Jena API.

下面是我的Java code:

Here's my Java code:

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();
    }
}
}

当我运行查询,我得到了以下情况除外:

When I run the query, I get the following exceptions:

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://本地主机:8890 / SPARQL ,它运行良好。

When I run the above query at the endpoint http://localhost:8890/sparql, it runs fine.

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

Can anyone tell me where the problem is? Why is it throwing a HttpException: 500 ?

谢谢!

推荐答案

端点将返回HTTP错误code 500(内部服务器故障)。客户端code看起来蛮好的,也许运行旧版本耶拿,因为它通常会打印更多详细资料(如果远端提供任何)。

The endpoint is returning HTTP error code 500 (internal server failure). The client code looks just fine, maybe running an old version of Jena because it usually prints more details (if the remote end provides any).

当您使用的http://本地主机:8890 / SPARQL 是presumably HTML表单,不是SPARQL端点。这可能需要额外的参数 - 见的文档该服务器

When you use http://localhost:8890/sparql that is presumably an HTML form, not the SPARQL endpoint. It may need additional parameters - see documentation of for that server.

这篇关于HttpException:500运行在远程端点的SPARQL查询时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆