public static String executeHTTPPostRequest(String serviceURL, String contentType, String acceptContentType, Map<String, String> formParameters) throws ClientProtocolException, IOException { // Prepare the message body parameters List<NameValuePair> formParams = new ArrayList<>(); for (Map.Entry<String, String> stringStringEntry : formParameters.entrySet()) { formParams.add(new BasicNameValuePair(stringStringEntry.getKey(), stringStringEntry.getValue())); } return executeHTTPPostRequest(serviceURL, contentType, acceptContentType, new UrlEncodedFormEntity(formParams, "UTF-8")); }
/** * This method clears all the statements from the given context * */ public static boolean clearContexts(String tripleStoreUrl, String graphUri) { if (tripleStoreUrl == null || tripleStoreUrl.isEmpty() || graphUri == null || graphUri.isEmpty()) { logger.error("Missing graphUri or tripleStoreUrl"); return false; } String responseString; try { String url = tripleStoreUrl + "/statements?context=" + URLEncoder.encode(graphUri, "UTF-8"); logger.info("Deleting from uri : " + url); responseString = HTTPUtil.executeHTTPDeleteRequest(url); logger.info("Response=" + responseString); return true; } catch (Exception e) { logger.error(e.getMessage(), e); } return false; }
public static boolean checkConnection(String url) { boolean retval = false; try { if (url.charAt(url.length() - 1) != '/') { url = url + "/"; } url = url + "size"; logger.info(url); String response = HTTPUtil.executeHTTPGetRequest(url, null); try { int i = Integer.parseInt(response.trim()); logger.debug("Connnection to repo : " + url + " Successful.\t Size : " + i); retval = true; } catch (Exception e) { logger.error("Could not parse size of repository query result."); } } catch (Exception e) { e.printStackTrace(); } return retval; }
public static String executeHTTPPostRequest(String serviceURL, String contentType, String acceptContentType, HttpEntity entity) throws ClientProtocolException, IOException { HttpPost httpPost = new HttpPost(serviceURL); httpPost.setEntity(entity); return invokeHTTPRequest(httpPost, contentType, acceptContentType); }
@Override public UpdateContainer doIt(Workspace workspace) throws CommandException { //save the preferences UpdateContainer c = new UpdateContainer(); try { Object json = HTTPUtil.executeAndParseHTTPGetService(serviceUrl, includeInputAttributes); logger.debug(json.toString()); Import imp = new JsonImport(json, worksheetName, workspace, encoding, -1); Worksheet wsht = imp.generateWorksheet(); c.add(new ImportServiceCommandPreferencesUpdate(serviceUrl, worksheetName)); c.add(new WorksheetListUpdate()); c.append(WorksheetUpdateFactory.createWorksheetHierarchicalAndCleaningResultsUpdates(wsht.getId(), SuperSelectionManager.DEFAULT_SELECTION, workspace.getContextId())); return c; } catch (Exception e) { logger.error("Error occured while creating worksheet from web-service: " + serviceUrl); return new UpdateContainer(new ErrorUpdate("Error creating worksheet from web-service")); } }
public static String executeHTTPPostRequest(String serviceURL, String contentType, String acceptContentType, String rawPostBodyData) throws ClientProtocolException, IOException { // Prepare the headers HttpPost httpPost = new HttpPost(serviceURL); httpPost.setEntity(new StringEntity(rawPostBodyData)); return invokeHTTPRequest(httpPost, contentType, acceptContentType); }
/** * Invokes a SPARQL query on the given Triple Store URL and returns the JSON * object containing the result. The content type of the result is * application/sparql-results+json. * * @param query * : SPARQL query * @param tripleStoreUrl * : SPARQL endpoint address of the triple store * @param acceptContentType * : The accept context type in the header * @param contextType * : * @return * @throws ClientProtocolException * @throws IOException * @throws JSONException */ public static String invokeSparqlQuery(String query, String tripleStoreUrl, String acceptContentType, String contextType) throws ClientProtocolException, IOException, JSONException { Map<String, String> formParams = new HashMap<>(); formParams.put("query", query); formParams.put("queryLn", "SPARQL"); String response = HTTPUtil.executeHTTPPostRequest(tripleStoreUrl, contextType, acceptContentType, formParams); if (response == null || response.isEmpty()) return null; return response; }
/** * This method fetches all the context from the given triplestore Url * */ public List<String> getContexts(String url) { if (url == null || url.isEmpty()) { url = defaultModelsRepoUrl; } url += "/contexts"; List<String> graphs = new ArrayList<>(); String responseString; try { responseString = HTTPUtil.executeHTTPGetRequest(url, "application/sparql-results+json"); if (responseString != null) { JSONObject models = new JSONObject(responseString); JSONArray values = models.getJSONObject("results") .getJSONArray("bindings"); int count = 0; while (count < values.length()) { JSONObject o = values.getJSONObject(count++); graphs.add(o.getJSONObject("contextID").getString("value")); } } } catch (Exception e) { logger.error(e.getMessage()); e.printStackTrace(); graphs = null; } return graphs; }
formparams.put("query", queryString); formparams.put("queryLn", "SPARQL"); String responseString = HTTPUtil.executeHTTPPostRequest( TripleStoreURL, null, "application/sparql-results+json", formparams);
formparams.put("update", queryString); String responseString = HTTPUtil.executeHTTPPostRequest( tripleStoreURL, null, mime_types.get(RDF_Types.N3.name()), formparams);
formparams.put("queryLn", "SPARQL"); String responseString = HTTPUtil.executeHTTPPostRequest( tripleStoreURL, null, "application/sparql-results+json", formparams);
public void deleteMappingFromTripleStore(String tripleStoreURL, String context, String mappingURI) throws KarmaException { testTripleStoreConnection(tripleStoreURL); tripleStoreURL = normalizeTripleStoreURL(tripleStoreURL) + "/statements"; try { StringBuilder query = new StringBuilder(); query.append("PREFIX km-dev:<http://isi.edu/integration/karma/dev#>\n"); query.append("PREFIX rr:<http://www.w3.org/ns/r2rml#>\n"); if (null != context && !context.trim().isEmpty()) { query.append("WITH "); formatURI(context, query); query.append("\n"); } query.append("DELETE { ?s ?p ?o } \n"); query.append("WHERE\n"); injectMapping(mappingURI, query); String queryString = query.toString(); logger.debug("query: " + queryString); Map<String, String> formparams = new HashMap<>(); formparams.put("update", queryString); String responseString = HTTPUtil.executeHTTPPostRequest( tripleStoreURL, null, mime_types.get(RDF_Types.N3.name()), formparams); System.out.println(responseString); } catch (Exception e) { logger.error(e.getMessage()); } }
formparams.put("queryLn", "SPARQL"); String responseString = HTTPUtil.executeHTTPPostRequest( tripleStoreURL, null, "application/sparql-results+json", formparams);
formparams.put("queryLn", "SPARQL"); String responseString = HTTPUtil.executeHTTPPostRequest( tripleStoreURL, null, "application/sparql-results+json", formparams);
formparams.put("queryLn", "SPARQL"); String responseString = HTTPUtil.executeHTTPPostRequest( TripleStoreURL, null, "application/sparql-results+json", formparams);
public String getMappingFromTripleStore(String tripleStoreURL, String context, String mappingURI) throws KarmaException { tripleStoreURL = normalizeTripleStoreURL(tripleStoreURL); testTripleStoreConnection(tripleStoreURL); context = normalizeURI(context); mappingURI = normalizeURI(mappingURI); try { StringBuilder query = new StringBuilder(); query.append("PREFIX km-dev:<http://isi.edu/integration/karma/dev#>\n"); query.append("PREFIX rr:<http://www.w3.org/ns/r2rml#>\n"); query.append("CONSTRUCT { ?s ?p ?o }\n"); injectContext(context, query); injectMapping(mappingURI, query); String queryString = query.toString(); logger.debug("query: " + queryString); Map<String, String> formparams = new HashMap<>(); formparams.put("query", queryString); formparams.put("queryLn", "SPARQL"); String responseString = HTTPUtil.executeHTTPPostRequest( tripleStoreURL, null, mime_types.get(RDF_Types.N3.name()), formparams); if (responseString != null) { return responseString; } } catch (Exception e) { logger.error(e.getMessage()); } return ""; }
formparams.put("queryLn", "SPARQL"); String responseString = HTTPUtil.executeHTTPPostRequest( tripleStoreURL, null, "application/sparql-results+json", formparams);
formparams.put("queryLn", "SPARQL"); String responseString = HTTPUtil.executeHTTPPostRequest( tripleStoreURL, null, "application/sparql-results+json", formparams);
formparams.put("queryLn", "SPARQL"); String responseString = HTTPUtil.executeHTTPPostRequest( tripleStoreURL, null, "application/sparql-results+json", formparams);
String reqResponse = HTTPUtil.executeHTTPPostRequest(cleaningServiceURL, null, null, formParams);