# Describe request with stardog API

**URL:** <https://community.stardog.com/t/describe-request-with-stardog-api/1822>\
**Category:** Bug\
**Created:** [August 12, 2019, 11:11am UTC](https://community.stardog.com/t/describe-request-with-stardog-api/1822 "2019-08-12T11:11:18Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![witchBioinformatics](https://avatars.discourse-cdn.com/v4/letter/w/71e660/32.png) [@witchBioinformatics](https://community.stardog.com/u/witchBioinformatics)\
**Post date:** [August 12, 2019, 11:11am UTC](https://community.stardog.com/t/describe-request-with-stardog-api/1822/1 "2019-08-12T11:11:19Z")

</div>

Hello

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

```auto
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 :

```auto
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

---

<div class="post-metadata">

**Author:** ![stephen](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/stephen/32/27_2.png) [@stephen](https://community.stardog.com/u/stephen)\
**Post date:** [August 12, 2019, 1:59pm UTC](https://community.stardog.com/t/describe-request-with-stardog-api/1822/2 "2019-08-12T13:59:49Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![witchBioinformatics](https://avatars.discourse-cdn.com/v4/letter/w/71e660/32.png) [@witchBioinformatics](https://community.stardog.com/u/witchBioinformatics)\
**Post date:** [August 13, 2019, 2:14pm UTC](https://community.stardog.com/t/describe-request-with-stardog-api/1822/3 "2019-08-13T14:14:16Z")

</div>

```
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()+")");
	}
```

---

<div class="post-metadata">

**Author:** ![stephen](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/stephen/32/27_2.png) [@stephen](https://community.stardog.com/u/stephen)\
**Post date:** [August 13, 2019, 3:08pm UTC](https://community.stardog.com/t/describe-request-with-stardog-api/1822/4 "2019-08-13T15:08:52Z")

</div>

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:

```java
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);
		}

```

---

<div class="post-metadata">

**Author:** ![witchBioinformatics](https://avatars.discourse-cdn.com/v4/letter/w/71e660/32.png) [@witchBioinformatics](https://community.stardog.com/u/witchBioinformatics)\
**Post date:** [August 13, 2019, 3:34pm UTC](https://community.stardog.com/t/describe-request-with-stardog-api/1822/5 "2019-08-13T15:34:02Z")

</div>

Yes it works  
Thank you very much

---

<div class="post-metadata">

**Author:** ![witchBioinformatics](https://avatars.discourse-cdn.com/v4/letter/w/71e660/32.png) [@witchBioinformatics](https://community.stardog.com/u/witchBioinformatics)\
**Post date:** [August 19, 2019, 11:21am UTC](https://community.stardog.com/t/describe-request-with-stardog-api/1822/6 "2019-08-19T11:21:41Z")

</div>

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](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 ?

---

<div class="post-metadata">

**Author:** ![stephen](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/stephen/32/27_2.png) [@stephen](https://community.stardog.com/u/stephen)\
**Post date:** [August 19, 2019, 11:59am UTC](https://community.stardog.com/t/describe-request-with-stardog-api/1822/7 "2019-08-19T11:59:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![witchBioinformatics](https://avatars.discourse-cdn.com/v4/letter/w/71e660/32.png) [@witchBioinformatics](https://community.stardog.com/u/witchBioinformatics)\
**Post date:** [August 19, 2019, 12:13pm UTC](https://community.stardog.com/t/describe-request-with-stardog-api/1822/8 "2019-08-19T12:13:02Z")

</div>

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](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 )
