2

I'm trying to use federated queries with Jena via a Fuseki endpoint. With the SERVICE keyword in my SPARQL query, I'm connecting to a Stardog endpoint. As it's a secured URL, the endpoint is specified as follows: http://admin:admin@url. As this is not secure, Jena shows the following message:

Code: 36/HAS_PASSWORD in USER: Including passwords in URIs is deprecated.

According to the docs, you can specify srv:queryAuthUser and srv:queryAuthPwd for the credentials. Is there any way to do this directly in the SPARQL query? Or, can it be configured in Fuseki (ttl file)?

EDIT

When I use @RobV's solution, the service context doesn't seem to be picked up. This is what the context looks like:

symbol:http://jena.hpl.hp.com/ARQ#regexImpl = symbol:http://jena.hpl.hp.com/ARQ#javaRegex
symbol:http://jena.hpl.hp.com/ARQ#constantBNodeLabels = true
symbol:http://jena.hpl.hp.com/ARQ#strictGraph = false
symbol:http://jena.hpl.hp.com/ARQ#strictSPARQL = false
symbol:http://jena.hpl.hp.com/ARQ#stageGenerator = com.hp.hpl.jena.tdb.solver.StageGeneratorDirectTDB@6f2dd58d
symbol:http://jena.hpl.hp.com/ARQ#enablePropertyFunctions = true
symbol:http://jena.hpl.hp.com/ARQ#romanNumerals = false
symbol:http://jena.hpl.hp.com/ARQ#optFilterPlacement = false
symbol:http://jena.hpl.hp.com/ARQ#registryPropertyFunctions = com.hp.hpl.jena.sparql.pfunction.PropertyFunctionRegistry@6f05ca41
symbol:http://jena.hpl.hp.com/ARQ/system#opExecutorFactory = com.hp.hpl.jena.tdb.solver.OpExecutorTDB$1@2a1f5501

When I leave the Fuseki config as is, and add the service context in my business layer, the service context does seem to be added:

symbol:http://jena.hpl.hp.com/Service#serviceContext = {http://host:5820/db/query=symbol:http://jena.hpl.hp.com/Service#queryAuthPwd = usr
symbol:http://jena.hpl.hp.com/Service#queryAuthUser = pwd}

Eitherway, I'm still getting an unauthorized message when I execute a federated query.

Stanislav Kralin
  • 11,070
  • 4
  • 35
  • 58
tstorms
  • 4,941
  • 1
  • 25
  • 47

1 Answers1

2

No there is no way to do this directly in the SPARQL query

In theory you could use the ja:context property in the Fuseki configuration file to specify context properties. However in practise this does not work because a service context is a nested context and the assembler does not support nested contexts currently.

However what you can do instead is to to use the ja:loadClass mechanism to load a custom class that you add to the class path which does the necessary static initialisation e.g.

[] rdf:type fuseki:Server ;
   ja:loadClass "com.example.YourInitializer" ;
   fuseki:services (
     # Whatever services you are defining
   ) .

Note that you MUST associate your initialiser with the subject that represents the fuseki:Server instance otherwise the ja:loadClass triple may not get processed.

And then:

package org.apache.jena.playground;

import java.util.HashMap;
import java.util.Map;

import com.hp.hpl.jena.query.ARQ;
import com.hp.hpl.jena.sparql.engine.http.Service;
import com.hp.hpl.jena.sparql.util.Context;

public class StardogInitializer {

    public static void init() {
        // Prepare Stardog specific context
        Context stardogContext = new Context();
        stardogContext.set(Service.queryAuthUser, "admin");
        stardogContext.set(Service.queryAuthPwd, "admin");

        // Associate context with your endpoint URL
        Map<String, Context> serviceContexts = new HashMap<>();
        // temp here is the name of the Stardog database to be queried
        serviceContexts.put("http://localhost:5820/temp/query", stardogContext);

        // Associate service contexts with the global ARQ context
        ARQ.getContext().set(Service.serviceContext, serviceContexts);
    }
}

Note that the method needs to be static and needs to be called init() in order for Fuseki to invoke it.

With this revised setup I was able to successfully query my local Stardog server.

RobV
  • 28,022
  • 11
  • 77
  • 119
  • I'm still getting the message _Problem accessing /ds/query. Reason:Unauthorized_. Maybe there's an error in my [Fuseki config file](https://gist.github.com/TimmyStorms/bc2014756dcec8b6b814). I've verified that the custom initializer gets loaded. Bear in mind that I would like to query TDB and Stardog simultaneously with the use of SERVICE. – tstorms Mar 03 '15 at 13:30
  • Can you try explicitly associating the `ja:loadClass` with the `fuseki:Server` instance as otherwise it looks like the `ja:loadClass` statement may get ignored – RobV Mar 05 '15 at 10:16
  • @tstorms Did a bit more digging and figured out exactly what you need to do to get this to work successfully. See my updated answer which works for me with my local Stardog and Fuseki setup – RobV Mar 05 '15 at 10:37
  • I appreciate all your digging, but sadly I'm still getting the unauthorized exception. Triple-checked everything, URL's are correct, the stardog endpoint is queryable separately with the same credentials. Maybe there's a Stardog setting that needs to be changed? Any pointers still very welcome. – tstorms Mar 05 '15 at 10:50
  • Updated the [fuseki config](https://gist.github.com/TimmyStorms/bc2014756dcec8b6b814) as well. – tstorms Mar 05 '15 at 10:58
  • Your configuration looks fine to me, see [this gist](https://gist.github.com/rvesse/9ac444a67b331744c5de) which is my exact config that worked for me. The Fuseki config is simply the `config-tdb.ttl` example modified to add the `ja:loadClass` statement and use the in-memory TDB location – RobV Mar 05 '15 at 12:34
  • My configuration is almost identical but to no avail. The main difference is that the Stardog instance runs on amazon cloud. But I don't see why that should be a problem. Getting pretty frustrated here... – tstorms Mar 05 '15 at 13:13
  • 1
    I've created a minimal project with jena and fuseki on the classpath. It works now when I use the latest library versions (2.12.1 and 1.1.1 respectively)! I will be very difficult to upgrade the actual project but I'll give it a shot. Thanks for all your help! – tstorms Mar 05 '15 at 14:25