1
|
import java.io.PrintWriter;
|
2
|
import java.io.IOException;
|
3
|
import java.util.Enumeration;
|
4
|
import java.util.Hashtable;
|
5
|
|
6
|
import javax.servlet.ServletConfig;
|
7
|
import javax.servlet.ServletContext;
|
8
|
import javax.servlet.ServletException;
|
9
|
import javax.servlet.http.HttpServlet;
|
10
|
import javax.servlet.http.HttpServletRequest;
|
11
|
import javax.servlet.http.HttpServletResponse;
|
12
|
|
13
|
/**
|
14
|
* A metadata catalog server implemented as a Java Servlet
|
15
|
*/
|
16
|
public class MetaCatServlet extends HttpServlet {
|
17
|
|
18
|
private ServletConfig config = null;
|
19
|
private ServletContext context = null;
|
20
|
DBSimpleQuery queryobj = null;
|
21
|
static String user = "jones";
|
22
|
static String password = "your-pw-goes-here";
|
23
|
static String defaultDB = "jdbc:oracle:thin:@localhost:1521:test";
|
24
|
|
25
|
public void init( ServletConfig config ) throws ServletException {
|
26
|
try {
|
27
|
super.init( config );
|
28
|
this.config = config;
|
29
|
this.context = config.getServletContext();
|
30
|
|
31
|
try {
|
32
|
queryobj = new DBSimpleQuery(user, password, defaultDB);
|
33
|
} catch (Exception e) {
|
34
|
}
|
35
|
} catch ( ServletException ex ) {
|
36
|
throw ex;
|
37
|
}
|
38
|
}
|
39
|
|
40
|
public void doGet (HttpServletRequest request, HttpServletResponse response)
|
41
|
throws ServletException, IOException {
|
42
|
|
43
|
PrintWriter out;
|
44
|
String query = "Value1";
|
45
|
|
46
|
// Run the query
|
47
|
Hashtable nodelist = queryobj.findRootNodes(query);
|
48
|
|
49
|
// set content type and other response header fields first
|
50
|
response.setContentType("text/xml");
|
51
|
|
52
|
// then write the data of the response
|
53
|
out = response.getWriter();
|
54
|
|
55
|
// Print the reulting root nodes
|
56
|
long nodeid;
|
57
|
out.println("<?xml version=\"1.0\"?>\n");
|
58
|
out.println("<resultset>\n");
|
59
|
Enumeration rootlist = nodelist.keys();
|
60
|
while (rootlist.hasMoreElements()) {
|
61
|
nodeid = ((Long)rootlist.nextElement()).longValue();
|
62
|
out.println(" <nodeid>" + nodeid + "</nodeid>");
|
63
|
}
|
64
|
out.println("</resultset>");
|
65
|
|
66
|
out.close();
|
67
|
}
|
68
|
|
69
|
public void doPost( HttpServletRequest req, HttpServletResponse res )
|
70
|
throws ServletException, IOException {
|
71
|
}
|
72
|
|
73
|
}
|