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
|
import javax.servlet.http.HttpUtils;
|
13
|
|
14
|
/**
|
15
|
* A metadata catalog server implemented as a Java Servlet
|
16
|
*/
|
17
|
public class MetaCatServlet extends HttpServlet {
|
18
|
|
19
|
private ServletConfig config = null;
|
20
|
private ServletContext context = null;
|
21
|
DBSimpleQuery queryobj = null;
|
22
|
static String user = "jones";
|
23
|
static String password = "your-pw-goes-here";
|
24
|
static String defaultDB = "jdbc:oracle:thin:@localhost:1521:test";
|
25
|
|
26
|
public void init( ServletConfig config ) throws ServletException {
|
27
|
try {
|
28
|
super.init( config );
|
29
|
this.config = config;
|
30
|
this.context = config.getServletContext();
|
31
|
|
32
|
try {
|
33
|
queryobj = new DBSimpleQuery(user, password, defaultDB);
|
34
|
} catch (Exception e) {
|
35
|
}
|
36
|
} catch ( ServletException ex ) {
|
37
|
throw ex;
|
38
|
}
|
39
|
}
|
40
|
|
41
|
public void doGet (HttpServletRequest request, HttpServletResponse response)
|
42
|
throws ServletException, IOException {
|
43
|
|
44
|
PrintWriter out;
|
45
|
|
46
|
// Get the parameters from the form
|
47
|
String querystring = request.getQueryString();
|
48
|
Hashtable params = HttpUtils.parseQueryString(querystring);
|
49
|
String[] query = (String[])params.get("query");
|
50
|
|
51
|
// Run the query
|
52
|
Hashtable nodelist = queryobj.findRootNodes(query[0]);
|
53
|
|
54
|
// set content type and other response header fields first
|
55
|
response.setContentType("text/xml");
|
56
|
|
57
|
// then write the data of the response
|
58
|
out = response.getWriter();
|
59
|
|
60
|
// Print the reulting root nodes
|
61
|
long nodeid;
|
62
|
out.println("<?xml version=\"1.0\"?>\n");
|
63
|
out.println("<resultset>\n");
|
64
|
out.println(" <query>" + query[0] + "</query>");
|
65
|
Enumeration rootlist = nodelist.keys();
|
66
|
while (rootlist.hasMoreElements()) {
|
67
|
nodeid = ((Long)rootlist.nextElement()).longValue();
|
68
|
out.println(" <nodeid>" + nodeid + "</nodeid>");
|
69
|
}
|
70
|
out.println("</resultset>");
|
71
|
|
72
|
out.close();
|
73
|
}
|
74
|
|
75
|
public void doPost( HttpServletRequest request, HttpServletResponse response)
|
76
|
throws ServletException, IOException {
|
77
|
|
78
|
PrintWriter out;
|
79
|
// set content type and other response header fields first
|
80
|
response.setContentType("text/html");
|
81
|
|
82
|
// then write the data of the response
|
83
|
out = response.getWriter();
|
84
|
out.println("POST detected");
|
85
|
out.close();
|
86
|
}
|
87
|
|
88
|
}
|