Thankyou very much for your response, sorry about the double post, a
moderator told me that the post was most likely not sent as at the time I
was not yet on the user group list, so I thought I had better send it again.

Basic authentication is indeed configured for my sesame instance, as I
cannot connect without basic auth, I have tested using apache http client
and also openrdf sesame libs, and can connect using preemptive basic auth
over https successfully.

Anyway, I have stumbled across a work-around, although I don't think its
intended... If I include the basic auth parameters in the url, I can avoid
using an HttpAuthenticator, and get a connection. e.g...

// returns a result set correctly
QueryExecution queryExecution = QueryExecutionFactory.sparqlService(
                    "https://*examples-repo:XXX*@
repo-eh-01.sparqlr.com/repositories/examples-repo", query
            );

// returns a 401 unauthorised
HttpAuthenticator authenticator = new PreemptiveBasicAuthenticator(
               new ScopedAuthenticator(new URI("
https://repo-eh-01.sparqlr.com/repositories/examples-repo";), "
*examples-repo*", "*XXX*".toCharArray())
       );
       QueryExecution queryExecution = QueryExecutionFactory.sparqlService("
https://repo-eh-01.sparqlr.com/repositories/examples-repo";, query,
authenticator);

...... But I would much rather use the HttpAuthenticator, as there is no
guarantee that my 'hack' will work in later releases!!

Any ideas what I am doing wrong?

Regards,
Charles.





On 16 January 2014 14:25, Rob Vesse <[email protected]> wrote:

> 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