You also asked on 
http://stackoverflow.com/questions/21137012/using-jena-arq-to-access-remote
-repo-with-basic-auth-preemptive

As I suggested there please turn on DEBUG level logging and run your test,
this will cause HttpClient to print HTTP trace information to the logs
which will allow you to see the HTTP request it makes and the response
received to determine whether authentication is even being attempted.  In
particular it would be useful to see the HTTP response from the server to
see what WWW-Authenticate header it is sending.  Is it possible that your
server does not support Basic Authentication?

Secondly have you tried without preemptive auth to see if that makes a
difference I.e. allow HttpClient to follow the standard HTTP challenge
response process and see what happens.

Thirdly are you actually accessing the server directly or does the host
shown in your query actually act as a proxy to the real server.  I suspect
not since you get 401 not a 407, but if you are getting a 407 then you
would need to use the 2 argument constructor for
PreemptiveBasicAuthenticator and set the forProxy argument to true.

Rob

On 16/01/2014 09:46, "Charles Ivie" <[email protected]> wrote:

>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