Dear Jena Users,

I am trying to use Jena ARQ with a PreemptiveBasicAuthenticator, without 
success, can anyone help?

Im always getting a 401, although the same request through a rest client, or 
using openrdf works. Could it be something to do with apache http client and 
having to set an AuthScope?

Here is my code…

package uk.co.bubobubo.examples;

import com.hp.hpl.jena.query.Query;
import com.hp.hpl.jena.query.QueryExecution;
import com.hp.hpl.jena.query.QueryExecutionFactory;
import com.hp.hpl.jena.query.QueryFactory;
import com.hp.hpl.jena.query.ResultSet;
import org.apache.jena.atlas.web.auth.HttpAuthenticator;
import org.apache.jena.atlas.web.auth.PreemptiveBasicAuthenticator;
import org.apache.jena.atlas.web.auth.ScopedAuthenticator;

import java.net.URI;

public class JenaConnect {

   private final static String SPARQLR_ENDPOINT = 
"https://repo-eh-01.sparqlr.com/repositories/examples-repo";;
   private final static String SPARQLR_USERNAME = "examples-repo";
   private final static String SPARQLR_PASSWORD = “XXX";

   public static void main(String[] args) throws Exception {

       String localEndpoint = 
"http://localhost:8080/openrdf-sesame/repositories/jena-connect";;

       String queryString = "SELECT * WHERE {?s ?p ?o}";
       Query query = QueryFactory.create(queryString);
       HttpAuthenticator authenticator = new PreemptiveBasicAuthenticator(
               new ScopedAuthenticator(new URI(SPARQLR_ENDPOINT), 
SPARQLR_USERNAME, SPARQLR_PASSWORD.toCharArray())
       );
       QueryExecution queryExecution = 
QueryExecutionFactory.sparqlService(SPARQLR_ENDPOINT, query, authenticator);
       try {
           ResultSet results = queryExecution.execSelect();
           int i = 0;
           while(results.hasNext()) {
               results.next();
               i++;
           }
           System.out.println(i);
       } finally {
           queryExecution.close();
       }
   }
}



Reply via email to