Describe request with stardog API

Hello

For my project i need to use a describe request called from my server (spring with stardog api).
My request is :

DESCRIBE ?x WHERE {
  ?x rdf:type myOntology:human .
}

If i use these request in Stardog web interface (Stardog 5.3.1) i have a result
But the same request from my server doesn't work and i have an error :

ERROR org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/].[dispatcherServlet] - Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is com.complexible.stardog.security.ResourceExistsException: Unsupported Accept for query type] with root cause
com.complexible.stardog.security.ResourceExistsException: Unsupported Accept for query type
	at com.complexible.stardog.protocols.http.client.BaseHttpClient.checkResponseCode(BaseHttpClient.java:530)
	at com.complexible.stardog.protocols.http.client.BaseHttpClient.execute(BaseHttpClient.java:363)

How can i allow these kind of request ?
thanks for your answers

Hello and welcome!

Can you show us how you're making the request from the server (Java API, HTTP, etc) and if you're adding an Accept header in any way? The server is expecting to be asked for an RDF format and it doesn't appear to be getting that, whether it's something explicitly set or something being set by whichever client is generating the call.

String request = "DESCRIBE ?x WHERE {\n" + 
				"  ?x rdf:type myOntology:human .\n" + 
				"}";
String[] resultat = executeRequest(request);


private synchronized String[] executeRequest(String request) throws TupleQueryResultHandlerException, QueryEvaluationException, 
	UnsupportedQueryResultFormatException, IOException, StardogException {
	
		createAdminConnection(database.ontoMedirad);
		logger.debug("Request "+request);
		
		SelectQuery aQuery = starDogConnection.select(request);
		
		TupleQueryResult aResult=null; ByteArrayOutputStream out=null;
		
		aResult = aQuery.execute();
		out = new ByteArrayOutputStream();
		QueryResultIO.writeTuple(aResult, TupleQueryResultFormat.CSV, out);
		String[] resultats = out.toString().split("\n");
		
		if (aResult!=null) {aResult.close();}
		return resultats;
	}

	public void createAdminConnection(database db, boolean paramreasoner) {									// Main method to open a connection to a Stardog database
		if (pacsUrl==null) {pacsUrl = Application.pacsUrl ;}
		if (starDogUrl==null) {starDogUrl = Application.starDogUrl ;}		
		logger.debug("Creation of the StarDog connection (Database : "+db.toString()+") at "+starDogUrl);
		ConnectionConfiguration connectionConfig = ConnectionConfiguration									// Configuration of the connection
				.to(db.toString())																			// Select Database (from the enumeration)
				.server(starDogUrl)																			// StarDog URL 
				.credentials(username, password)															// Login and Pasword of Stardog
				.reasoning(paramreasoner);																	// Will it use reasoning (boollean)

		logger.debug("StarDog connection (reasoning : "+ConnectionConfiguration.REASONING_ENABLED.toString()+")"); 

		ConnectionPool connectionPool = createConnectionPool(connectionConfig);								// Create the Stardog connection 
		starDogConnection = connectionPool.obtain();														// Return the Stardog connection as a java Object
		logger.debug("Sucessfully created the StarDog connection (Database : "+db.toString()+")");
	}

Hi,

The issue here is that DESCRIBE is not a select query, so executing it as a SelectQuery is returning this error. What you want is a GraphQuery, since the end result will be an RDF graph:

final String aQuery = "DESCRIBE ?x WHERE {\n" +
		                      "  ?x rdf:type myOntology:human .\n" +
		                      "}";

		try (Connection c = ConnectionConfiguration.to("myDb").server("http://localhost:5820").credentials("admin", "admin").connect();
		     GraphQueryResult r = c.graph(aQuery).execute()) {
			r.toGraph().forEach(System.out::println);
		}

Yes it works
Thank you very much

I was able to make many requests, and i used the pragma describe.strategy bidirectional, lie that
DESCRIBE http://medicis.univ-rennes1.fr/ontologies/ontospm/OntoMEDIRAD.owl#Patient_d20baee9-39b4-47fc-91c9-ad6a998869b5
But in some cases i receive an error :
org.openrdf.query.QueryEvaluationException: LongHashSet can't handle long element which equal to 0
at com.complexible.stardog.protocols.http.client.BaseHttpClient.checkResponseCode(BaseHttpClient.java:491)
at com.complexible.stardog.protocols.http.client.BaseHttpClient.execute(BaseHttpClient.java:363)
at com.complexible.stardog.protocols.http.client.HttpClientImpl.graph(HttpClientImpl.java:292)
at com.complexible.stardog.protocols.http.client.HttpConnection._graph(HttpConnection.java:158)
at com.complexible.stardog.api.impl.AbstractConnection.executeGraph(AbstractConnection.java:450)
at com.complexible.stardog.api.impl.GraphQueryImpl.execute(GraphQueryImpl.java:33)
at com.complexible.stardog.api.impl.GraphQueryImpl.execute(GraphQueryImpl.java:23)
at repository.RequestBuilder.describeRequest(RequestBuilder.java:298)

But the same request works in StarDog

Do you know what is my error ?

Can you post the entire query that you are running, #pragma included? And where are you seeing the error happening?

A request : #pragma describe.strategy bidirectional
DESCRIBE http://medicis.univ-rennes1.fr/ontologies/ontospm/OntoMEDIRAD.owl#age_of_patient_undergoing_medical_procedure_ce9073ef-44de-4452-a317-c21161854831

I see then in my java console, these requests are executed by my java server (and result is sent in Json to a HTML/Java script page )