[Idrs-commit] CVS: Idrs/dev/src/net/sourceforge/idrs/core/servlet IDRSServlet.java,1.7,1.8
Brought to you by:
bigman921
|
From: Marc B. <big...@us...> - 2002-01-23 21:33:56
|
Update of /cvsroot/idrs/Idrs/dev/src/net/sourceforge/idrs/core/servlet
In directory usw-pr-cvs1:/tmp/cvs-serv9091/net/sourceforge/idrs/core/servlet
Modified Files:
IDRSServlet.java
Log Message:
Added line by line comments
Index: IDRSServlet.java
===================================================================
RCS file: /cvsroot/idrs/Idrs/dev/src/net/sourceforge/idrs/core/servlet/IDRSServlet.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** IDRSServlet.java 2002/01/18 15:26:18 1.7
--- IDRSServlet.java 2002/01/23 21:33:52 1.8
***************
*** 57,70 ****
poolInfo = new PoolInfo();
try {
init = new Init(svg);
app = init.getApplication();
toLower = init.toLower();
IDRSName = svg.getServletName();
! //insworld only
! app.put("IDRS_INIT", init);
resetThread = new DocReset(init);
resetThread.start();
}
catch (Exception e) {
}
super.init(svg);
--- 57,77 ----
poolInfo = new PoolInfo();
try {
+ //The Init class loads all of the configuration information from the web.xml file and
+ //loads all reports into the pooling system
init = new Init(svg);
+
+ //retrieves the serverside application object from the init object
app = init.getApplication();
+
+ //determines if all sql statements and fields should be lowercase
toLower = init.toLower();
IDRSName = svg.getServletName();
!
! //the reset thread listens for reset requests to reload specific rml pages
resetThread = new DocReset(init);
resetThread.start();
}
catch (Exception e) {
+ //this is admitadly a bad idea
}
super.init(svg);
***************
*** 79,102 ****
ERRORS: doc_Name, doc_ID don't exist
*/
! public void preProc(HttpServletRequest req, HttpServletResponse resp)
! throws ServletException {
try {
! System.out.println(
! "$%$%$%$%$% idrsFirstLogin: "
! + req.getSession().getAttribute("idrsFirstLogin"));
!
! //long start = System.currentTimeMillis();
! System.out.println("**Header**");
! Enumeration e = req.getHeaderNames();
! String n;
! while (e.hasMoreElements()) {
! n = (String) e.nextElement();
! System.out.println(n + " = " + req.getHeader(n));
! }
RequestWrapper rap;
PoolInfo poolInfo = new PoolInfo();
Vector dbNames = new Vector();
if (req.getAttribute("fetchAttr") == null) {
-
rap = new ReqReq(req);
}
--- 86,104 ----
ERRORS: doc_Name, doc_ID don't exist
*/
! public void preProc(HttpServletRequest req, HttpServletResponse resp) throws ServletException {
try {
! //a request wrapper is needed in cases of forwarding where parameters are passed as "attributes"
! //and retrieved via getAttribute as oppossed to getParameter
RequestWrapper rap;
+
+ //A pool info structure is used to store the current ids of the pooled objects retrieved
PoolInfo poolInfo = new PoolInfo();
+
+ //A list of databases retrieved for this document
Vector dbNames = new Vector();
+
+ //we need to determine if this is a forward, and if we need to use getAttribute or getParameter
+ //to retrieve paramters
if (req.getAttribute("fetchAttr") == null) {
rap = new ReqReq(req);
}
***************
*** 105,114 ****
}
! System.out.println("doc_Name IS " + rap.getParameter("doc_Name"));
req.getSession().setAttribute("idrsFirstLogin", "1");
try {
this.procIDRS(req, resp, rap, dbNames, poolInfo);
}
catch (Exception ee) {
init.logEvent("Error", ee);
PrintWriter out = resp.getWriter();
--- 107,120 ----
}
!
req.getSession().setAttribute("idrsFirstLogin", "1");
+
try {
+ //try processesing the request
this.procIDRS(req, resp, rap, dbNames, poolInfo);
}
catch (Exception ee) {
+ //an error has occurred, lets recover and print a generice error response
+ //this area needs serious work
init.logEvent("Error", ee);
PrintWriter out = resp.getWriter();
***************
*** 119,122 ****
--- 125,129 ----
}
finally {
+ //wether or not an error occurred anywhere, we need to return pooled resources
if (poolInfo.sysConID != -1)
init.returnSysCon(poolInfo.sysConID);
***************
*** 129,135 ****
}
req.setAttribute("fetchAddr", null);
- //System.out.println("Request Processed");
- //long end = System.currentTimeMillis();
- //System.out.println("time : " + (end-start));
}
catch (Exception e) {
--- 136,139 ----
***************
*** 162,172 ****
ERRORS: Conn doesn't exist, System maxed out
*/
! private boolean getConns(
! IDRSSecurity secure,
! HashMap conns,
! Vector dbNames,
! Connection sysCon)
! throws Exception {
!
String conString;
JDBCPool brkr;
--- 166,170 ----
ERRORS: Conn doesn't exist, System maxed out
*/
! private boolean getConns(IDRSSecurity secure, HashMap conns, Vector dbNames, Connection sysCon) throws Exception {
String conString;
JDBCPool brkr;
***************
*** 175,188 ****
int i;
boolean found = false;
Object[] Conns = secure.getConns();
Connection tmpCon;
PooledObject po = null;
! //synchronized (dbs) {
! //if (this.numDbs != 0) {
!
for (i = 0; i < Conns.length; i++) {
found = false;
conString = (String) Conns[i];
!
if ((!found) && (conString.equals(init.getAppDBName()))) {
tmpCon = sysCon;
--- 173,189 ----
int i;
boolean found = false;
+
+ //retrieve a list of connection needed by page
Object[] Conns = secure.getConns();
Connection tmpCon;
+
PooledObject po = null;
!
! //we need to loop through all requested connections and retrieve whats needed
for (i = 0; i < Conns.length; i++) {
found = false;
conString = (String) Conns[i];
!
! //if the connection used by the idrs for wuthentication and pages is needed by the page we'll retrieve it for use
if ((!found) && (conString.equals(init.getAppDBName()))) {
tmpCon = sysCon;
***************
*** 190,193 ****
--- 191,195 ----
conns.put(conString, sysCon);
}
+ //retrieve a connection pool and a connection from it
else {
brkr = init.getDBPool(conString);
***************
*** 204,207 ****
--- 206,210 ----
//there are no more connections to use and waiting has timed out
+ //something has gone wrong and we need to exit return all resources
connsGotten = conns.keySet().iterator();
while (connsGotten.hasNext()) {
***************
*** 218,221 ****
--- 221,226 ----
return false;
}
+
+ //everything is ok, add the connection to the list of retrieved connections
if (found && po != null) {
dbNames.add(new Integer(po.getID()));
***************
*** 225,233 ****
}
return true;
! //}
! //return true;
! //end loadConns
! //}
}
--- 230,237 ----
}
+
+ //evrything worked
return true;
!
}
***************
*** 241,274 ****
JDBCPool brkr;
Connection tmpCon;
! //Object[] Conns = secure.getConns();
int i = 0;
! //synchronized (dbs) {
! //if (numDbs != 0) {
!
! //conns = rep.getConns();
! //conns = null; //the connection will be returned by name, not object
!
for (i = 0; i < Conns.length; i++) {
conString = (String) Conns[i];
if (!conString.equals(init.getAppDBName())) {
brkr = (JDBCPool) init.getDBPool(conString);
! /*if (brkr == null) {
! System.out.println("Broker Aint THERE!");
! while (brkr == null) {
! wait();
! brkr = (JDBCPool) dbs.remove(conString);
! }
! notifyAll();
!
! }*/
!
brkr.freeConnection(((Integer) dbNames.elementAt(i)).intValue());
}
i++;
! //dbs.put(conString,brkr);
! //notifyAll();
}
! //}
! //}
}
--- 245,267 ----
JDBCPool brkr;
Connection tmpCon;
!
int i = 0;
!
! //loop through all connections and return them
for (i = 0; i < Conns.length; i++) {
+ //retrieve the name of the connection
conString = (String) Conns[i];
+
+ //if it's not an app db, return it
if (!conString.equals(init.getAppDBName())) {
+ //retrieve the pool
brkr = (JDBCPool) init.getDBPool(conString);
! //Free the connection
brkr.freeConnection(((Integer) dbNames.elementAt(i)).intValue());
}
i++;
!
}
!
}
***************
*** 284,287 ****
--- 277,283 ----
IDRSRep rep;
PooledObject po;
+
+ //determine if we know the id or the name
+ //retrive the pool based on the id or name
if (name != null)
po = init.getReport(name).checkOut(0);
***************
*** 289,293 ****
--- 285,292 ----
po = init.getReport(id).checkOut(0);
+ //retrieve report
rep = (IDRSRep) po.getValue();
+
+ //reset the header, where all of the information for each request is stored
rep.getHead().reset();
***************
*** 306,312 ****
protected DocInfo getDocInfo(int id, String name) {
DocInfo doc;
- System.out.println("doc_Name=" + name);
if (name != null) {
- System.out.println("DocName:" + name);
doc = init.getDocInfo(name);
}
--- 305,309 ----
***************
*** 332,347 ****
String param;
String db;
IDRSHead head = rep.getHead();
Object[] Params = secure.getParamNames();
for (int i = 0; i < Params.length; i++) {
-
param = (String) Params[i];
db = param.substring(0, param.indexOf("_"));
valName = param.substring(param.indexOf("_") + 1);
- System.out.println("db:" + db);
if (!db.equalsIgnoreCase(currentDB)) {
-
currentDB = db;
}
--- 329,350 ----
String param;
String db;
+
+ //retrieve the report header
IDRSHead head = rep.getHead();
+
+ //retrieve the list of parameter names
Object[] Params = secure.getParamNames();
+
+ //loop through all parameter names and add them to the correct portion of the header
for (int i = 0; i < Params.length; i++) {
param = (String) Params[i];
+ //determine what area of the header "db" is being added to
db = param.substring(0, param.indexOf("_"));
+
+ //determine the value
valName = param.substring(param.indexOf("_") + 1);
if (!db.equalsIgnoreCase(currentDB)) {
currentDB = db;
}
***************
*** 379,385 ****
}
else {
-
head.add(db, valName, req.getParameter(param));
-
}
}
--- 382,386 ----
***************
*** 407,411 ****
String docName = "";
String groups;
! //leave
try {
docID = Integer.parseInt(rap.getParameter("doc_ID"));
--- 408,414 ----
String docName = "";
String groups;
!
!
! //try retrieving the name or id of the report lo load
try {
docID = Integer.parseInt(rap.getParameter("doc_ID"));
***************
*** 415,418 ****
--- 418,422 ----
}
+ //initialize some information about the report
poolInfo.docID = docID;
poolInfo.docName = docName;
***************
*** 421,428 ****
String user = "", pass = "";
! //end leave
int repName = -1;
! //leave
try {
user = (String) session.getValue("user");
--- 425,433 ----
String user = "", pass = "";
!
int repName = -1;
!
! //try to retrieve the username and password from first the session and then the request object
try {
user = (String) session.getValue("user");
***************
*** 435,444 ****
}
catch (Exception E) {
! //resp.getWriter().println("<H1>Error</H1>");
! //resp.getWriter().println(E + "\n" + E.getMessage() + "\n" + E.toString());
throw E;
! //quit = true;
}
! //end leave
String IDRSLocation = IDRSName;
--- 440,448 ----
}
catch (Exception E) {
!
throw E;
!
}
!
String IDRSLocation = IDRSName;
***************
*** 451,465 ****
Connection con;
- //Vector dbNames = new Vector();
HashMap conns;
String report;
PooledObject po;
if (!quit) {
po = init.getSysCon();
! System.out.println("PO:" + po);
if (po == null) {
//we don't have a connection to the database
-
resp.getWriter().println("<h1>The server is busy, please try again later</h1>");
resp.getWriter().close();
--- 455,469 ----
Connection con;
HashMap conns;
String report;
PooledObject po;
+ //so far, no errors
if (!quit) {
+ //retrieve the system connection
po = init.getSysCon();
!
if (po == null) {
//we don't have a connection to the database
resp.getWriter().println("<h1>The server is busy, please try again later</h1>");
resp.getWriter().close();
***************
*** 467,482 ****
throw new Exception("Server Busy");
}
con = (Connection) po.getValue();
sysConID = po.getID();
poolInfo.sysConID = sysConID;
sysConName = con.toString();
secure = new IDRSSecurity(getDocInfo(docID, docName), user, pass, con, toLower);
String conString = "";
- //DbConnectionBroker brkr;
Connection tmpCon;
//dbCache = (Hashtable) session.getAttribute("DbCache");
! session.removeAttribute("DbCache");
IDRSScriptLanguage idrss;
int idrssName;
--- 471,490 ----
throw new Exception("Server Busy");
}
+
+ //retrieve authentication connection
con = (Connection) po.getValue();
sysConID = po.getID();
poolInfo.sysConID = sysConID;
sysConName = con.toString();
+
+ //initialize a security object for retrieving all report information
secure = new IDRSSecurity(getDocInfo(docID, docName), user, pass, con, toLower);
String conString = "";
Connection tmpCon;
//dbCache = (Hashtable) session.getAttribute("DbCache");
! //session.removeAttribute("DbCache");
!
IDRSScriptLanguage idrss;
int idrssName;
***************
*** 484,487 ****
--- 492,496 ----
boolean isSecur;
+ //attempt authentication of user for current page
try {
isSecur = secure.checkOK();
***************
*** 489,493 ****
}
catch (Exception securException) {
! //do nothing
secure.close();
accessDenied(req, resp);
--- 498,502 ----
}
catch (Exception securException) {
! //user is not authentic, deny access
secure.close();
accessDenied(req, resp);
***************
*** 495,503 ****
--- 504,520 ----
}
+ //is authentic?
if (secure.checkOK()) {
+ //retrieve connection list
poolInfo.Conns = secure.getConns();
+
+ //store username and password
req.getSession().putValue("user", user);
req.getSession().putValue("pass", pass);
+
+ //retrieve valid groups
groups = secure.getGroups();
+
+ //if the password isn't ok
if (!secure.passwordOK()) {
try {
***************
*** 512,523 ****
String buffer = "";
conns = new HashMap();
if (getConns(secure, conns, dbNames, con)) {
try {
!
po = getReport(docID, docName);
rep = (IDRSRep) po.getValue();
reportName = po.getID();
poolInfo.reportName = reportName;
addVars(secure, rap, rep);
//rep.setCache(dbCache);
--- 529,544 ----
String buffer = "";
conns = new HashMap();
+
+ //retrieve connections
if (getConns(secure, conns, dbNames, con)) {
try {
! //retrieve the report
po = getReport(docID, docName);
rep = (IDRSRep) po.getValue();
reportName = po.getID();
poolInfo.reportName = reportName;
+
+ //add the parameters
addVars(secure, rap, rep);
//rep.setCache(dbCache);
***************
*** 526,533 ****
--- 547,557 ----
try {
+ //retrieve a scripting context
po = init.getScriptContext();
idrss = (IDRSScriptLanguage) po.getValue();
idrssName = po.getID();
poolInfo.idrssName = idrssName;
+
+ //initialize the report header with parameters, server side objects, connections and script contexts
rep.getHead().init(
conns,
***************
*** 541,551 ****
idrss,
new UserInfo(groups, secure.getUserID(), secure.getUserName()));
! //resp.getWriter().print("");
! //resp.getWriter().println(rep.buildReport());
rep.getHead().setSendToClient(true);
buffer = rep.buildReport();
! System.out.println("Buffer:");
if (rep.getHead().getSendToClient()) {
! System.out.println("Printing IT");
resp.setContentType("text/html");
resp.getWriter().println(buffer);
--- 565,578 ----
idrss,
new UserInfo(groups, secure.getUserID(), secure.getUserName()));
!
! //send content to the client
rep.getHead().setSendToClient(true);
+
+ //build the report
buffer = rep.buildReport();
!
! //if we want to send to the client, send it
if (rep.getHead().getSendToClient()) {
! //set the content type
resp.setContentType("text/html");
resp.getWriter().println(buffer);
***************
*** 573,577 ****
//session.setAttribute("DbCache",dbCache);
!
secure.close();
--- 600,605 ----
//session.setAttribute("DbCache",dbCache);
!
! //close the security object
secure.close();
***************
*** 594,601 ****
if (!quit) {
secure.close();
- //init.returnSysCon(sysConID);
-
- //resp.getWriter().println("<H1>Access Denied</H1>");
- //resp.getWriter().println("<H2>Hit Backspace and re-enter your username and password</H2>");
rep = null;
secure = null;
--- 622,625 ----
***************
*** 607,612 ****
else {
! //resp.getWriter().println("<H1>Access Denied</H1>");
! //resp.getWriter().println("<H2>Hit Backspace and re-enter your username and password</H2>");
rep = null;
secure = null;
--- 631,635 ----
else {
!
rep = null;
secure = null;
***************
*** 620,629 ****
private void returnReport(int rep, String docName) throws Exception {
IDRSPool pool = init.getReport(docName);
pool.checkIn(rep);
}
public void destroy() {
!
super.destroy();
}
--- 643,655 ----
private void returnReport(int rep, String docName) throws Exception {
+ //retrieve the pool
IDRSPool pool = init.getReport(docName);
+
+ //return the report
pool.checkIn(rep);
}
public void destroy() {
! //de-initalization code needs to be written, we should clean up after our selves
super.destroy();
}
***************
*** 636,644 ****
public void accessDenied(HttpServletRequest req, HttpServletResponse resp)
throws Exception {
! //first invalidate the session
!
resp.setContentType("text/html");
req.getSession(true).invalidate();
- System.out.println("Denied PAge:" + init.getDeniedPage());
req.getRequestDispatcher(init.getDeniedPage()).include(req, resp);
}
--- 662,669 ----
public void accessDenied(HttpServletRequest req, HttpServletResponse resp)
throws Exception {
!
! //forward to access denied page specified in the web.xml file
resp.setContentType("text/html");
req.getSession(true).invalidate();
req.getRequestDispatcher(init.getDeniedPage()).include(req, resp);
}
|