10.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
Copy to Clipboard Toggle word wrap
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);
        }
Copy to Clipboard Toggle word wrap
Back to top
Red Hat logoGithubredditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust. Explore our recent updates.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

Theme

© 2025 Red Hat