Skip navigation

Hereby, I just provide a more convenient way to access and process HTTP data. Now I illustrate some use cases in esProc, an innovative data processing language.

t4.jpg

In this example, a servlet provides outward query of employee information in json format. Servlet accesses employee table in the database and saves employee information as follows:

EID   NAME       SURNAME GENDER   STATE        BIRTHDAY        HIREDATE     DEPT         SALARY

1       Rebecca   Moore           F            California   1974-11-20        2005-03-11        R&D           7000

2       Ashley      Wilson          F            New York   1980-07-19       2008-03-16       Finance       11000

3       Rachel      Johnson        F            New Mexico1970-12-17       2010-12-01      Sales           9000

4       Emily         Smith          F            Texas        1985-03-07        2006-08-15       HR              7000

5       Ashley      Smith           F            Texas        1975-05-13        2004-07-30       R&D            16000

6       Matthew   Johnson        M           California     1984-07-07       2005-07-07       Sales           11000

7       Alexis        Smith          F            Illinois         1972-08-16       2002-08-16       Sales           9000

8       Megan      Wilson          F           California     1979-04-19       1984-04-19      Marketing      11000

9       Victoria     Davis            F           Texas         1983-12-07        2009-12-07       HR              3000

doGet function of servlet receives employee id strings of json format, queries corresponding employee information through the database and generates employee information list in json format and then returns it. Process of reading the database and generating employee information is omitted in the following code:

protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

         // TODO Auto-generated method stub

         String inputString=(String) req.getParameter("input");

         //inputString  input value is"[{EID:8},{EID:32},{EID:44}]";

         if (inputString==null) inputString="";

         String outputString ="";

     

         {...}//code for querying the database through inputString and generating outputSring is omitted here

            // the generated outputString

//"[{EID:8,NAME:"Megan",SURNAME:"Wilson",GENDER:"F",STATE:\...";

         resp.getOutputStream().println(outputString);

         resp.setContentType("text/json; charset=GBK");

}

 

The following code can be used for esProc to access this http servlet:

HTTP1.jpg

A1 Define the input parameter to be submitted to servlet, i.e. the employee id list in json format.

A2 Define httpfile objects, URL is http://localhost:8080/demo/testServlet?input=[{EID:8},{EID:32},{EID:44}].

A3Import A2, the result returned by httpfile objects.

A4Parse by rows the json format information of each employee, and create a sequence.

A5Compute on the table sequence in A4 and combine SURNAME and NAME into FULLNAME.

A6Export results of A5 to a text file.