Might be a good idea to check the proxy settings of your JVM (if a proxy is
managing your web connection).
This code should do the trick:

System.setProperty("http.proxyHost", yourProxy);
System.setProperty("http.proxyPort", yourproxyPort)

final String authUser = "yourUser";
final String authPassword = "yourPassword";
Authenticator.setDefault(
   new Authenticator() {
      public PasswordAuthentication getPasswordAuthentication() {
         return new PasswordAuthentication(
               authUser, authPassword.toCharArray());
      }
   }
);

System.setProperty("http.proxyUser", authUser);
System.setProperty("http.proxyPassword", authPassword);




On Tue, Sep 3, 2013 at 9:04 AM, Marco Neumann <[email protected]>wrote:

> make sure you can access the sparql endpoint at
> http://dbpedia.org/sparqlfrom your
> jvm.
>
> QueryExecution qexec = QueryExecutionFactory.sparqlService("
> http://dbpedia.org/sparql";, query);
>
>
>
> On Mon, Sep 2, 2013 at 9:42 PM, bocai <[email protected]> wrote:
>
> > Oh, I changed Prefix from
> > "PREFIX dbpedia: http://dbpedia.org/";
> > to
> > "PREFIX dbpedia: <http://dbpedia.org/resource/>"
> >
> > the error also changed as below:
> > HttpException: java.net.SocketException: Connection reset:
> > java.net.SocketException: Connection reset
> > at
> >
> com.hp.hpl.jena.sparql.engine.http.HttpQuery.execCommon(HttpQuery.java:529)
> > at
> com.hp.hpl.jena.sparql.engine.http.HttpQuery.execGet(HttpQuery.java:289)
> > at com.hp.hpl.jena.sparql.engine.http.HttpQuery.exec(HttpQuery.java:240)
> > at
> >
> com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP.execSelect(QueryEngineHTTP.java:302)
> > at Dbpedia.GetFromSparql.SearchSparql(GetFromSparql.java:42)
> > at Dbpedia.GetFromSparql.main(GetFromSparql.java:53)
> >
> > Caused by: java.net.SocketException: Connection reset
> > at java.net.SocketInputStream.read(SocketInputStream.java:168)
> > at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
> > at java.io.BufferedInputStream.read1(BufferedInputStream.java:258)
> > at java.io.BufferedInputStream.read(BufferedInputStream.java:317)
> > at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:687)
> > at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:632)
> > at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:652)
> > at
> >
> sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1064)
> > at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:373)
> > at
> >
> com.hp.hpl.jena.sparql.engine.http.HttpQuery.execCommon(HttpQuery.java:412)
> > ... 5 more
> >
> > How can I do ?
> >
> >
> >
> > 发件人: Marco Neumann
> > 发送时间: 2013-09-02 18:46
> > 收件人: users
> > 主题: Re: JENA API question
> > change dbpedia prefix to
> >
> >   "PREFIX dbpedia: <http://dbpedia.org/resource/>" +
> >
> >
> > On Mon, Sep 2, 2013 at 5:37 AM, bocai <[email protected]> wrote:
> >
> > > Hi,
> > > I want to access remote sparql endpoint throuth JENA API. My program
>  is
> > > below.
> > > After I ran the program, There is no record in resultset
> > > -----
> > > | p |
> > > =====
> > > -----
> > > But I visit http://dbpedia.org/sparql and ran this sparql ( select *
> > > where {?p dbpedia-owl:country dbpedia:Germany.} LIMIT 10  ) as same as
> > > sparql in my program, I can get the result i want
> > >
> > > p
> > > http://dbpedia.org/resource/%C3%96lsen
> > > http://dbpedia.org/resource/%C3%96stringen
> > > http://dbpedia.org/resource/%C3%9Cbach-Palenberg
> > > http://dbpedia.org/resource/%C3%9Cberherrn
> > > http://dbpedia.org/resource/%C3%9Cdersdorf
> > > http://dbpedia.org/resource/%C3%9Chlingen-Birkendorf
> > > http://dbpedia.org/resource/%C3%9Crzig
> > > http://dbpedia.org/resource/16_Blocks
> > > http://dbpedia.org/resource/18_%E2%80%93_Allein_unter_M%C3%A4dchen
> > > http://dbpedia.org/resource/2011_German_Grand_Prix
> > >
> > >
> > > Can you point out my error? thanks very much!
> > >
> > > public static void SearchSparql(){
> > >   try {
> > >    String queryStr =
> > >   "PREFIX dbpedia: <http://dbpedia.org/>" +
> > >   "PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>" +
> > >   "select * where {?p dbpedia-owl:country dbpedia:Germany.} LIMIT 10";
> > >
> > >             Query query = QueryFactory.create(queryStr);
> > >             QueryExecution qexec =
> QueryExecutionFactory.sparqlService("
> > > http://dbpedia.org/sparql";, query);
> > >             ((QueryEngineHTTP)qexec).addParam("timeout", "10000") ;
> > >             ResultSet rs = qexec.execSelect();
> > >             ResultSetFormatter.out(System.out, rs, query);
> > >             qexec.close();
> > >         } catch (Exception e) {
> > >             e.printStackTrace();
> > >         }
> > >
> > >  }
> > >
> > >
> > > -
> >
> >
> > ---
> > Marco Neumann
> > KONA
>
>
>
>
> --
>
>
> ---
> Marco Neumann
> KONA
>

Reply via email to