diff --git a/corese-server/src/main/java/fr/inria/corese/server/webservice/SPARQLRestAPI.java b/corese-server/src/main/java/fr/inria/corese/server/webservice/SPARQLRestAPI.java index 3dfc9924f..a98c7a460 100644 --- a/corese-server/src/main/java/fr/inria/corese/server/webservice/SPARQLRestAPI.java +++ b/corese-server/src/main/java/fr/inria/corese/server/webservice/SPARQLRestAPI.java @@ -47,8 +47,8 @@ @Path("sparql") public class SPARQLRestAPI implements ResultFormatDef, URLParam { private static final String ERROR_ENDPOINT = "Error while querying Corese SPARQL endpoint"; - private static final String headerAccept = "Access-Control-Allow-Origin"; - private static final String headerContent = "Content-type"; + private static final String HEADER_ACCESS_CONTROL_ALLOW_ORIGIN = "Access-Control-Allow-Origin"; + private static final String HEADER_CONTENT_TYPE = "Content-type"; private static final String TEXT_PLAIN = "text/plain"; static final String SPARQL_RESULTS_XML = ResultFormat.SPARQL_RESULTS_XML; @@ -57,6 +57,7 @@ public class SPARQLRestAPI implements ResultFormatDef, URLParam { static final String SPARQL_RESULTS_TSV = ResultFormat.SPARQL_RESULTS_TSV; static final String SPARQL_RESULTS_MD = ResultFormat.SPARQL_RESULTS_MD; static final String SPARQL_QUERY = ResultFormat.SPARQL_QUERY; + static final String SPARQL_UPDATE_QUERY = "application/sparql-update"; static final String XML = ResultFormat.XML; static final String RDF_XML = ResultFormat.RDF_XML; @@ -99,7 +100,7 @@ public class SPARQLRestAPI implements ResultFormatDef, URLParam { private static Profile mprofile; - static private final Logger logger = LogManager.getLogger(SPARQLRestAPI.class); + private static final Logger logger = LogManager.getLogger(SPARQLRestAPI.class); private static String key; static { @@ -164,12 +165,10 @@ public Response initRDF( @DefaultValue("false") @FormParam("load") String load, @FormParam("profile") String profile, @DefaultValue("false") @FormParam("localhost") String localhost) { - logger.info("entering initRDF"); boolean ent = entailments.equals("true"); boolean owl = owlrl.equals("true"); boolean ld = load.equals("true"); localProfile = profile; - System.out.println("entailment: " + ent); // option -init propertyFile may declare db storage path // with property STORAGE=path // DatasetManager create appropriate DataManager for db storage @@ -179,7 +178,7 @@ public Response initRDF( store = new TripleStore(ent, owl); // default db storage DataManager is for sparql endpoint store.setDataManager(man.getDataManager()); - // logger.info("DatasetManager: " + store.getDataManager()); + init(localhost.equals("true")); if (ld) { // load data from st:default or st:user service profile if any @@ -189,14 +188,13 @@ public Response initRDF( setVisitor(QuerySolverVisitorServer.create(createEval())); getVisitor().initServer(EmbeddedJettyServer.BASE_URI); init(); - return Response.status(200).header(headerAccept, "*").entity("Endpoint reset").build(); + return Response.status(200).header(HEADER_ACCESS_CONTROL_ALLOW_ORIGIN, "*").entity("Endpoint reset").build(); } void init() { if (getKey() == null) { setKey(genkey()); } - logger.info("key: " + getKey()); } String genkey() { @@ -221,7 +219,6 @@ void init(boolean localhost) { Profile.setProfile(mprofile); if (localProfile != null) { localProfile = NSManager.toURI(localProfile); - logger.info("Load: " + localProfile); } mprofile.initServer(PROFILE_DEFAULT, localProfile); } @@ -249,7 +246,7 @@ public Response loadRDF( if (remotePath == null) { String error = "Null remote path"; logger.error(error); - return Response.status(404).header(headerAccept, "*").entity(error).build(); + return Response.status(404).header(HEADER_ACCESS_CONTROL_ALLOW_ORIGIN, "*").entity(error).build(); } logger.debug(remotePath); @@ -258,16 +255,15 @@ public Response loadRDF( // path with extension : use extension // path with no extension : load as turtle // use case: rdf: is in Turtle - if (!getTripleStore().isProtect()) { // getMode() != QueryProcess.PROTECT_SERVER_MODE) { + if (!getTripleStore().isProtect()) { getTripleStore().load(remotePath, source); } } catch (LoadException ex) { logger.error(ex); - return Response.status(404).header(headerAccept, "*").entity(output).build(); + return Response.status(404).header(HEADER_ACCESS_CONTROL_ALLOW_ORIGIN, "*").entity(output).build(); } - logger.info(output + "Successfully loaded " + remotePath); - return Response.status(200).header(headerAccept, "*").entity(output).build(); + return Response.status(200).header(HEADER_ACCESS_CONTROL_ALLOW_ORIGIN, "*").entity(output).build(); } @GET @@ -279,7 +275,7 @@ public Response setDebug(@QueryParam("value") String debug, @QueryParam("detail" if (detail != null) { isDetail = detail.equals("true"); } - return Response.status(200).header(headerAccept, "*") + return Response.status(200).header(HEADER_ACCESS_CONTROL_ALLOW_ORIGIN, "*") .entity("debug: " + isDebug + " ; " + "detail: " + isDetail).build(); } @@ -303,7 +299,7 @@ public Response setDebug(@QueryParam("value") String debug, @QueryParam("detail" */ @GET @Produces({ SPARQL_RESULTS_XML, XML }) - public Response getTriplesXMLForGet(@jakarta.ws.rs.core.Context HttpServletRequest request, + public Response getSPARQLXMLForGet(@jakarta.ws.rs.core.Context HttpServletRequest request, // name of server from SPARQLService @PathParam("name") String name, // name of federation from SPARQLService @@ -318,7 +314,6 @@ public Response getTriplesXMLForGet(@jakarta.ws.rs.core.Context HttpServletReque @QueryParam("mode") List mode, @QueryParam("uri") List uri) { - logger.info("getTriplesXMLForGet"); String ft = request.getHeader("Accept"); if (ft.contains(SPARQL_RESULTS_XML) || ft.contains(XML)) { // Explicit @Produces, skip format parameter @@ -341,33 +336,14 @@ public Response getResultFormat(HttpServletRequest request, .getResultFormat(name, oper, uri, param, mode, query, access, defaut, named, format, type, transform); } - /** - * Std endpoint function - * type is the return format, eg JSON format - * Content-Type is set by @Produces annotation of the calling function. - * - */ - Response myGetResult(HttpServletRequest request, String name, - String oper, List uri, List param, List mode, + public Response getResultFormat(HttpServletRequest request, + String name, String oper, List uri, List param, List mode, String query, String access, List defaut, List named, int type) { return getResultFormat(request, name, oper, uri, param, mode, query, access, defaut, named, null, type, null); } - Response getResultForPost(HttpServletRequest request, - String name, - String oper, - List uri, - List param, - List mode, - String query, String access, - List defaut, - List named, - int format) { - return myGetResult(request, name, oper, uri, param, mode, query, access, defaut, named, format); - } - /** * parameter format=application/sparql-results+json * format may be null: return default format wrt map kind @@ -406,10 +382,6 @@ private ArrayList getProfiles(String accept) { } } return profiles; - - // eg: Accept: - // application/n-quads;profile="https://www.w3.org/TR/rdf-canon/#sha-256 - // https://www.w3.org/TR/rdf-canon#sha-384" } @GET @@ -429,8 +401,6 @@ public Response getHTMLForGet(@jakarta.ws.rs.core.Context HttpServletRequest req @QueryParam("mode") List mode, @QueryParam("uri") List uri) { - logger.info("getHTMLForGet"); - if ((query == null || query.isEmpty()) && (mode == null || mode.isEmpty())) { query = "select * where {?s ?p ?o} limit 5"; @@ -458,7 +428,7 @@ public Response getHTMLForGet(@jakarta.ws.rs.core.Context HttpServletRequest req @GET @Produces({ "text/plain" }) - public Response getTriplesXMLForGet2(@jakarta.ws.rs.core.Context HttpServletRequest request, + public Response getPlainTextForGet(@jakarta.ws.rs.core.Context HttpServletRequest request, @QueryParam("query") String query, @QueryParam("access") String access, @PathParam("name") String name, @@ -469,8 +439,7 @@ public Response getTriplesXMLForGet2(@jakarta.ws.rs.core.Context HttpServletRequ @QueryParam("mode") List mode, @QueryParam("uri") List uri) { - logger.info("getTriplesXMLForGet2"); - return myGetResult(request, name, oper, uri, param, mode, query, access, defaut, named, TEXT_FORMAT); + return getResultFormat(request, name, oper, uri, param, mode, query, access, defaut, named, TEXT_FORMAT); } @GET @@ -487,7 +456,6 @@ public Response getTriplesJSONForGet(@jakarta.ws.rs.core.Context HttpServletRequ @QueryParam("mode") List mode, @QueryParam("uri") List uri) { - logger.info("getTriplesJSONForGet"); return getResultFormat(request, name, oper, uri, param, mode, query, access, defaut, named, null, JSON_FORMAT, transform); } @@ -505,8 +473,7 @@ public Response getTriplesCSVForGet(@jakarta.ws.rs.core.Context HttpServletReque @QueryParam("mode") List mode, @QueryParam("uri") List uri) { - logger.info("getTriplesCSVForGet"); - return myGetResult(request, name, oper, uri, param, mode, query, access, defaut, named, CSV_FORMAT); + return getResultFormat(request, name, oper, uri, param, mode, query, access, defaut, named, CSV_FORMAT); } @GET @@ -522,8 +489,7 @@ public Response getTriplesTSVForGet(@jakarta.ws.rs.core.Context HttpServletReque @QueryParam("mode") List mode, @QueryParam("uri") List uri) { - logger.info("getTriplesTSVForGet"); - return myGetResult(request, name, oper, uri, param, mode, query, access, defaut, named, TSV_FORMAT); + return getResultFormat(request, name, oper, uri, param, mode, query, access, defaut, named, TSV_FORMAT); } @GET @@ -539,8 +505,7 @@ public Response getTriplesMDForGet(@jakarta.ws.rs.core.Context HttpServletReques @QueryParam("mode") List mode, @QueryParam("uri") List uri) { - logger.info("getTriplesMDForGet"); - return myGetResult(request, name, oper, uri, param, mode, query, access, defaut, named, MARKDOWN_FORMAT); + return getResultFormat(request, name, oper, uri, param, mode, query, access, defaut, named, MARKDOWN_FORMAT); } // ---------------------------------------------------- @@ -560,8 +525,7 @@ public Response getRDFGraphXMLForGet(@jakarta.ws.rs.core.Context HttpServletRequ @QueryParam("mode") List mode, @QueryParam("uri") List uri) { - logger.info("getRDFGraphXMLForGet"); - return myGetResult(request, name, oper, uri, param, mode, query, access, defaut, named, RDF_XML_FORMAT); + return getResultFormat(request, name, oper, uri, param, mode, query, access, defaut, named, RDF_XML_FORMAT); } @GET @@ -577,8 +541,7 @@ public Response getRDFGraphNTripleForGet(@jakarta.ws.rs.core.Context HttpServlet @QueryParam("mode") List mode, @QueryParam("uri") List uri) { - logger.info("getRDFGraphNTripleForGet"); - return myGetResult(request, name, oper, uri, param, mode, query, access, defaut, named, TURTLE_FORMAT); + return getResultFormat(request, name, oper, uri, param, mode, query, access, defaut, named, TURTLE_FORMAT); } @GET @@ -594,8 +557,7 @@ public Response getRDFGraphTrigForGet(@jakarta.ws.rs.core.Context HttpServletReq @QueryParam("mode") List mode, @QueryParam("uri") List uri) { - logger.info("getRDFGraphTrigForGet"); - return myGetResult(request, name, oper, uri, param, mode, query, access, defaut, named, TRIG_FORMAT); + return getResultFormat(request, name, oper, uri, param, mode, query, access, defaut, named, TRIG_FORMAT); } @GET @@ -611,8 +573,7 @@ public Response getRDFGraphJsonLDForGet(@jakarta.ws.rs.core.Context HttpServletR @QueryParam("mode") List mode, @QueryParam("uri") List uri) { - System.out.println("getRDFGraphJsonLDForGet"); - return myGetResult(request, name, oper, uri, param, mode, query, access, defaut, named, JSONLD_FORMAT); + return getResultFormat(request, name, oper, uri, param, mode, query, access, defaut, named, JSONLD_FORMAT); } @GET @@ -628,8 +589,7 @@ public Response getRDFGraphNTriplesForGet(@jakarta.ws.rs.core.Context HttpServle @QueryParam("mode") List mode, @QueryParam("uri") List uri) { - logger.info("getRDFGraphNTriplesForGet"); - return myGetResult(request, name, oper, uri, param, mode, query, access, defaut, named, NTRIPLES_FORMAT); + return getResultFormat(request, name, oper, uri, param, mode, query, access, defaut, named, NTRIPLES_FORMAT); } @GET @@ -645,24 +605,23 @@ public Response getRDFGraphNQuadsForGet(@jakarta.ws.rs.core.Context HttpServletR @QueryParam("mode") List mode, @QueryParam("uri") List uri) { - logger.info("getRDFGraphNQuadsForGet"); - // Get the profiles from the Accept header ArrayList profiles = getProfiles(request.getHeader("Accept")); for (String profile : profiles) { if (profile.equals(this.CN10_SHA) || profile.equals(this.CN10_SHA256)) { - logger.info("Profile: " + profile); - return myGetResult(request, name, oper, uri, param, mode, query, access, defaut, named, RDFC10_FORMAT); + + return getResultFormat(request, name, oper, uri, param, mode, query, access, defaut, named, + RDFC10_FORMAT); } if (profile.equals(this.CN10_SHA384)) { - logger.info("Profile: " + profile); - return myGetResult(request, name, oper, uri, param, mode, query, access, defaut, named, + + return getResultFormat(request, name, oper, uri, param, mode, query, access, defaut, named, RDFC10_SHA384_FORMAT); } } - return myGetResult(request, name, oper, uri, param, mode, query, access, defaut, named, NQUADS_FORMAT); + return getResultFormat(request, name, oper, uri, param, mode, query, access, defaut, named, NQUADS_FORMAT); } // ---------------------------------------------------- @@ -684,6 +643,7 @@ public Response getXMLForPost(@jakarta.ws.rs.core.Context HttpServletRequest req @PathParam("name") String name, @PathParam("oper") String oper, @DefaultValue("") @QueryParam("query") String query, + @DefaultValue("") @FormParam("update") String update, @QueryParam("access") String access, @QueryParam("default-graph-uri") List defaut, @QueryParam("named-graph-uri") List named, @@ -692,11 +652,9 @@ public Response getXMLForPost(@jakarta.ws.rs.core.Context HttpServletRequest req @QueryParam("mode") List mode, @QueryParam("uri") List uri) { - logger.info("getXMLForPost"); - - query = getQuery(query, message); + query = getQuery(query, update, message); - return getResultForPost(request, name, oper, uri, param, mode, query, access, defaut, named, XML_FORMAT); + return getResultFormat(request, name, oper, uri, param, mode, query, access, defaut, named, XML_FORMAT); } @POST @@ -706,6 +664,7 @@ public Response getXMLForPostText(@jakarta.ws.rs.core.Context HttpServletRequest @PathParam("name") String name, @PathParam("oper") String oper, @DefaultValue("") @QueryParam("query") String query, + @DefaultValue("") @FormParam("update") String update, @QueryParam("access") String access, @QueryParam("default-graph-uri") List defaut, @QueryParam("named-graph-uri") List named, @@ -714,48 +673,9 @@ public Response getXMLForPostText(@jakarta.ws.rs.core.Context HttpServletRequest @QueryParam("mode") List mode, @QueryParam("uri") List uri) { - logger.info("getXMLForPostText"); - - query = getQuery(query, message); - - return getResultForPost(request, name, oper, uri, param, mode, query, access, defaut, named, TEXT_FORMAT); - } - - @POST - @Produces(HTML) - @Consumes(MediaType.APPLICATION_FORM_URLENCODED) - public Response getHTMLForPost(@jakarta.ws.rs.core.Context HttpServletRequest request, - @PathParam("name") String name, - @PathParam("oper") String oper, - @DefaultValue("") @FormParam("query") String query, - @FormParam("access") String access, - @FormParam("default-graph-uri") List defaut, - @FormParam("named-graph-uri") List named, - @FormParam("param") List param, - @FormParam("mode") List mode, - @FormParam("uri") List uri, - String message) { - - logger.info("getHTMLForPost"); - - query = getQuery(query, message); + query = getQuery(query, update, message); - return new Transformer().queryPOSTHTML( - request, - oper, - fr.inria.corese.core.transform.Transformer.SPARQL, - null, - null, - null, - null, - HTML, - access, - query, - name, - null, - null, - defaut, - named); + return getResultFormat(request, name, oper, uri, param, mode, query, access, defaut, named, TEXT_FORMAT); } /** @@ -783,12 +703,7 @@ public Response getTriplesXMLForPost(@jakarta.ws.rs.core.Context HttpServletRequ @FormParam("mode") List mode, @FormParam("uri") List uri, String message) { - - logger.info("getTriplesXMLForPost"); String accept = request.getHeader("Accept"); - if (accept != null && !accept.isEmpty()) { - logger.info("Accept: " + accept); - } query = getQuery(query, update, message); @@ -808,6 +723,27 @@ List dataset(List from, List using) { return from; } + @POST + @Produces(HTML) + @Consumes(MediaType.APPLICATION_FORM_URLENCODED) + public Response getHTMLForPost(@jakarta.ws.rs.core.Context HttpServletRequest request, + @PathParam("name") String name, + @PathParam("oper") String oper, + @DefaultValue("") @FormParam("query") String query, + @DefaultValue("") @FormParam("update") String update, + @FormParam("access") String access, + @FormParam("default-graph-uri") List defaut, + @FormParam("named-graph-uri") List named, + @FormParam("param") List param, + @FormParam("mode") List mode, + @FormParam("uri") List uri, + String message) { + + query = getQuery(query, update, message); + + return getResultFormat(request, name, oper, uri, param, mode, query, access, defaut, named, HTML_FORMAT); + } + @POST @Produces(TEXT) @Consumes(MediaType.APPLICATION_FORM_URLENCODED) @@ -825,17 +761,17 @@ public Response getTriplesTEXTForPost(@jakarta.ws.rs.core.Context HttpServletReq String message) { query = getQuery(query, update, message); - logger.info("getTriplesTEXTForPost"); - return getResultForPost(request, name, oper, uri, param, mode, query, access, defaut, named, TEXT_FORMAT); + return getResultFormat(request, name, oper, uri, param, mode, query, access, defaut, named, TEXT_FORMAT); } @POST @Produces(SPARQL_RESULTS_JSON) @Consumes(SPARQL_QUERY) - public Response getTriplesJSONForPostNew(@jakarta.ws.rs.core.Context HttpServletRequest request, + public Response getTriplesJSONForPost(@jakarta.ws.rs.core.Context HttpServletRequest request, @PathParam("name") String name, @PathParam("oper") String oper, @DefaultValue("") @QueryParam("query") String query, + @DefaultValue("") @FormParam("update") String update, @QueryParam("access") String access, @QueryParam("default-graph-uri") List defaut, @QueryParam("named-graph-uri") List named, @@ -843,16 +779,15 @@ public Response getTriplesJSONForPostNew(@jakarta.ws.rs.core.Context HttpServlet @QueryParam("mode") List mode, @QueryParam("uri") List uri, String message) { - logger.info("getTriplesJSONForPostNew"); - query = getQuery(query, message); + query = getQuery(query, update, message); - return getResultForPost(request, name, oper, uri, param, mode, query, access, defaut, named, JSON_FORMAT); + return getResultFormat(request, name, oper, uri, param, mode, query, access, defaut, named, JSON_FORMAT); } @POST @Produces(SPARQL_RESULTS_JSON) @Consumes(MediaType.APPLICATION_FORM_URLENCODED) - public Response getTriplesJSONForPost(@jakarta.ws.rs.core.Context HttpServletRequest request, + public Response getTriplesJSONForPostFormUrlEncoded(@jakarta.ws.rs.core.Context HttpServletRequest request, @PathParam("name") String name, @PathParam("oper") String oper, @DefaultValue("") @FormParam("query") String query, @@ -867,7 +802,6 @@ public Response getTriplesJSONForPost(@jakarta.ws.rs.core.Context HttpServletReq String message) { query = getQuery(query, update, message); - logger.info("getTriplesJSONForPost"); return getResultFormat(request, name, oper, uri, param, mode, query, access, defaut, named, null, JSON_FORMAT, transform); } @@ -890,26 +824,11 @@ public Response getTriplesCSVForPost(@jakarta.ws.rs.core.Context HttpServletRequ String message) { query = getQuery(query, update, message); - logger.info("getTriplesCSVForPost"); + return getResultFormat(request, name, oper, uri, param, mode, query, access, defaut, named, null, CSV_FORMAT, transform); } - // try { - // query = getQuery(query, update, message); - // logger.info("getTriplesCSVForPost"); - // - // return Response.status(200).header(headerAccept, - // "*").entity(CSVFormat.create(getTripleStore(name) - // .query(request, query, createDataset(request, defaut, named, - // access))).toString()).build(); - // } catch (Exception ex) { - // logger.error(ERROR_ENDPOINT, ex); - // return Response.status(ERROR).header(headerAccept, - // "*").entity(ERROR_ENDPOINT).build(); - // } - // } - @POST @Produces(SPARQL_RESULTS_TSV) @Consumes(MediaType.APPLICATION_FORM_URLENCODED) @@ -927,26 +846,11 @@ public Response getTriplesTSVForPost(@jakarta.ws.rs.core.Context HttpServletRequ @FormParam("uri") List uri, String message) { query = getQuery(query, update, message); - logger.info("getTriplesTSVForPost"); + return getResultFormat(request, name, oper, uri, param, mode, query, access, defaut, named, null, TSV_FORMAT, transform); } - // try { - // query = getQuery(query, update, message); - // logger.info("getTriplesTSVForPost"); - // - // return Response.status(200).header(headerAccept, - // "*").entity(TSVFormat.create(getTripleStore(name) - // .query(request, query, createDataset(request, defaut, named, - // access))).toString()).build(); - // } catch (Exception ex) { - // logger.error(ERROR_ENDPOINT, ex); - // return Response.status(ERROR).header(headerAccept, - // "*").entity(ERROR_ENDPOINT).build(); - // } - // } - // ---------------------------------------------------- // SPARQL QUERY - DESCRIBE and CONSTRUCT with HTTP POST // ---------------------------------------------------- @@ -969,8 +873,7 @@ public Response getRDFGraphXMLForPost(@jakarta.ws.rs.core.Context HttpServletReq query = getQuery(query, update, message); - logger.info("getRDFGraphXMLForPost"); - return getResultForPost(request, name, oper, uri, param, mode, query, access, defaut, named, RDF_XML_FORMAT); + return getResultFormat(request, name, oper, uri, param, mode, query, access, defaut, named, RDF_XML_FORMAT); } @POST @@ -990,8 +893,8 @@ public Response getRDFGraphNTripleForPost(@jakarta.ws.rs.core.Context HttpServle String message) { query = getQuery(query, update, message); - logger.info("getRDFGraphNTripleForPost"); - return getResultForPost(request, name, oper, uri, param, mode, query, access, defaut, named, TURTLE_FORMAT); + + return getResultFormat(request, name, oper, uri, param, mode, query, access, defaut, named, TURTLE_FORMAT); } @POST @@ -1010,8 +913,8 @@ public Response getRDFGraphJsonLDForPost(@jakarta.ws.rs.core.Context HttpServlet @FormParam("uri") List uri, String message) { query = getQuery(query, update, message); - logger.info("getRDFGraphJsonLDForPost"); - return getResultForPost(request, name, oper, uri, param, mode, query, access, defaut, named, JSONLD_FORMAT); + + return getResultFormat(request, name, oper, uri, param, mode, query, access, defaut, named, JSONLD_FORMAT); } @POST @@ -1030,8 +933,8 @@ public Response getRDFGraphNTriplesForPost(@jakarta.ws.rs.core.Context HttpServl @FormParam("uri") List uri, String message) { query = getQuery(query, update, message); - logger.info("getRDFGraphNTriplesForPost"); - return getResultForPost(request, name, oper, uri, param, mode, query, access, defaut, named, NTRIPLES_FORMAT); + + return getResultFormat(request, name, oper, uri, param, mode, query, access, defaut, named, NTRIPLES_FORMAT); } @POST @@ -1050,24 +953,24 @@ public Response getRDFGraphNQuadsForPost(@jakarta.ws.rs.core.Context HttpServlet @FormParam("uri") List uri, String message) { query = getQuery(query, update, message); - logger.info("getRDFGraphNQuadsForPost"); // Get the profiles from the Accept header ArrayList profiles = getProfiles(request.getHeader("Accept")); for (String profile : profiles) { if (profile.equals(this.CN10_SHA) || profile.equals(this.CN10_SHA256)) { - logger.info("Profile: " + profile); - return myGetResult(request, name, oper, uri, param, mode, query, access, defaut, named, RDFC10_FORMAT); + + return getResultFormat(request, name, oper, uri, param, mode, query, access, defaut, named, + RDFC10_FORMAT); } if (profile.equals(this.CN10_SHA384)) { - logger.info("Profile: " + profile); - return myGetResult(request, name, oper, uri, param, mode, query, access, defaut, named, + + return getResultFormat(request, name, oper, uri, param, mode, query, access, defaut, named, RDFC10_SHA384_FORMAT); } } - return myGetResult(request, name, oper, uri, param, mode, query, access, defaut, named, NQUADS_FORMAT); + return getResultFormat(request, name, oper, uri, param, mode, query, access, defaut, named, NQUADS_FORMAT); } // ---------------------------------------------------- @@ -1087,34 +990,112 @@ void afterRequest(HttpServletRequest request, Response resp, String query, Mappi } @POST - @Consumes("application/sparql-update") - public Response updateTriplesDirect(@jakarta.ws.rs.core.Context HttpServletRequest request, + @Consumes(SPARQL_UPDATE_QUERY) + @Produces(SPARQL_RESULTS_XML) + public Response updateTriplesDirectXML(@jakarta.ws.rs.core.Context HttpServletRequest request, String message, // standard parameter, do not add @QueryParam() @PathParam("name") String name, + @PathParam("oper") String oper, @QueryParam("access") String access, @QueryParam("using-graph-uri") List defaut, - @QueryParam("using-named-graph-uri") List named) { - try { - // request. - logger.info("updateTriplesDirect"); - Mappings map = null; - if (message != null) { - logger.info(message); - beforeRequest(request, message); - map = getTripleStore(name).query(request, message, createDataset(request, defaut, named, access)); - } else { - logger.warn("Null update query !"); - } + @QueryParam("using-named-graph-uri") List named, + @QueryParam("param") List param, + @QueryParam("mode") List mode, + @QueryParam("uri") List uri) { + if (message != null) { + return getResultFormat(request, name, oper, uri, param, mode, message, access, defaut, named, XML_FORMAT); + } else { + logger.warn("Null update query !"); + return Response.status(ERROR).header(HEADER_ACCESS_CONTROL_ALLOW_ORIGIN, "*").entity(ERROR_ENDPOINT) + .build(); + } + } - Response resp = Response.status(200) - .header(headerAccept, "*") - .header(headerContent, TEXT_PLAIN) - .entity("").build(); - afterRequest(request, resp, message, map, resp.getEntity().toString()); - return resp; - } catch (Exception ex) { - logger.error(ERROR_ENDPOINT, ex); - return Response.status(ERROR).header(headerAccept, "*").entity(ERROR_ENDPOINT).build(); + @POST + @Consumes(SPARQL_UPDATE_QUERY) + @Produces(SPARQL_RESULTS_CSV) + public Response updateTriplesDirectCSV(@jakarta.ws.rs.core.Context HttpServletRequest request, + String message, // standard parameter, do not add @QueryParam() + @PathParam("name") String name, + @PathParam("oper") String oper, + @QueryParam("access") String access, + @QueryParam("using-graph-uri") List defaut, + @QueryParam("using-named-graph-uri") List named, + @QueryParam("param") List param, + @QueryParam("mode") List mode, + @QueryParam("uri") List uri) { + if (message != null) { + return getResultFormat(request, name, oper, uri, param, mode, message, access, defaut, named, CSV_FORMAT); + } else { + logger.warn("Null update query !"); + return Response.status(ERROR).header(HEADER_ACCESS_CONTROL_ALLOW_ORIGIN, "*").entity(ERROR_ENDPOINT) + .build(); + } + } + + @POST + @Consumes(SPARQL_UPDATE_QUERY) + @Produces(SPARQL_RESULTS_TSV) + public Response updateTriplesDirectTSV(@jakarta.ws.rs.core.Context HttpServletRequest request, + String message, // standard parameter, do not add @QueryParam() + @PathParam("name") String name, + @PathParam("oper") String oper, + @QueryParam("access") String access, + @QueryParam("using-graph-uri") List defaut, + @QueryParam("using-named-graph-uri") List named, + @QueryParam("param") List param, + @QueryParam("mode") List mode, + @QueryParam("uri") List uri) { + if (message != null) { + return getResultFormat(request, name, oper, uri, param, mode, message, access, defaut, named, TSV_FORMAT); + } else { + logger.warn("Null update query !"); + return Response.status(ERROR).header(HEADER_ACCESS_CONTROL_ALLOW_ORIGIN, "*").entity(ERROR_ENDPOINT) + .build(); + } + } + + @POST + @Consumes(SPARQL_UPDATE_QUERY) + @Produces(SPARQL_RESULTS_JSON) + public Response updateTriplesDirectJSON(@jakarta.ws.rs.core.Context HttpServletRequest request, + String message, // standard parameter, do not add @QueryParam() + @PathParam("name") String name, + @PathParam("oper") String oper, + @QueryParam("access") String access, + @QueryParam("using-graph-uri") List defaut, + @QueryParam("using-named-graph-uri") List named, + @QueryParam("param") List param, + @QueryParam("mode") List mode, + @QueryParam("uri") List uri) { + if (message != null) { + return getResultFormat(request, name, oper, uri, param, mode, message, access, defaut, named, JSON_FORMAT); + } else { + logger.warn("Null update query !"); + return Response.status(ERROR).header(HEADER_ACCESS_CONTROL_ALLOW_ORIGIN, "*").entity(ERROR_ENDPOINT) + .build(); + } + } + + @POST + @Consumes(SPARQL_UPDATE_QUERY) + @Produces(SPARQL_RESULTS_MD) + public Response updateTriplesDirectMD(@jakarta.ws.rs.core.Context HttpServletRequest request, + String message, // standard parameter, do not add @QueryParam() + @PathParam("name") String name, + @PathParam("oper") String oper, + @QueryParam("access") String access, + @QueryParam("using-graph-uri") List defaut, + @QueryParam("using-named-graph-uri") List named, + @QueryParam("param") List param, + @QueryParam("mode") List mode, + @QueryParam("uri") List uri) { + if (message != null) { + return getResultFormat(request, name, oper, uri, param, mode, message, access, defaut, named, MARKDOWN_FORMAT); + } else { + logger.warn("Null update query !"); + return Response.status(ERROR).header(HEADER_ACCESS_CONTROL_ALLOW_ORIGIN, "*").entity(ERROR_ENDPOINT) + .build(); } } @@ -1126,13 +1107,14 @@ public Response getTriplesForHead(@jakarta.ws.rs.core.Context HttpServletRequest @QueryParam("default-graph-uri") List defaut, @QueryParam("named-graph-uri") List named) { try { - logger.info("getTriplesForHead"); Mappings mp = getTripleStore(name).query(request, query, createDataset(request, defaut, named, access)); - return Response.status(mp.size() > 0 ? 200 : 400).header(headerAccept, "*").entity("Query has no response") + return Response.status(mp.size() > 0 ? 200 : 400).header(HEADER_ACCESS_CONTROL_ALLOW_ORIGIN, "*") + .entity("Query has no response") .build(); } catch (Exception ex) { logger.error(ERROR_ENDPOINT, ex); - return Response.status(ERROR).header(headerAccept, "*").entity(ERROR_ENDPOINT).build(); + return Response.status(ERROR).header(HEADER_ACCESS_CONTROL_ALLOW_ORIGIN, "*").entity(ERROR_ENDPOINT) + .build(); } } @@ -1147,7 +1129,6 @@ public Response getJSON(@jakarta.ws.rs.core.Context HttpServletRequest request, if (query == null) throw new Exception("No query"); Mappings maps = getTripleStore().query(request, query); - logger.info(maps.size()); Graph g = (Graph) maps.getGraph(); String mapsProvJson = "{ \"mappings\" : " + JSONFormat.create(maps).toString() + " , " + "\"d3\" : " @@ -1181,7 +1162,8 @@ public Response getTriplesJSONForGetWithGraph(@jakarta.ws.rs.core.Context HttpSe } catch (Exception ex) { logger.error(ERROR_ENDPOINT, ex); - return Response.status(ERROR).header(headerAccept, "*").entity(ERROR_ENDPOINT).build(); + return Response.status(ERROR).header(HEADER_ACCESS_CONTROL_ALLOW_ORIGIN, "*").entity(ERROR_ENDPOINT) + .build(); } } diff --git a/corese-server/src/test/java/fr/inria/corese/server/webservice/GraphStoreProtocolTest.java b/corese-server/src/test/java/fr/inria/corese/server/webservice/GraphStoreProtocolTest.java index b018dbdd9..a50e48c6f 100644 --- a/corese-server/src/test/java/fr/inria/corese/server/webservice/GraphStoreProtocolTest.java +++ b/corese-server/src/test/java/fr/inria/corese/server/webservice/GraphStoreProtocolTest.java @@ -79,7 +79,7 @@ public void getGraphStoreProtocolWithGraph() throws Exception { headers.add(acceptHeader); String urlQuery = GRAPH_STORE_ENDPOINT + "?" + SPARQLTestUtils.generateGraphStoreParameters("http://example.com/A"); - HttpURLConnection con = SPARQLTestUtils.getConnection(urlQuery, headers); + HttpURLConnection con = HTTPConnectionUtils.getConnection(urlQuery, headers); BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); @@ -112,7 +112,7 @@ public void getGraphStoreProtocolWithDefault() throws Exception{ headers.add(acceptHeader); String urlQuery = GRAPH_STORE_ENDPOINT + "?" + SPARQLTestUtils.generateGraphStoreParameters("default"); - HttpURLConnection con = SPARQLTestUtils.getConnection(urlQuery, headers); + HttpURLConnection con = HTTPConnectionUtils.getConnection(urlQuery, headers); BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); @@ -147,7 +147,7 @@ public void getGraphStoreProtocolWithUnknownGraph() throws Exception{ headers.add(acceptHeader); String urlQuery = GRAPH_STORE_ENDPOINT + "?" + SPARQLTestUtils.generateGraphStoreParameters("http://example.com/Z"); - HttpURLConnection con = SPARQLTestUtils.getConnection(urlQuery, headers); + HttpURLConnection con = HTTPConnectionUtils.getConnection(urlQuery, headers); BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); @@ -186,7 +186,7 @@ public void putGraphStoreProtocolNewGraph() throws Exception { String rdfPayload = "@prefix ex: . ex:C a ex:Thing ."; - HttpURLConnection con = SPARQLTestUtils.putConnection(urlQuery, headers, rdfPayload); + HttpURLConnection con = HTTPConnectionUtils.putConnection(urlQuery, headers, rdfPayload); int status = con.getResponseCode(); @@ -214,7 +214,7 @@ public void putGraphStoreProtocolExistingGraph() throws Exception { String rdfPayload = "@prefix ex: . ex:C a ex:Thing ."; - HttpURLConnection con = SPARQLTestUtils.putConnection(urlQuery, headers, rdfPayload); + HttpURLConnection con = HTTPConnectionUtils.putConnection(urlQuery, headers, rdfPayload); int status = con.getResponseCode(); @@ -233,7 +233,7 @@ public void deleteGraphStoreProtocol() throws Exception { boolean presenceTest = SPARQLTestUtils.sendSPARQLAsk("ASK { GRAPH { ?s ?p ?o } }"); String urlQuery = GRAPH_STORE_ENDPOINT + "?" + SPARQLTestUtils.generateGraphStoreParameters("http://example.com/B"); - HttpURLConnection deleteCon = SPARQLTestUtils.deleteConnection(urlQuery); + HttpURLConnection deleteCon = HTTPConnectionUtils.deleteConnection(urlQuery); int status = deleteCon.getResponseCode(); @@ -252,7 +252,7 @@ public void deleteGraphStoreProtocolWithUnknownGraph() throws Exception { boolean presenceTest = ! SPARQLTestUtils.sendSPARQLAsk("ASK { GRAPH { ?s ?p ?o } }"); String urlQuery = GRAPH_STORE_ENDPOINT + "?" + SPARQLTestUtils.generateGraphStoreParameters("http://example.com/Z"); - HttpURLConnection deleteCon = SPARQLTestUtils.deleteConnection(urlQuery); + HttpURLConnection deleteCon = HTTPConnectionUtils.deleteConnection(urlQuery); int status = deleteCon.getResponseCode(); @@ -280,7 +280,7 @@ public void postGraphStoreProtocolNewGraph() throws Exception { String rdfPayload = "@prefix ex: . ex:C a ex:Thing ."; - HttpURLConnection con = SPARQLTestUtils.postConnection(urlQuery, headers, rdfPayload); + HttpURLConnection con = HTTPConnectionUtils.postConnection(urlQuery, headers, rdfPayload); int status = con.getResponseCode(); @@ -308,7 +308,7 @@ public void postGraphStoreProtocolExistingGraph() throws Exception { String rdfPayload = "@prefix ex: . ex:C a ex:Thing ."; - HttpURLConnection con = SPARQLTestUtils.postConnection(urlQuery, headers, rdfPayload); + HttpURLConnection con = HTTPConnectionUtils.postConnection(urlQuery, headers, rdfPayload); int status = con.getResponseCode(); @@ -331,7 +331,7 @@ public void headGraphStoreProtocolWithDefault() throws Exception{ headers.add(acceptHeader); String urlQuery = GRAPH_STORE_ENDPOINT + "?" + SPARQLTestUtils.generateGraphStoreParameters("default"); - HttpURLConnection con = SPARQLTestUtils.headConnection(urlQuery); + HttpURLConnection con = HTTPConnectionUtils.headConnection(urlQuery); BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); @@ -356,7 +356,7 @@ public void headGraphStoreProtocolWithGraph() throws Exception{ boolean presenceTest = SPARQLTestUtils.sendSPARQLAsk("ASK { GRAPH { ?x ?y ?z } }"); String urlQuery = GRAPH_STORE_ENDPOINT + "?" + SPARQLTestUtils.generateGraphStoreParameters("http://example.com/A"); - HttpURLConnection con = SPARQLTestUtils.headConnection(urlQuery); + HttpURLConnection con = HTTPConnectionUtils.headConnection(urlQuery); BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); String inputLine; @@ -381,7 +381,7 @@ public void headGraphStoreProtocolWithUnknownGraph() throws Exception{ boolean absenceTest = ! SPARQLTestUtils.sendSPARQLAsk("ASK { GRAPH { ?x ?y ?z } }"); String urlQuery = GRAPH_STORE_ENDPOINT + "?" + SPARQLTestUtils.generateGraphStoreParameters("http://example.com/Z"); - HttpURLConnection con = SPARQLTestUtils.headConnection(urlQuery); + HttpURLConnection con = HTTPConnectionUtils.headConnection(urlQuery); BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); diff --git a/corese-server/src/test/java/fr/inria/corese/server/webservice/HTTPConnectionUtils.java b/corese-server/src/test/java/fr/inria/corese/server/webservice/HTTPConnectionUtils.java new file mode 100644 index 000000000..33a84791c --- /dev/null +++ b/corese-server/src/test/java/fr/inria/corese/server/webservice/HTTPConnectionUtils.java @@ -0,0 +1,88 @@ +package fr.inria.corese.server.webservice; + +import java.io.IOException; +import java.net.HttpURLConnection; +import java.net.MalformedURLException; +import java.net.ProtocolException; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; + +public class HTTPConnectionUtils { + + /** + * Get a connection to a server. + * + * @param url server URL + * @param headers HTTP headers + * @return + * @throws MalformedURLException + * @throws IOException + * @throws ProtocolException + */ + + public static HttpURLConnection methodConnection(String method, String url, List> headers) + throws IOException { + URL u = new URL(url); + HttpURLConnection con = (HttpURLConnection) u.openConnection(); + con.setRequestMethod(method); + con.setConnectTimeout(5000); + con.setReadTimeout(5000); + con.setInstanceFollowRedirects(true); + for (List header : headers) { + con.setRequestProperty(header.get(0), header.get(1)); + } + return con; + } + + public static HttpURLConnection getConnection(String url, List> headers) + throws IOException { + return methodConnection("GET", url, headers); + } + + public static HttpURLConnection postConnection(String url, List> headers, String body) + throws IOException { + HttpURLConnection con = methodConnection("POST", url, headers); + con.setDoOutput(true); + con.getOutputStream().write(body.getBytes()); + return con; + } + + public static HttpURLConnection postUrlencodedConnection(String url, List> headers, String body) + throws IOException { + List> newHeaders = new ArrayList<>(headers); + List contentTypeHeader = new ArrayList<>(); + contentTypeHeader.add("Content-Type"); + contentTypeHeader.add("application/x-www-form-urlencoded"); + newHeaders.add(contentTypeHeader); + return postConnection(url, newHeaders, body); + } + + public static HttpURLConnection putConnection(String url, List> headers, String body) + throws IOException { + HttpURLConnection con = methodConnection("PUT", url, headers); + con.setDoOutput(true); + con.getOutputStream().write(body.getBytes()); + return con; + } + + public static HttpURLConnection deleteConnection(String url, List> headers) + throws IOException { + return methodConnection("DELETE", url, headers); + } + + public static HttpURLConnection deleteConnection(String url) + throws IOException { + return deleteConnection( url, new ArrayList<>()); + } + + public static HttpURLConnection headConnection(String url, List> headers) + throws IOException { + return methodConnection("HEAD", url, headers); + } + + public static HttpURLConnection headConnection(String url) + throws IOException { + return headConnection(url, new ArrayList<>()); + } +} diff --git a/corese-server/src/test/java/fr/inria/corese/server/webservice/SPARQLEndpointDescriptionTest.java b/corese-server/src/test/java/fr/inria/corese/server/webservice/SPARQLEndpointDescriptionTest.java index 59a530779..7f099f209 100644 --- a/corese-server/src/test/java/fr/inria/corese/server/webservice/SPARQLEndpointDescriptionTest.java +++ b/corese-server/src/test/java/fr/inria/corese/server/webservice/SPARQLEndpointDescriptionTest.java @@ -98,7 +98,7 @@ public void sparqlWellKnownVoidXMLRDF() throws Exception { contentTypeHeader.add(RDF_XML); headers.add(contentTypeHeader); - HttpURLConnection con = SPARQLTestUtils.getConnection(sparqlEndpoint, headers); + HttpURLConnection con = HTTPConnectionUtils.getConnection(sparqlEndpoint, headers); BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); @@ -139,7 +139,7 @@ public void sparqlWellKnownVoidTurtleRDF() throws Exception { contentTypeHeader.add(TURTLE_TEXT); headers.add(contentTypeHeader); - HttpURLConnection con = SPARQLTestUtils.getConnection(sparqlEndpoint, headers); + HttpURLConnection con = HTTPConnectionUtils.getConnection(sparqlEndpoint, headers); BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); @@ -180,7 +180,7 @@ public void wellKnownVoidXMLRDF() throws Exception { contentTypeHeader.add(RDF_XML); headers.add(contentTypeHeader); - HttpURLConnection con = SPARQLTestUtils.getConnection(sparqlEndpoint, headers); + HttpURLConnection con = HTTPConnectionUtils.getConnection(sparqlEndpoint, headers); BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); @@ -221,7 +221,7 @@ public void wellKnownVoidTurtleRDF() throws Exception { contentTypeHeader.add(TURTLE_TEXT); headers.add(contentTypeHeader); - HttpURLConnection con = SPARQLTestUtils.getConnection(sparqlEndpoint, headers); + HttpURLConnection con = HTTPConnectionUtils.getConnection(sparqlEndpoint, headers); BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); diff --git a/corese-server/src/test/java/fr/inria/corese/server/webservice/SPARQLEndpointQueryTest.java b/corese-server/src/test/java/fr/inria/corese/server/webservice/SPARQLEndpointQueryTest.java index e0e87e21d..c96cca0ee 100644 --- a/corese-server/src/test/java/fr/inria/corese/server/webservice/SPARQLEndpointQueryTest.java +++ b/corese-server/src/test/java/fr/inria/corese/server/webservice/SPARQLEndpointQueryTest.java @@ -131,7 +131,7 @@ public void sparqlSelectResultsXMLEndpointGet() throws Exception { String query = "select * where {?x ?p ?y} limit 1"; String urlQuery = SPARQL_ENDPOINT_URL + "?" + SPARQLTestUtils.generateSPARQLQueryParameters(query); - HttpURLConnection con = SPARQLTestUtils.getConnection(urlQuery, headers); + HttpURLConnection con = HTTPConnectionUtils.getConnection(urlQuery, headers); BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); @@ -165,7 +165,7 @@ public void sparqlSelectResultsXMLEndpointUrlEncodedPost() throws Exception { headers.add(acceptHeader); String query = "select * where {?x ?p ?y} limit 1"; - HttpURLConnection con = SPARQLTestUtils.postUrlencodedConnection(SPARQL_ENDPOINT_URL, headers, + HttpURLConnection con = HTTPConnectionUtils.postUrlencodedConnection(SPARQL_ENDPOINT_URL, headers, SPARQLTestUtils.generateSPARQLQueryParameters(query)); BufferedReader in = new BufferedReader( @@ -203,7 +203,7 @@ public void sparqlSelectResultsXMLEndpointUnencodedPost() throws Exception { headers.add(contentTypeHeader); String query = "select * where {?x ?p ?y} limit 1"; - HttpURLConnection con = SPARQLTestUtils.postConnection(SPARQL_ENDPOINT_URL, headers, query); + HttpURLConnection con = HTTPConnectionUtils.postConnection(SPARQL_ENDPOINT_URL, headers, query); BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); @@ -238,7 +238,7 @@ public void sparqlSelectCSVEndpointGet() throws Exception { String query = "select * where {?x ?p ?y} limit 1"; String urlQuery = SPARQL_ENDPOINT_URL + "?" + SPARQLTestUtils.generateSPARQLQueryParameters(query); - HttpURLConnection con = SPARQLTestUtils.getConnection(urlQuery, headers); + HttpURLConnection con = HTTPConnectionUtils.getConnection(urlQuery, headers); BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); @@ -272,7 +272,7 @@ public void sparqlSelectCSVEndpointUrlEncodedPost() throws Exception { headers.add(acceptHeader); String query = "select * where {?x ?p ?y} limit 1"; - HttpURLConnection con = SPARQLTestUtils.postUrlencodedConnection(SPARQL_ENDPOINT_URL, headers, + HttpURLConnection con = HTTPConnectionUtils.postUrlencodedConnection(SPARQL_ENDPOINT_URL, headers, SPARQLTestUtils.generateSPARQLQueryParameters(query)); BufferedReader in = new BufferedReader( @@ -310,7 +310,7 @@ public void sparqlSelectCSVEndpointUnencodedPost() throws Exception { headers.add(contentTypeHeader); String query = "select * where {?x ?p ?y} limit 1"; - HttpURLConnection con = SPARQLTestUtils.postConnection(SPARQL_ENDPOINT_URL, headers, query); + HttpURLConnection con = HTTPConnectionUtils.postConnection(SPARQL_ENDPOINT_URL, headers, query); BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); @@ -345,7 +345,7 @@ public void sparqlSelectTSVEndpointGet() throws Exception { String query = "select * where {?x ?p ?y} limit 1"; String urlQuery = SPARQL_ENDPOINT_URL + "?" + SPARQLTestUtils.generateSPARQLQueryParameters(query); - HttpURLConnection con = SPARQLTestUtils.getConnection(urlQuery, headers); + HttpURLConnection con = HTTPConnectionUtils.getConnection(urlQuery, headers); BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); @@ -379,7 +379,7 @@ public void sparqlSelectTSVEndpointUrlEncodedPost() throws Exception { headers.add(acceptHeader); String query = "select * where {?x ?p ?y} limit 1"; - HttpURLConnection con = SPARQLTestUtils.postUrlencodedConnection(SPARQL_ENDPOINT_URL, headers, + HttpURLConnection con = HTTPConnectionUtils.postUrlencodedConnection(SPARQL_ENDPOINT_URL, headers, SPARQLTestUtils.generateSPARQLQueryParameters(query)); BufferedReader in = new BufferedReader( @@ -417,7 +417,7 @@ public void sparqlSelectTSVEndpointUnencodedPost() throws Exception { headers.add(contentTypeHeader); String query = "select * where {?x ?p ?y} limit 1"; - HttpURLConnection con = SPARQLTestUtils.postConnection(SPARQL_ENDPOINT_URL, headers, query); + HttpURLConnection con = HTTPConnectionUtils.postConnection(SPARQL_ENDPOINT_URL, headers, query); BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); @@ -452,7 +452,7 @@ public void sparqlSelectMarkdownEndpointGet() throws Exception { String query = "select * where {?x ?p ?y} limit 1"; String urlQuery = SPARQL_ENDPOINT_URL + "?" + SPARQLTestUtils.generateSPARQLQueryParameters(query); - HttpURLConnection con = SPARQLTestUtils.getConnection(urlQuery, headers); + HttpURLConnection con = HTTPConnectionUtils.getConnection(urlQuery, headers); BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); @@ -486,7 +486,7 @@ public void sparqlSelectMarkdownEndpointUrlEncodedPost() throws Exception { headers.add(acceptHeader); String query = "select * where {?x ?p ?y} limit 1"; - HttpURLConnection con = SPARQLTestUtils.postUrlencodedConnection(SPARQL_ENDPOINT_URL, headers, + HttpURLConnection con = HTTPConnectionUtils.postUrlencodedConnection(SPARQL_ENDPOINT_URL, headers, SPARQLTestUtils.generateSPARQLQueryParameters(query)); BufferedReader in = new BufferedReader( @@ -524,7 +524,7 @@ public void sparqlSelectMarkdownEndpointUnencodedPost() throws Exception { headers.add(contentTypeHeader); String query = "select * where {?x ?p ?y} limit 1"; - HttpURLConnection con = SPARQLTestUtils.postConnection(SPARQL_ENDPOINT_URL, headers, query); + HttpURLConnection con = HTTPConnectionUtils.postConnection(SPARQL_ENDPOINT_URL, headers, query); BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); @@ -559,7 +559,7 @@ public void sparqlSelectJSONEndpointGet() throws Exception { String query = "select * where {?x ?p ?y} limit 1"; String urlQuery = SPARQL_ENDPOINT_URL + "?" + SPARQLTestUtils.generateSPARQLQueryParameters(query); - HttpURLConnection con = SPARQLTestUtils.getConnection(urlQuery, headers); + HttpURLConnection con = HTTPConnectionUtils.getConnection(urlQuery, headers); BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); @@ -593,7 +593,7 @@ public void sparqlSelectJSONEndpointUrlEncodedPost() throws Exception { headers.add(acceptHeader); String query = "select * where {?x ?p ?y} limit 1"; - HttpURLConnection con = SPARQLTestUtils.postUrlencodedConnection(SPARQL_ENDPOINT_URL, headers, + HttpURLConnection con = HTTPConnectionUtils.postUrlencodedConnection(SPARQL_ENDPOINT_URL, headers, SPARQLTestUtils.generateSPARQLQueryParameters(query)); BufferedReader in = new BufferedReader( @@ -631,7 +631,7 @@ public void sparqlSelectJSONEndpointUnencodedPost() throws Exception { headers.add(contentTypeHeader); String query = "select * where {?x ?p ?y} limit 1"; - HttpURLConnection con = SPARQLTestUtils.postConnection(SPARQL_ENDPOINT_URL, headers, query); + HttpURLConnection con = HTTPConnectionUtils.postConnection(SPARQL_ENDPOINT_URL, headers, query); BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); @@ -666,7 +666,7 @@ public void sparqlAskRDFXMLEndpointGet() throws Exception { String query = "ASK {?x ?p ?y}"; String urlQuery = SPARQL_ENDPOINT_URL + "?" + SPARQLTestUtils.generateSPARQLQueryParameters(query); - HttpURLConnection con = SPARQLTestUtils.getConnection(urlQuery, headers); + HttpURLConnection con = HTTPConnectionUtils.getConnection(urlQuery, headers); BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); @@ -700,7 +700,7 @@ public void sparqlAskRDFXMLEndpointUrlEncodedPost() throws Exception { headers.add(acceptHeader); String query = "ASK {?x ?p ?y}"; - HttpURLConnection con = SPARQLTestUtils.postUrlencodedConnection(SPARQL_ENDPOINT_URL, headers, + HttpURLConnection con = HTTPConnectionUtils.postUrlencodedConnection(SPARQL_ENDPOINT_URL, headers, SPARQLTestUtils.generateSPARQLQueryParameters(query)); BufferedReader in = new BufferedReader( @@ -738,7 +738,7 @@ public void sparqlAskRDFXMLEndpointUnencodedPost() throws Exception { headers.add(contentTypeHeader); String query = "ASK {?x ?p ?y}"; - HttpURLConnection con = SPARQLTestUtils.postConnection(SPARQL_ENDPOINT_URL, headers, query); + HttpURLConnection con = HTTPConnectionUtils.postConnection(SPARQL_ENDPOINT_URL, headers, query); BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); @@ -773,7 +773,7 @@ public void sparqlAskCSVEndpointGet() throws Exception { String query = "ASK {?x ?p ?y}"; String urlQuery = SPARQL_ENDPOINT_URL + "?" + SPARQLTestUtils.generateSPARQLQueryParameters(query); - HttpURLConnection con = SPARQLTestUtils.getConnection(urlQuery, headers); + HttpURLConnection con = HTTPConnectionUtils.getConnection(urlQuery, headers); BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); @@ -807,7 +807,7 @@ public void sparqlAskCSVEndpointUrlEncodedPost() throws Exception { headers.add(acceptHeader); String query = "ASK {?x ?p ?y}"; - HttpURLConnection con = SPARQLTestUtils.postUrlencodedConnection(SPARQL_ENDPOINT_URL, headers, + HttpURLConnection con = HTTPConnectionUtils.postUrlencodedConnection(SPARQL_ENDPOINT_URL, headers, SPARQLTestUtils.generateSPARQLQueryParameters(query)); BufferedReader in = new BufferedReader( @@ -845,7 +845,7 @@ public void sparqlAskCSVEndpointUnencodedPost() throws Exception { headers.add(contentTypeHeader); String query = "ASK {?x ?p ?y}"; - HttpURLConnection con = SPARQLTestUtils.postConnection(SPARQL_ENDPOINT_URL, headers, query); + HttpURLConnection con = HTTPConnectionUtils.postConnection(SPARQL_ENDPOINT_URL, headers, query); BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); @@ -880,7 +880,7 @@ public void sparqlAskTSVEndpointGet() throws Exception { String query = "ASK {?x ?p ?y}"; String urlQuery = SPARQL_ENDPOINT_URL + "?" + SPARQLTestUtils.generateSPARQLQueryParameters(query); - HttpURLConnection con = SPARQLTestUtils.getConnection(urlQuery, headers); + HttpURLConnection con = HTTPConnectionUtils.getConnection(urlQuery, headers); BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); @@ -914,7 +914,7 @@ public void sparqlAskTSVEndpointUrlEncodedPost() throws Exception { headers.add(acceptHeader); String query = "ASK {?x ?p ?y}"; - HttpURLConnection con = SPARQLTestUtils.postUrlencodedConnection(SPARQL_ENDPOINT_URL, headers, + HttpURLConnection con = HTTPConnectionUtils.postUrlencodedConnection(SPARQL_ENDPOINT_URL, headers, SPARQLTestUtils.generateSPARQLQueryParameters(query)); BufferedReader in = new BufferedReader( @@ -952,7 +952,7 @@ public void sparqlAskTSVEndpointUnencodedPost() throws Exception { headers.add(contentTypeHeader); String query = "ASK {?x ?p ?y}"; - HttpURLConnection con = SPARQLTestUtils.postConnection(SPARQL_ENDPOINT_URL, headers, query); + HttpURLConnection con = HTTPConnectionUtils.postConnection(SPARQL_ENDPOINT_URL, headers, query); BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); @@ -987,7 +987,7 @@ public void sparqlAskMarkdownEndpointGet() throws Exception { String query = "ASK {?x ?p ?y}"; String urlQuery = SPARQL_ENDPOINT_URL + "?" + SPARQLTestUtils.generateSPARQLQueryParameters(query); - HttpURLConnection con = SPARQLTestUtils.getConnection(urlQuery, headers); + HttpURLConnection con = HTTPConnectionUtils.getConnection(urlQuery, headers); BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); @@ -1021,7 +1021,7 @@ public void sparqlAskMarkdownEndpointUrlEncodedPost() throws Exception { headers.add(acceptHeader); String query = "ASK {?x ?p ?y}"; - HttpURLConnection con = SPARQLTestUtils.postUrlencodedConnection(SPARQL_ENDPOINT_URL, headers, + HttpURLConnection con = HTTPConnectionUtils.postUrlencodedConnection(SPARQL_ENDPOINT_URL, headers, SPARQLTestUtils.generateSPARQLQueryParameters(query)); BufferedReader in = new BufferedReader( @@ -1059,7 +1059,7 @@ public void sparqlAskMarkdownEndpointUnencodedPost() throws Exception { headers.add(contentTypeHeader); String query = "ASK {?x ?p ?y}"; - HttpURLConnection con = SPARQLTestUtils.postConnection(SPARQL_ENDPOINT_URL, headers, query); + HttpURLConnection con = HTTPConnectionUtils.postConnection(SPARQL_ENDPOINT_URL, headers, query); BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); @@ -1094,7 +1094,7 @@ public void sparqlAskJSONEndpointGet() throws Exception { String query = "ASK {?x ?p ?y}"; String urlQuery = SPARQL_ENDPOINT_URL + "?" + SPARQLTestUtils.generateSPARQLQueryParameters(query); - HttpURLConnection con = SPARQLTestUtils.getConnection(urlQuery, headers); + HttpURLConnection con = HTTPConnectionUtils.getConnection(urlQuery, headers); BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); @@ -1128,7 +1128,7 @@ public void sparqlAskJSONEndpointUrlEncodedPost() throws Exception { headers.add(acceptHeader); String query = "ASK {?x ?p ?y}"; - HttpURLConnection con = SPARQLTestUtils.postUrlencodedConnection(SPARQL_ENDPOINT_URL, headers, + HttpURLConnection con = HTTPConnectionUtils.postUrlencodedConnection(SPARQL_ENDPOINT_URL, headers, SPARQLTestUtils.generateSPARQLQueryParameters(query)); BufferedReader in = new BufferedReader( @@ -1166,7 +1166,7 @@ public void sparqlAskJSONEndpointUnencodedPost() throws Exception { headers.add(contentTypeHeader); String query = "ASK {?x ?p ?y}"; - HttpURLConnection con = SPARQLTestUtils.postConnection(SPARQL_ENDPOINT_URL, headers, query); + HttpURLConnection con = HTTPConnectionUtils.postConnection(SPARQL_ENDPOINT_URL, headers, query); BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); @@ -1202,7 +1202,7 @@ public void sparqlConstructTurtleEndpointGet() throws Exception { String query = "CONSTRUCT { ?x ?p ?y } WHERE { ?x ?p ?y } LIMIT 1"; String urlQuery = SPARQL_ENDPOINT_URL + "?" + SPARQLTestUtils.generateSPARQLQueryParameters(query); - HttpURLConnection con = SPARQLTestUtils.getConnection(urlQuery, headers); + HttpURLConnection con = HTTPConnectionUtils.getConnection(urlQuery, headers); BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); @@ -1242,7 +1242,7 @@ public void sparqlConstructTurtleEndpointUrlEncodedPost() throws Exception { headers.add(acceptHeader); String query = "CONSTRUCT { ?x ?p ?y } WHERE { ?x ?p ?y } LIMIT 1"; - HttpURLConnection con = SPARQLTestUtils.postUrlencodedConnection(SPARQL_ENDPOINT_URL, headers, + HttpURLConnection con = HTTPConnectionUtils.postUrlencodedConnection(SPARQL_ENDPOINT_URL, headers, SPARQLTestUtils.generateSPARQLQueryParameters(query)); BufferedReader in = new BufferedReader( @@ -1286,7 +1286,7 @@ public void sparqlConstructTurtleEndpointUnencodedPost() throws Exception { headers.add(contentTypeHeader); String query = "CONSTRUCT { ?x ?p ?y } WHERE { ?x ?p ?y } LIMIT 1"; - HttpURLConnection con = SPARQLTestUtils.postConnection(SPARQL_ENDPOINT_URL, headers, query); + HttpURLConnection con = HTTPConnectionUtils.postConnection(SPARQL_ENDPOINT_URL, headers, query); BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); @@ -1327,7 +1327,7 @@ public void sparqlConstructRDFXMLEndpointGet() throws Exception { String query = "CONSTRUCT { ?x ?p ?y } WHERE { ?x ?p ?y } LIMIT 1"; String urlQuery = SPARQL_ENDPOINT_URL + "?" + SPARQLTestUtils.generateSPARQLQueryParameters(query); - HttpURLConnection con = SPARQLTestUtils.getConnection(urlQuery, headers); + HttpURLConnection con = HTTPConnectionUtils.getConnection(urlQuery, headers); BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); @@ -1367,7 +1367,7 @@ public void sparqlConstructRDFXMLEndpointUrlEncodedPost() throws Exception { headers.add(acceptHeader); String query = "CONSTRUCT { ?x ?p ?y } WHERE { ?x ?p ?y } LIMIT 1"; - HttpURLConnection con = SPARQLTestUtils.postUrlencodedConnection(SPARQL_ENDPOINT_URL, headers, + HttpURLConnection con = HTTPConnectionUtils.postUrlencodedConnection(SPARQL_ENDPOINT_URL, headers, SPARQLTestUtils.generateSPARQLQueryParameters(query)); BufferedReader in = new BufferedReader( @@ -1411,7 +1411,7 @@ public void sparqlConstructRDFXMLEndpointUnencodedPost() throws Exception { headers.add(contentTypeHeader); String query = "CONSTRUCT { ?x ?p ?y } WHERE { ?x ?p ?y } LIMIT 1"; - HttpURLConnection con = SPARQLTestUtils.postConnection(SPARQL_ENDPOINT_URL, headers, query); + HttpURLConnection con = HTTPConnectionUtils.postConnection(SPARQL_ENDPOINT_URL, headers, query); BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); @@ -1452,7 +1452,7 @@ public void sparqlConstructTrigEndpointGet() throws Exception { String query = "CONSTRUCT { ?x ?p ?y } WHERE { ?x ?p ?y } LIMIT 1"; String urlQuery = SPARQL_ENDPOINT_URL + "?" + SPARQLTestUtils.generateSPARQLQueryParameters(query); - HttpURLConnection con = SPARQLTestUtils.getConnection(urlQuery, headers); + HttpURLConnection con = HTTPConnectionUtils.getConnection(urlQuery, headers); BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); @@ -1492,7 +1492,7 @@ public void sparqlConstructTrigEndpointUrlEncodedPost() throws Exception { headers.add(acceptHeader); String query = "CONSTRUCT { ?x ?p ?y } WHERE { ?x ?p ?y } LIMIT 1"; - HttpURLConnection con = SPARQLTestUtils.postUrlencodedConnection(SPARQL_ENDPOINT_URL, headers, + HttpURLConnection con = HTTPConnectionUtils.postUrlencodedConnection(SPARQL_ENDPOINT_URL, headers, SPARQLTestUtils.generateSPARQLQueryParameters(query)); BufferedReader in = new BufferedReader( @@ -1536,7 +1536,7 @@ public void sparqlConstructTrigEndpointUnencodedPost() throws Exception { headers.add(contentTypeHeader); String query = "CONSTRUCT { ?x ?p ?y } WHERE { ?x ?p ?y } LIMIT 1"; - HttpURLConnection con = SPARQLTestUtils.postConnection(SPARQL_ENDPOINT_URL, headers, query); + HttpURLConnection con = HTTPConnectionUtils.postConnection(SPARQL_ENDPOINT_URL, headers, query); BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); @@ -1577,7 +1577,7 @@ public void sparqlConstructJSONLDEndpointGet() throws Exception { String query = "CONSTRUCT { ?x ?p ?y } WHERE { ?x ?p ?y } LIMIT 1"; String urlQuery = SPARQL_ENDPOINT_URL + "?" + SPARQLTestUtils.generateSPARQLQueryParameters(query); - HttpURLConnection con = SPARQLTestUtils.getConnection(urlQuery, headers); + HttpURLConnection con = HTTPConnectionUtils.getConnection(urlQuery, headers); BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); @@ -1617,7 +1617,7 @@ public void sparqlConstructJSONLDEndpointUrlEncodedPost() throws Exception { headers.add(acceptHeader); String query = "CONSTRUCT { ?x ?p ?y } WHERE { ?x ?p ?y } LIMIT 1"; - HttpURLConnection con = SPARQLTestUtils.postUrlencodedConnection(SPARQL_ENDPOINT_URL, headers, + HttpURLConnection con = HTTPConnectionUtils.postUrlencodedConnection(SPARQL_ENDPOINT_URL, headers, SPARQLTestUtils.generateSPARQLQueryParameters(query)); BufferedReader in = new BufferedReader( @@ -1661,7 +1661,7 @@ public void sparqlConstructJSONLDEndpointUnencodedPost() throws Exception { headers.add(contentTypeHeader); String query = "CONSTRUCT { ?x ?p ?y } WHERE { ?x ?p ?y } LIMIT 1"; - HttpURLConnection con = SPARQLTestUtils.postConnection(SPARQL_ENDPOINT_URL, headers, query); + HttpURLConnection con = HTTPConnectionUtils.postConnection(SPARQL_ENDPOINT_URL, headers, query); BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); @@ -1702,7 +1702,7 @@ public void sparqlConstructNTriplesEndpointGet() throws Exception { String query = "CONSTRUCT { ?x ?p ?y } WHERE { ?x ?p ?y } LIMIT 1"; String urlQuery = SPARQL_ENDPOINT_URL + "?" + SPARQLTestUtils.generateSPARQLQueryParameters(query); - HttpURLConnection con = SPARQLTestUtils.getConnection(urlQuery, headers); + HttpURLConnection con = HTTPConnectionUtils.getConnection(urlQuery, headers); BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); @@ -1742,7 +1742,7 @@ public void sparqlConstructNTriplesEndpointUrlEncodedPost() throws Exception { headers.add(acceptHeader); String query = "CONSTRUCT { ?x ?p ?y } WHERE { ?x ?p ?y } LIMIT 1"; - HttpURLConnection con = SPARQLTestUtils.postUrlencodedConnection(SPARQL_ENDPOINT_URL, headers, + HttpURLConnection con = HTTPConnectionUtils.postUrlencodedConnection(SPARQL_ENDPOINT_URL, headers, SPARQLTestUtils.generateSPARQLQueryParameters(query)); BufferedReader in = new BufferedReader( @@ -1786,7 +1786,7 @@ public void sparqlConstructNTriplesEndpointUnencodedPost() throws Exception { headers.add(contentTypeHeader); String query = "CONSTRUCT { ?x ?p ?y } WHERE { ?x ?p ?y } LIMIT 1"; - HttpURLConnection con = SPARQLTestUtils.postConnection(SPARQL_ENDPOINT_URL, headers, query); + HttpURLConnection con = HTTPConnectionUtils.postConnection(SPARQL_ENDPOINT_URL, headers, query); BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); @@ -1827,7 +1827,7 @@ public void sparqlConstructNQuadsEndpointGet() throws Exception { String query = "CONSTRUCT { ?x ?p ?y } WHERE { ?x ?p ?y } LIMIT 1"; String urlQuery = SPARQL_ENDPOINT_URL + "?" + SPARQLTestUtils.generateSPARQLQueryParameters(query); - HttpURLConnection con = SPARQLTestUtils.getConnection(urlQuery, headers); + HttpURLConnection con = HTTPConnectionUtils.getConnection(urlQuery, headers); BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); @@ -1867,7 +1867,7 @@ public void sparqlConstructNQuadsEndpointUrlEncodedPost() throws Exception { headers.add(acceptHeader); String query = "CONSTRUCT { ?x ?p ?y } WHERE { ?x ?p ?y } LIMIT 1"; - HttpURLConnection con = SPARQLTestUtils.postUrlencodedConnection(SPARQL_ENDPOINT_URL, headers, + HttpURLConnection con = HTTPConnectionUtils.postUrlencodedConnection(SPARQL_ENDPOINT_URL, headers, SPARQLTestUtils.generateSPARQLQueryParameters(query)); BufferedReader in = new BufferedReader( @@ -1911,7 +1911,7 @@ public void sparqlConstructNQuadsEndpointUnencodedPost() throws Exception { headers.add(contentTypeHeader); String query = "CONSTRUCT { ?x ?p ?y } WHERE { ?x ?p ?y } LIMIT 1"; - HttpURLConnection con = SPARQLTestUtils.postConnection(SPARQL_ENDPOINT_URL, headers, query); + HttpURLConnection con = HTTPConnectionUtils.postConnection(SPARQL_ENDPOINT_URL, headers, query); BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); @@ -1949,7 +1949,7 @@ public void sparqlEndpointHtml() throws Exception { contentTypeHeader.add(TEXT_HTML); headers.add(contentTypeHeader); - HttpURLConnection con = SPARQLTestUtils.getConnection(SPARQL_ENDPOINT_URL, headers); + HttpURLConnection con = HTTPConnectionUtils.getConnection(SPARQL_ENDPOINT_URL, headers); BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); @@ -1978,7 +1978,7 @@ public void sparqlEndpointSelectRDFXML() throws Exception { String query = "select * where {?x ?p ?y} limit 1"; String urlQuery = SPARQL_ENDPOINT_URL + "?" + SPARQLTestUtils.generateSPARQLQueryParameters(query); - HttpURLConnection con = SPARQLTestUtils.getConnection(urlQuery, headers); + HttpURLConnection con = HTTPConnectionUtils.getConnection(urlQuery, headers); BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); @@ -2010,7 +2010,7 @@ public void sparqlEndpointSelectJSON() throws Exception { String query = "select * where {?x ?p ?y} limit 1"; String urlQuery = SPARQL_ENDPOINT_URL + "?" + SPARQLTestUtils.generateSPARQLQueryParameters(query); - HttpURLConnection con = SPARQLTestUtils.getConnection(urlQuery, headers); + HttpURLConnection con = HTTPConnectionUtils.getConnection(urlQuery, headers); BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); @@ -2042,7 +2042,7 @@ public void sparqlEndpointSelectCSV() throws Exception { String query = "select * where {?x ?p ?y} limit 1"; String urlQuery = SPARQL_ENDPOINT_URL + "?" + SPARQLTestUtils.generateSPARQLQueryParameters(query); - HttpURLConnection con = SPARQLTestUtils.getConnection(urlQuery, headers); + HttpURLConnection con = HTTPConnectionUtils.getConnection(urlQuery, headers); BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); @@ -2072,7 +2072,7 @@ public void sparqlEndpointSelectTSV() throws Exception { String query = "select * where {?x ?p ?y} limit 1"; String urlQuery = SPARQL_ENDPOINT_URL + "?" + SPARQLTestUtils.generateSPARQLQueryParameters(query); - HttpURLConnection con = SPARQLTestUtils.getConnection(urlQuery, headers); + HttpURLConnection con = HTTPConnectionUtils.getConnection(urlQuery, headers); BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); @@ -2102,7 +2102,7 @@ public void sparqlEndpointAskRDFXML() throws Exception { String query = "ASK {?x ?p ?y}"; String urlQuery = SPARQL_ENDPOINT_URL + "?" + SPARQLTestUtils.generateSPARQLQueryParameters(query); - HttpURLConnection con = SPARQLTestUtils.getConnection(urlQuery, headers); + HttpURLConnection con = HTTPConnectionUtils.getConnection(urlQuery, headers); BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); @@ -2134,7 +2134,7 @@ public void sparqlEndpointAskJSON() throws Exception { String query = "ASK {?x ?p ?y}"; String urlQuery = SPARQL_ENDPOINT_URL + "?" + SPARQLTestUtils.generateSPARQLQueryParameters(query); - HttpURLConnection con = SPARQLTestUtils.getConnection(urlQuery, headers); + HttpURLConnection con = HTTPConnectionUtils.getConnection(urlQuery, headers); BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); @@ -2165,7 +2165,7 @@ public void sparqlEndpointAskCSV() throws Exception { String query = "ASK {?x ?p ?y}"; String urlQuery = SPARQL_ENDPOINT_URL + "?" + SPARQLTestUtils.generateSPARQLQueryParameters(query); - HttpURLConnection con = SPARQLTestUtils.getConnection(urlQuery, headers); + HttpURLConnection con = HTTPConnectionUtils.getConnection(urlQuery, headers); BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); @@ -2195,7 +2195,7 @@ public void sparqlEndpointAskTSV() throws Exception { String query = "ASK {?x ?p ?y}"; String urlQuery = SPARQL_ENDPOINT_URL + "?" + SPARQLTestUtils.generateSPARQLQueryParameters(query); - HttpURLConnection con = SPARQLTestUtils.getConnection(urlQuery, headers); + HttpURLConnection con = HTTPConnectionUtils.getConnection(urlQuery, headers); BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); @@ -2225,7 +2225,7 @@ public void sparqlEndpointConstructRDFXML() throws Exception { String query = "construct {?x ?p ?y} where {?x ?p ?y} limit 1"; String urlQuery = SPARQL_ENDPOINT_URL + "?" + SPARQLTestUtils.generateSPARQLQueryParameters(query); - HttpURLConnection con = SPARQLTestUtils.getConnection(urlQuery, headers); + HttpURLConnection con = HTTPConnectionUtils.getConnection(urlQuery, headers); BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); @@ -2260,7 +2260,7 @@ public void sparqlEndpointDescribeRDFXML() throws Exception { String query = "describe ?x where {?x ?p ?y} limit 1"; String urlQuery = SPARQL_ENDPOINT_URL + "?" + SPARQLTestUtils.generateSPARQLQueryParameters(query); - HttpURLConnection con = SPARQLTestUtils.getConnection(urlQuery, headers); + HttpURLConnection con = HTTPConnectionUtils.getConnection(urlQuery, headers); BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); @@ -2295,7 +2295,7 @@ public void sparqlEndpointConstructTurtle() throws Exception { String query = "construct {?x ?p ?y} where {?x ?p ?y} limit 1"; String urlQuery = SPARQL_ENDPOINT_URL + "?" + SPARQLTestUtils.generateSPARQLQueryParameters(query); - HttpURLConnection con = SPARQLTestUtils.getConnection(urlQuery, headers); + HttpURLConnection con = HTTPConnectionUtils.getConnection(urlQuery, headers); BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); @@ -2330,7 +2330,7 @@ public void sparqlEndpointDescribeTurtle() throws Exception { String query = "describe ?x where {?x ?p ?y} limit 1"; String urlQuery = SPARQL_ENDPOINT_URL + "?" + SPARQLTestUtils.generateSPARQLQueryParameters(query); - HttpURLConnection con = SPARQLTestUtils.getConnection(urlQuery, headers); + HttpURLConnection con = HTTPConnectionUtils.getConnection(urlQuery, headers); BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); @@ -2375,7 +2375,7 @@ public void sparqlEndpointOneDefaultGraph() throws Exception { parameters.get(0).add("default-graph-uri"); parameters.get(0).add("http://example.com/nothing"); String urlQuery = SPARQL_ENDPOINT_URL + "?" + SPARQLTestUtils.generateSPARQLQueryParameters(query, parameters); - HttpURLConnection con = SPARQLTestUtils.getConnection(urlQuery, headers); + HttpURLConnection con = HTTPConnectionUtils.getConnection(urlQuery, headers); BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); @@ -2423,7 +2423,7 @@ public void sparqlEndpointMultipleDefaultGraphs() throws Exception { parameters.get(2).add("default-graph-uri"); parameters.get(2).add("http://example.com/B"); String urlQuery = SPARQL_ENDPOINT_URL + "?" + SPARQLTestUtils.generateSPARQLQueryParameters(query, parameters); - HttpURLConnection con = SPARQLTestUtils.getConnection(urlQuery, headers); + HttpURLConnection con = HTTPConnectionUtils.getConnection(urlQuery, headers); BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); @@ -2471,7 +2471,7 @@ public void sparqlEndpointOneNamedGraph() throws Exception { parameters.get(1).add("named-graph-uri"); parameters.get(1).add("http://example.com/A"); String urlQuery = SPARQL_ENDPOINT_URL + "?" + SPARQLTestUtils.generateSPARQLQueryParameters(query, parameters); - HttpURLConnection con = SPARQLTestUtils.getConnection(urlQuery, headers); + HttpURLConnection con = HTTPConnectionUtils.getConnection(urlQuery, headers); BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); @@ -2522,7 +2522,7 @@ public void sparqlEndpointNamedGraphsAmbiguous() throws Exception { parameters.get(1).add("named-graph-uri"); parameters.get(1).add("http://example.com/A"); String urlQuery = SPARQL_ENDPOINT_URL + "?" + SPARQLTestUtils.generateSPARQLQueryParameters(query, parameters); - HttpURLConnection con = SPARQLTestUtils.getConnection(urlQuery, headers); + HttpURLConnection con = HTTPConnectionUtils.getConnection(urlQuery, headers); BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); diff --git a/corese-server/src/test/java/fr/inria/corese/server/webservice/SPARQLEndpointUpdateTest.java b/corese-server/src/test/java/fr/inria/corese/server/webservice/SPARQLEndpointUpdateTest.java index a877272b2..b9f8cefa9 100644 --- a/corese-server/src/test/java/fr/inria/corese/server/webservice/SPARQLEndpointUpdateTest.java +++ b/corese-server/src/test/java/fr/inria/corese/server/webservice/SPARQLEndpointUpdateTest.java @@ -4,11 +4,16 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import java.io.BufferedReader; import java.io.File; import java.io.IOException; +import java.io.InputStreamReader; import java.net.HttpURLConnection; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import java.util.LinkedList; import java.util.List; + import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.junit.AfterClass; @@ -65,19 +70,201 @@ public static void shutdown() { * @throws Exception */ @Test - public void postUrlencodedUpdateTest() throws Exception { + public void postUrlencodedAcceptSPARQLXmlUpdateTest() throws Exception { + String query = "INSERT DATA { }"; + String body = "update=" + URLEncoder.encode(query, StandardCharsets.UTF_8.toString()); + List> headers = new LinkedList<>(); + List contentTypeHeader = new LinkedList<>(); + contentTypeHeader.add("Content-Type"); + contentTypeHeader.add("application/x-www-form-urlencoded"); + List acceptHeader = new LinkedList<>(); + acceptHeader.add("Accept"); + acceptHeader.add("application/sparql-results+xml"); + headers.add(contentTypeHeader); + headers.add(acceptHeader); + HttpURLConnection con = HTTPConnectionUtils.postConnection(SPARQL_ENDPOINT_URL, headers, body); + int responseCode = con.getResponseCode(); + BufferedReader in = new BufferedReader( + new InputStreamReader(con.getInputStream())); + String inputLine; + StringBuffer content = new StringBuffer(); + while ((inputLine = in.readLine()) != null) { + content.append(inputLine); + } + in.close(); + con.disconnect(); + + assertEquals(200, responseCode); + assertEquals("", content.toString()); + } + + /** + * Test the insertion of a triple in the server using a POST request with a URL-encoded body. + * @throws Exception + */ + @Test + public void postUrlencodedAcceptCSVUpdateTest() throws Exception { String query = "INSERT DATA { }"; - String body = SPARQLTestUtils.generateSPARQLUpdateParameters(query); + String body = "update=" + URLEncoder.encode(query, StandardCharsets.UTF_8.toString()); List> headers = new LinkedList<>(); List contentTypeHeader = new LinkedList<>(); contentTypeHeader.add("Content-Type"); contentTypeHeader.add("application/x-www-form-urlencoded"); + List acceptHeader = new LinkedList<>(); + acceptHeader.add("Accept"); + acceptHeader.add("text/csv"); + headers.add(contentTypeHeader); + headers.add(acceptHeader); + HttpURLConnection con = HTTPConnectionUtils.postConnection(SPARQL_ENDPOINT_URL, headers, body); + int responseCode = con.getResponseCode(); + + BufferedReader in = new BufferedReader( + new InputStreamReader(con.getInputStream())); + String inputLine; + StringBuffer content = new StringBuffer(); + while ((inputLine = in.readLine()) != null) { + content.append(inputLine); + } + in.close(); + con.disconnect(); + + assertEquals(200, responseCode); + assertEquals("", content.toString()); + } + + /** + * Test the insertion of a triple in the server using a POST request with a URL-encoded body. + * @throws Exception + */ + @Test + public void postUrlencodedAcceptJSONUpdateTest() throws Exception { + String query = "INSERT DATA { }"; + String body = "update=" + URLEncoder.encode(query, StandardCharsets.UTF_8.toString()); + List> headers = new LinkedList<>(); + List contentTypeHeader = new LinkedList<>(); + contentTypeHeader.add("Content-Type"); + contentTypeHeader.add("application/x-www-form-urlencoded"); + List acceptHeader = new LinkedList<>(); + acceptHeader.add("Accept"); + acceptHeader.add("application/sparql-results+json"); + headers.add(contentTypeHeader); + headers.add(acceptHeader); + HttpURLConnection con = HTTPConnectionUtils.postConnection(SPARQL_ENDPOINT_URL, headers, body); + int responseCode = con.getResponseCode(); + + BufferedReader in = new BufferedReader( + new InputStreamReader(con.getInputStream())); + String inputLine; + StringBuffer content = new StringBuffer(); + while ((inputLine = in.readLine()) != null) { + content.append(inputLine); + } + in.close(); + con.disconnect(); + + assertEquals(200, responseCode); + assertEquals("{\"head\": { \"vars\": []},\"results\": { \"bindings\": [{}] }}", content.toString()); + } + + /** + * Test the insertion of a triple in the server using a POST request with a URL-encoded body. + * @throws Exception + */ + @Test + public void postAcceptSPARQLXmlUpdateTest() throws Exception { + String query = "INSERT DATA { }"; + String body = query; + List> headers = new LinkedList<>(); + List contentTypeHeader = new LinkedList<>(); + contentTypeHeader.add("Content-Type"); + contentTypeHeader.add("application/sparql-update"); + List acceptHeader = new LinkedList<>(); + acceptHeader.add("Accept"); + acceptHeader.add("application/sparql-results+xml"); + headers.add(contentTypeHeader); + headers.add(acceptHeader); + HttpURLConnection con = HTTPConnectionUtils.postConnection(SPARQL_ENDPOINT_URL, headers, body); + int responseCode = con.getResponseCode(); + BufferedReader in = new BufferedReader( + new InputStreamReader(con.getInputStream())); + String inputLine; + StringBuffer content = new StringBuffer(); + while ((inputLine = in.readLine()) != null) { + content.append(inputLine); + } + in.close(); + con.disconnect(); + + assertEquals(200, responseCode); + assertEquals("", content.toString()); + } + + /** + * Test the insertion of a triple in the server using a POST request with a URL-encoded body. + * @throws Exception + */ + @Test + public void postAcceptCSVUpdateTest() throws Exception { + String query = "INSERT DATA { }"; + String body = query; + List> headers = new LinkedList<>(); + List contentTypeHeader = new LinkedList<>(); + contentTypeHeader.add("Content-Type"); + contentTypeHeader.add("application/sparql-update"); + List acceptHeader = new LinkedList<>(); + acceptHeader.add("Accept"); + acceptHeader.add("text/csv"); + headers.add(contentTypeHeader); + headers.add(acceptHeader); + HttpURLConnection con = HTTPConnectionUtils.postConnection(SPARQL_ENDPOINT_URL, headers, body); + int responseCode = con.getResponseCode(); + + BufferedReader in = new BufferedReader( + new InputStreamReader(con.getInputStream())); + String inputLine; + StringBuffer content = new StringBuffer(); + while ((inputLine = in.readLine()) != null) { + content.append(inputLine); + } + in.close(); + con.disconnect(); + + assertEquals(200, responseCode); + assertEquals("", content.toString()); + } + + /** + * Test the insertion of a triple in the server using a POST request with a URL-encoded body. + * @throws Exception + */ + @Test + public void postAcceptJSONUpdateTest() throws Exception { + String query = "INSERT DATA { }"; + String body = query; + List> headers = new LinkedList<>(); + List contentTypeHeader = new LinkedList<>(); + contentTypeHeader.add("Content-Type"); + contentTypeHeader.add("application/sparql-update"); + List acceptHeader = new LinkedList<>(); + acceptHeader.add("Accept"); + acceptHeader.add("application/sparql-results+json"); headers.add(contentTypeHeader); - HttpURLConnection con = SPARQLTestUtils.postConnection(SPARQL_ENDPOINT_URL, headers, body); + headers.add(acceptHeader); + HttpURLConnection con = HTTPConnectionUtils.postConnection(SPARQL_ENDPOINT_URL, headers, body); int responseCode = con.getResponseCode(); + + BufferedReader in = new BufferedReader( + new InputStreamReader(con.getInputStream())); + String inputLine; + StringBuffer content = new StringBuffer(); + while ((inputLine = in.readLine()) != null) { + content.append(inputLine); + } + in.close(); con.disconnect(); assertEquals(200, responseCode); + assertEquals("{\"head\": { \"vars\": []},\"results\": { \"bindings\": [{}] }}", content.toString()); } /** @@ -92,7 +279,7 @@ public void postUpdateTest() throws Exception { contentTypeHeader.add("Content-Type"); contentTypeHeader.add("application/sparql-update"); headers.add(contentTypeHeader); - HttpURLConnection con = SPARQLTestUtils.postConnection(SPARQL_ENDPOINT_URL, headers, query); + HttpURLConnection con = HTTPConnectionUtils.postConnection(SPARQL_ENDPOINT_URL, headers, query); int responseCode = con.getResponseCode(); con.disconnect(); @@ -122,7 +309,7 @@ public void usingNamedGraphUpdateTest() throws Exception { contentTypeFormUrlEncodedHeader.add("Content-Type"); contentTypeFormUrlEncodedHeader.add("application/sparql-update"); updateHeaders.add(contentTypeFormUrlEncodedHeader); - HttpURLConnection updateCon = SPARQLTestUtils.postConnection(SPARQL_ENDPOINT_URL, updateHeaders, updateQuery); + HttpURLConnection updateCon = HTTPConnectionUtils.postConnection(SPARQL_ENDPOINT_URL, updateHeaders, updateQuery); int updateResponseCode = updateCon.getResponseCode(); updateCon.disconnect(); diff --git a/corese-server/src/test/java/fr/inria/corese/server/webservice/SPARQLTestUtils.java b/corese-server/src/test/java/fr/inria/corese/server/webservice/SPARQLTestUtils.java index 1ef1e5f4e..a4e07e9f2 100644 --- a/corese-server/src/test/java/fr/inria/corese/server/webservice/SPARQLTestUtils.java +++ b/corese-server/src/test/java/fr/inria/corese/server/webservice/SPARQLTestUtils.java @@ -7,14 +7,10 @@ import java.io.BufferedReader; import java.io.ByteArrayInputStream; -import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; import java.net.HttpURLConnection; -import java.net.MalformedURLException; -import java.net.ProtocolException; -import java.net.URL; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; import java.util.ArrayList; @@ -37,82 +33,6 @@ public class SPARQLTestUtils { private static final String SERVER_URL = "http://localhost:8080/"; private static final String SPARQL_ENDPOINT_URL = SERVER_URL + "sparql"; - /** - * Get a connection to a server. - * - * @param url server URL - * @param headers HTTP headers - * @return - * @throws MalformedURLException - * @throws IOException - * @throws ProtocolException - */ - - public static HttpURLConnection methodConnection(String method, String url, List> headers) - throws IOException { - URL u = new URL(url); - HttpURLConnection con = (HttpURLConnection) u.openConnection(); - con.setRequestMethod(method); - con.setConnectTimeout(5000); - con.setReadTimeout(5000); - con.setInstanceFollowRedirects(true); - for (List header : headers) { - con.setRequestProperty(header.get(0), header.get(1)); - } - return con; - } - - public static HttpURLConnection getConnection(String url, List> headers) - throws IOException { - return methodConnection("GET", url, headers); - } - - public static HttpURLConnection postConnection(String url, List> headers, String body) - throws IOException { - HttpURLConnection con = methodConnection("POST", url, headers); - con.setDoOutput(true); - con.getOutputStream().write(body.getBytes()); - return con; - } - - public static HttpURLConnection postUrlencodedConnection(String url, List> headers, String body) - throws IOException { - List> newHeaders = new ArrayList<>(headers); - List contentTypeHeader = new ArrayList<>(); - contentTypeHeader.add("Content-Type"); - contentTypeHeader.add("application/x-www-form-urlencoded"); - newHeaders.add(contentTypeHeader); - return postConnection(url, newHeaders, body); - } - - public static HttpURLConnection putConnection(String url, List> headers, String body) - throws IOException { - HttpURLConnection con = methodConnection("PUT", url, headers); - con.setDoOutput(true); - con.getOutputStream().write(body.getBytes()); - return con; - } - - public static HttpURLConnection deleteConnection(String url, List> headers) - throws IOException { - return methodConnection("DELETE", url, headers); - } - - public static HttpURLConnection deleteConnection(String url) - throws IOException { - return deleteConnection( url, new ArrayList<>()); - } - - public static HttpURLConnection headConnection(String url, List> headers) - throws IOException { - return methodConnection("HEAD", url, headers); - } - - public static HttpURLConnection headConnection(String url) - throws IOException { - return headConnection(url, new ArrayList<>()); - } - public static String generateSPARQLQueryParameters(String query, List> optionalParameters) { return generateSPARQLParameters("query", query, optionalParameters); } @@ -166,7 +86,7 @@ public static Mappings sendSPARQLSelect(String query) throws Exception { headers.add(acceptHeader); String urlQuery = SPARQL_ENDPOINT_URL + "?" + SPARQLTestUtils.generateSPARQLQueryParameters(query); - HttpURLConnection con = SPARQLTestUtils.getConnection(urlQuery, headers); + HttpURLConnection con = HTTPConnectionUtils.getConnection(urlQuery, headers); BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); @@ -190,7 +110,7 @@ public static boolean sendSPARQLAsk(String query) throws Exception { headers.add(acceptHeader); String urlQuery = SPARQL_ENDPOINT_URL + "?" + SPARQLTestUtils.generateSPARQLQueryParameters(query); - HttpURLConnection con = SPARQLTestUtils.getConnection(urlQuery, headers); + HttpURLConnection con = HTTPConnectionUtils.getConnection(urlQuery, headers); BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); @@ -214,7 +134,7 @@ public static Graph sendSPARQLConstructDescribe(String query) throws Exception { headers.add(acceptHeader); String urlQuery = SPARQL_ENDPOINT_URL + "?" + SPARQLTestUtils.generateSPARQLQueryParameters(query); - HttpURLConnection con = SPARQLTestUtils.getConnection(urlQuery, headers); + HttpURLConnection con = HTTPConnectionUtils.getConnection(urlQuery, headers); BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream()));