* Remaining public fields in RequestTrans converted to private, final where possible

* Added setters/getters
* Improved hashCode() implementation for RequestTrans
This commit is contained in:
hns 2005-08-18 22:55:30 +00:00
parent 3d6da7803d
commit af84ec19c9
5 changed files with 48 additions and 25 deletions

View file

@ -128,7 +128,7 @@ public class RequestBean implements Serializable {
* @return ... * @return ...
*/ */
public String getPath() { public String getPath() {
return req.path; return req.getPath();
} }
/** /**

View file

@ -50,10 +50,10 @@ public class RequestTrans implements Serializable {
final HttpServletResponse response; final HttpServletResponse response;
// the uri path of the request // the uri path of the request
public String path; private final String path;
// the request's session id // the request's session id
public String session; private String session;
// the map of form and cookie data // the map of form and cookie data
private final Map values; private final Map values;
@ -78,8 +78,9 @@ public class RequestTrans implements Serializable {
/** /**
* Create a new Request transmitter with an empty data map. * Create a new Request transmitter with an empty data map.
*/ */
public RequestTrans(String method) { public RequestTrans(String method, String path) {
this.method = method; this.method = method;
this.path = path;
this.request = null; this.request = null;
this.response = null; this.response = null;
values = new SystemMap(); values = new SystemMap();
@ -89,10 +90,12 @@ public class RequestTrans implements Serializable {
/** /**
* Create a new request transmitter with the given data map. * Create a new request transmitter with the given data map.
*/ */
public RequestTrans(HttpServletRequest request, HttpServletResponse response) { public RequestTrans(HttpServletRequest request,
HttpServletResponse response, String path) {
this.method = request.getMethod(); this.method = request.getMethod();
this.request = request; this.request = request;
this.response = response; this.response = response;
this.path = path;
values = new SystemMap(); values = new SystemMap();
startTime = System.currentTimeMillis(); startTime = System.currentTimeMillis();
} }
@ -143,7 +146,10 @@ public class RequestTrans implements Serializable {
* detect multiple identic requests. * detect multiple identic requests.
*/ */
public int hashCode() { public int hashCode() {
return (session == null) ? super.hashCode() : session.hashCode(); if (session == null || path == null)
return super.hashCode();
return 17 + (37 * session.hashCode()) +
(37 * path.hashCode());
} }
/** /**
@ -183,17 +189,38 @@ public class RequestTrans implements Serializable {
return POST.equalsIgnoreCase(method); return POST.equalsIgnoreCase(method);
} }
/**
* Get the request's session id
*/
public String getSession() {
return session;
}
/**
* Set the request's session id
*/
public void setSession(String session) {
this.session = session;
}
/**
* Get the request's path
*/
public String getPath() {
return path;
}
/** /**
* Get the request's action. * Get the request's action.
*/ */
public synchronized String getAction() { public String getAction() {
return action; return action;
} }
/** /**
* Set the request's action. * Set the request's action.
*/ */
public synchronized void setAction(String action) { public void setAction(String action) {
this.action = action; this.action = action;
} }

View file

@ -620,7 +620,7 @@ public final class Application implements IPathElement, Runnable {
requestCount += 1; requestCount += 1;
// get user for this request's session // get user for this request's session
Session session = createSession(req.session); Session session = createSession(req.getSession());
session.touch(); session.touch();

View file

@ -151,7 +151,7 @@ public final class RequestEvaluator implements Runnable {
// Transaction name is used for logging etc. // Transaction name is used for logging etc.
StringBuffer txname = new StringBuffer(app.getName()); StringBuffer txname = new StringBuffer(app.getName());
txname.append(":").append(req.getMethod().toLowerCase()).append(":"); txname.append(":").append(req.getMethod().toLowerCase()).append(":");
txname.append((error == null) ? req.path : "error"); txname.append((error == null) ? req.getPath() : "error");
// begin transaction // begin transaction
localrtx.begin(txname.toString()); localrtx.begin(txname.toString());
@ -190,8 +190,8 @@ public final class RequestEvaluator implements Runnable {
if (action == null) { if (action == null) {
throw new RuntimeException(error); throw new RuntimeException(error);
} }
} else if ((req.path == null) || } else if ((req.getPath() == null) ||
"".equals(req.path.trim())) { "".equals(req.getPath().trim())) {
currentElement = root; currentElement = root;
requestPath.add(null, currentElement); requestPath.add(null, currentElement);
@ -202,7 +202,7 @@ public final class RequestEvaluator implements Runnable {
} }
} else { } else {
// march down request path... // march down request path...
StringTokenizer st = new StringTokenizer(req.path, StringTokenizer st = new StringTokenizer(req.getPath(),
"/"); "/");
int ntokens = st.countTokens(); int ntokens = st.countTokens();
@ -674,7 +674,7 @@ public final class RequestEvaluator implements Runnable {
wait(app.requestTimeout); wait(app.requestTimeout);
if (reqtype != NONE) { if (reqtype != NONE) {
app.logEvent("Stopping Thread for Request " + app.getName() + "/" + req.path); app.logEvent("Stopping Thread for Request " + app.getName() + "/" + req.getPath());
stopTransactor(); stopTransactor();
res.reset(); res.reset();
res.writeErrorReport(app.getName(), "Request timed out"); res.writeErrorReport(app.getName(), "Request timed out");
@ -879,8 +879,7 @@ public final class RequestEvaluator implements Runnable {
private void initObjects(String functionName, int reqtype, String reqtypeName) { private void initObjects(String functionName, int reqtype, String reqtypeName) {
this.functionName = functionName; this.functionName = functionName;
this.reqtype = reqtype; this.reqtype = reqtype;
req = new RequestTrans(reqtypeName); req = new RequestTrans(reqtypeName, functionName);
req.path = functionName;
session = new Session(functionName, app); session = new Session(functionName, app);
res = new ResponseTrans(app, req); res = new ResponseTrans(app, req);
result = null; result = null;

View file

@ -134,7 +134,7 @@ public abstract class AbstractServletClient extends HttpServlet {
protected void service (HttpServletRequest request, HttpServletResponse response) protected void service (HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { throws ServletException, IOException {
RequestTrans reqtrans = new RequestTrans(request, response); RequestTrans reqtrans = new RequestTrans(request, response, getPathInfo(request));
try { try {
// get the character encoding // get the character encoding
@ -225,7 +225,7 @@ public abstract class AbstractServletClient extends HttpServlet {
String nextPart = reqCookies[i].getValue(); String nextPart = reqCookies[i].getValue();
if (sessionCookieName.equals(nextKey)) { if (sessionCookieName.equals(nextKey)) {
reqtrans.session = nextPart; reqtrans.setSession(nextPart);
} else { } else {
reqtrans.set(nextKey, nextPart); reqtrans.set(nextKey, nextPart);
} }
@ -301,9 +301,6 @@ public abstract class AbstractServletClient extends HttpServlet {
reqtrans.set("authorization", authorization); reqtrans.set("authorization", authorization);
} }
// response.setHeader ("Server", "Helma/"+helma.main.Server.version);
reqtrans.path = getPathInfo(request);
ResponseTrans restrans = getApplication().execute(reqtrans); ResponseTrans restrans = getApplication().execute(reqtrans);
// if the response was already written and committed by the application // if the response was already written and committed by the application
@ -559,10 +556,10 @@ public abstract class AbstractServletClient extends HttpServlet {
addIPAddress(b, request.getRemoteAddr()); addIPAddress(b, request.getRemoteAddr());
addIPAddress(b, request.getHeader("X-Forwarded-For")); addIPAddress(b, request.getHeader("X-Forwarded-For"));
addIPAddress(b, request.getHeader("Client-ip")); addIPAddress(b, request.getHeader("Client-ip"));
if (reqtrans.session == null || !reqtrans.session.startsWith(b.toString())) { if (reqtrans.getSession() == null || !reqtrans.getSession().startsWith(b.toString())) {
response.addCookie(createSessionCookie(b, reqtrans, domain)); response.addCookie(createSessionCookie(b, reqtrans, domain));
} }
} else if (reqtrans.session == null) { } else if (reqtrans.getSession() == null) {
response.addCookie(createSessionCookie(new StringBuffer(), reqtrans, domain)); response.addCookie(createSessionCookie(new StringBuffer(), reqtrans, domain));
} }
} }
@ -581,8 +578,8 @@ public abstract class AbstractServletClient extends HttpServlet {
b.append (Long.toString(Math.round(Math.random() * Long.MAX_VALUE) - b.append (Long.toString(Math.round(Math.random() * Long.MAX_VALUE) -
System.currentTimeMillis(), 36)); System.currentTimeMillis(), 36));
reqtrans.session = b.toString(); reqtrans.setSession(b.toString());
Cookie cookie = new Cookie(sessionCookieName, reqtrans.session); Cookie cookie = new Cookie(sessionCookieName, reqtrans.getSession());
cookie.setPath("/"); cookie.setPath("/");