Show Table of Contents
9.6. Ad-Hoc REST Services
Apart from the explicitly defined procedure based rest services, the generated jax-rs war file will also implicitly include a special rest based service under URI "/query" that can take any XML or JSON producing SQL as parameter and expose the results of that query as result of the service. This service is defined with "POST", accepting a Form Parameter named "sql". For example, after you deploy the VDB defined in above example, you can issue a HTTP POST call as
http://localhost:8080/sample_1/view/query
sql=SELECT XMLELEMENT(NAME "rows",XMLAGG(XMLELEMENT(NAME "row", XMLFOREST(e1, e2)))) AS xml_out FROM PM1.G1
A sample HTTP Request from Java can be made like below:
public static String httpCall(String url, String method, String params) throws Exception {
StringBuffer buff = new StringBuffer();
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
connection.setRequestMethod(method);
connection.setDoOutput(true);
if (method.equalsIgnoreCase("post")) {
OutputStreamWriter wr = new OutputStreamWriter(connection.getOutputStream());
wr.write(params);
wr.flush();
}
BufferedReader serverResponse = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String line;
while ((line = serverResponse.readLine()) != null) {
buff.append(line);
}
return buff.toString();
}
public static void main(String[] args) throws Exception {
String params = URLEncoder.encode("sql", "UTF-8") + "=" + URLEncoder.encode("SELECT XMLELEMENT(NAME "rows",XMLAGG(XMLELEMENT(NAME "row", XMLFOREST(e1, e2)))) AS xml_out FROM PM1.G1", "UTF-8");
httpCall("http://localhost:8080/sample_1/view/query", "POST", params);
}

Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.