3636
3737package nl .dtls .fairdatapoint .api .controller .search ;
3838
39- import io .swagger .v3 .oas .annotations .media .Schema ;
4039import io .swagger .v3 .oas .annotations .tags .Tag ;
4140import jakarta .servlet .http .HttpServletResponse ;
4241import org .eclipse .rdf4j .http .server .readonly .sparql .EvaluateResult ;
@@ -57,6 +56,8 @@ public class SearchSparqlController {
5756
5857 private static final String [] ALL_GRAPHS = {};
5958
59+ private static final String JSON_MEDIA_TYPES = "application/json, application/ld+json" ;
60+
6061 private final Repository rdf4jRepository ;
6162
6263 private final SparqlQueryEvaluator sparqlQueryEvaluator ;
@@ -72,19 +73,23 @@ public SearchSparqlController(Repository rdf4jRepository, SparqlQueryEvaluator s
7273 /**
7374 * Allows authenticated users to POST a full SPARQL query.
7475 * Method body copied from org.eclipse.rdf4j.http.server.readonly.QueryResponder.
75- * The "Accept" header is required, and allowable values depend on the type of query,
76+ * The "Accept" header is required, and allowable media types depend on the type of query,
7677 * as defined in <code>org.eclipse.rdf4j.http.server.readonly.sparql.QueryTypes.formats</code>.
78+ * However, to simplify things, we restrict the allowable media types to JSON and/or JSON-LD.
7779 */
7880 @ PreAuthorize ("isAuthenticated()" )
79- @ PostMapping (path = "/search/sparql" , consumes = MediaType .APPLICATION_JSON_VALUE )
81+ @ PostMapping (
82+ path = "/search/sparql" ,
83+ consumes = MediaType .APPLICATION_JSON_VALUE ,
84+ produces = { MediaType .APPLICATION_JSON_VALUE , "application/ld+json" }
85+ )
8086 public void sparqlPost (
81- @ Schema (example = MediaType .APPLICATION_JSON_VALUE )
82- @ RequestHeader (value = HttpHeaders .ACCEPT ) String acceptHeader ,
87+ @ RequestHeader (value = HttpHeaders .ACCEPT , defaultValue = JSON_MEDIA_TYPES ) String acceptHeader ,
8388 @ RequestBody SparqlQuery sparqlQuery ,
8489 HttpServletResponse response
8590 ) throws IOException {
8691 // enforce default accept header for wildcard
87- final String accept = ("*/*" .equals (acceptHeader )) ? MediaType . APPLICATION_JSON_VALUE : acceptHeader ;
92+ final String accept = ("*/*" .equals (acceptHeader )) ? JSON_MEDIA_TYPES : acceptHeader ;
8893 try {
8994 final EvaluateResultHttpResponse result = new EvaluateResultHttpResponse (response );
9095 sparqlQueryEvaluator .evaluate (
0 commit comments