Search code examples
javasparqljenadbpediahttpexception

Error HttpException: 502 when I do query SPARQL on DBPedia


I have a problem with SPARQL when I execute a query on DBPedia.

I have this Java class:

public class example {

    public static void main(String[] args) {

        String value = "http://dbpedia.org/resource/McLeod's_Daughters_(season_8)";
        String object = "tsmgo";

        example le = new example();
        QueryExecution qe = le.queryColumn(object, value);
        ResultSet results = ResultSetFactory.copyResults( qe.execSelect() );
    }


    public QueryExecution queryColumn(String object, String string) {
        ParameterizedSparqlString qs = new ParameterizedSparqlString( "" +
                "prefix dbpediaont: <http://dbpedia.org/ontology/>\n" +
                "prefix dbpedia: <http://dbpedia.org/resource/>\n" +
                "prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n" +
                "prefix rdfs:    <http://www.w3.org/2000/01/rdf-schema#>\n" +
                "\n" +  
                "select ?ob where {\n" +
                "?subj rdfs:label ?ob\n" +
                "FILTER (contains(?ob, ?obj) )\n" +
                "}" );


        Resource risorsa = ResourceFactory.createResource(string);
        qs.setParam( "subj", risorsa );

        Literal obj2 = ResourceFactory.createPlainLiteral(object);
        qs.setParam( "obj", obj2 );

        System.out.println( qs );

        QueryExecution exec = QueryExecutionFactory.sparqlService( "http://dbpedia.org/sparql", qs.asQuery() );


                ResultSet results = ResultSetFactory.copyResults( exec.execSelect() );

                while ( results.hasNext() ) {

                    System.out.println( results.next().get( "ob" ));
                }

                // A simpler way of printing the results.
                ResultSetFormatter.out( results );

        return exec;
    }

}

When I execute this code, I get this error:

Exception in thread "main" HttpException: 502
    at com.hp.hpl.jena.sparql.engine.http.HttpQuery.execGet(HttpQuery.java:340)
    at com.hp.hpl.jena.sparql.engine.http.HttpQuery.exec(HttpQuery.java:276)
    at com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP.execSelect(QueryEngineHTTP.java:345)
    at MyPackage.example.queryColumn(example.java:176)
    at MyPackage.example.main(example.java:28)

This error is different than that reported in the response of the post

To write a query SPARQL in Java code using strstarts filter

I also tried to execute the same query with the subject "http://dbpedia.org/resource/Adriano_Celentano" and to the query is executed correctly. In particular, I get results to some queries, so do not all queries are rejected. This behavior could be given by some caching mechanism of DBPedia Why do I get this error? What am I doing wrong here?


Solution

  • If you have a problem when trying to run a query against DBpedia, one of the most important debugging techniques that you must try is printing the query, copying it, and pasting it into the web-based endpoint. In this case, if you copy and paste the following query into the endpoint, you get the following message that explains the 502 error:

    select ?ob where {
      <http://dbpedia.org/resource/McLeod's_Daughters_(season_8)> rdfs:label ?ob
      FILTER (contains(?ob, "tsmgo") ) 
    }
    

    The web-site you are currently trying to access is under maintenance at this time. We are sorry for any inconvenience this has caused.