开发者

Best way to web application return XML document basis on database data (USED BY VXML)?

开发者 https://www.devze.com 2023-02-28 06:28 出处:网络
I have to write VXML application which will be able to access to database. The VXML standard let cause external url with parameters but in response I have to return generated VXML document contains da

I have to write VXML application which will be able to access to database. The VXML standard let cause external url with parameters but in response I have to return generated VXML document contains data get out from database and other VXML tags.

Could you tell me which framework will be the best to do that (JSF, pure servlets with hibernate or something other, REST)? Please advise me which method will be simplest to create Java web application to that d开发者_开发知识库estination.

PS. I wanted to use JSF (with JPA), but I I wonder if there is a possibility to call JSF Managed Bean action with parameters from that managed bean by GET Http Request.


You can use a combination of JAX-RS, JPA, and JAXB for this use case. You can check out an example I posted to my blog:

  • Part 1 - The Database
  • Part 2 - Mapping the Database to JPA Entities
  • Part 3 - Mapping JPA entities to XML (using JAXB)
  • Part 4 - The RESTful Service
  • Part 5 - The Client


If you wish simply database connection for vxml, Try use the subdialog tag and call servlet(or JSP).

[Server VXML JSP (URL=http://hostname:port/app_name/sample.jsp)]

<?xml version="1.0" encoding="UTF-8" ?>
<%@ page language="java" contentType="application/voicexml+xml; charset=UTF-8"  pageEncoding="UTF-8" %>
<!DOCTYPE vxml PUBLIC "-//W3C//DTD VOICEXML 2.1//EN" "http://www.w3.org/TR/voicexml21/vxml.dtd">
<%@ page import="import java.sql.*" %>
<vxml version="2.1" xmlns="http://www.w3.org/2001/vxml">
<script><![CDATA[
<%
    out.println("var myObject = new Array();");

    // Set character encoding
    request.setCharacterEncoding("UTF-8");

    // Get VXML parameter.
    String input1 = request.getParameter("input1");
    String input2 = request.getParameter("input2");
    String input3 = request.getParameter("input3");

    ResultSet rs = null:

    //
    // Execute SQL
    //

    int i = 0;
    while(rs.next()) {
        String value1 = rs.getString("column1")
        String value2 = rs.getString("column2")
        String value3 = rs.getString("column3")

        out.println("myObject[" + i + "] = new Object();");
        out.println("myObject[" + i + "].column1 = " + value1 + ";");
        out.println("myObject[" + i + "].column2 = " + value2 + ";");
        out.println("myObject[" + i + "].column3 = " + value3 + ";");

        i++;
    }
    rs.close();

%>
]]></script>
<form id="response">
    <block>
        <return namelist="myObject" />
    </block>
</form>
</vxml>

[Cliant VXML Text]

<form id="database_connection_sample">
    <subdialog 
            name="database_connection_subdialog"  
            method="post" 
            srcexpr="'http://hostname:port/app_name/sample.jsp'"
            maxage="0"
            maxstale="0"
            namelist="input1 input2 input3">
        <filled>
            <!-- Get Result Object -->
            <assign name="resultObject" expr="database_connection_subdialog.myObject" />
        </filled>
    </subdialog>
    <catch event="error">
        <!-- Error Handling-->
    </catch>
    <block>
        <goto next="#next_form" />
    </block>
</form>

Getting database value expression exemple -> "resultObject[0].column1"

0

精彩评论

暂无评论...
验证码 换一张
取 消