* Remaining public fields in RequestTrans converted to private, final where possible
* Added setters/getters * Improved hashCode() implementation for RequestTrans
This commit is contained in:
parent
3d6da7803d
commit
af84ec19c9
5 changed files with 48 additions and 25 deletions
|
@ -128,7 +128,7 @@ public class RequestBean implements Serializable {
|
|||
* @return ...
|
||||
*/
|
||||
public String getPath() {
|
||||
return req.path;
|
||||
return req.getPath();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -50,10 +50,10 @@ public class RequestTrans implements Serializable {
|
|||
final HttpServletResponse response;
|
||||
|
||||
// the uri path of the request
|
||||
public String path;
|
||||
private final String path;
|
||||
|
||||
// the request's session id
|
||||
public String session;
|
||||
private String session;
|
||||
|
||||
// the map of form and cookie data
|
||||
private final Map values;
|
||||
|
@ -78,8 +78,9 @@ public class RequestTrans implements Serializable {
|
|||
/**
|
||||
* Create a new Request transmitter with an empty data map.
|
||||
*/
|
||||
public RequestTrans(String method) {
|
||||
public RequestTrans(String method, String path) {
|
||||
this.method = method;
|
||||
this.path = path;
|
||||
this.request = null;
|
||||
this.response = null;
|
||||
values = new SystemMap();
|
||||
|
@ -89,10 +90,12 @@ public class RequestTrans implements Serializable {
|
|||
/**
|
||||
* 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.request = request;
|
||||
this.response = response;
|
||||
this.path = path;
|
||||
values = new SystemMap();
|
||||
startTime = System.currentTimeMillis();
|
||||
}
|
||||
|
@ -143,7 +146,10 @@ public class RequestTrans implements Serializable {
|
|||
* detect multiple identic requests.
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
public synchronized String getAction() {
|
||||
public String getAction() {
|
||||
return action;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the request's action.
|
||||
*/
|
||||
public synchronized void setAction(String action) {
|
||||
public void setAction(String action) {
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
|
|
|
@ -620,7 +620,7 @@ public final class Application implements IPathElement, Runnable {
|
|||
requestCount += 1;
|
||||
|
||||
// get user for this request's session
|
||||
Session session = createSession(req.session);
|
||||
Session session = createSession(req.getSession());
|
||||
|
||||
session.touch();
|
||||
|
||||
|
|
|
@ -151,7 +151,7 @@ public final class RequestEvaluator implements Runnable {
|
|||
// Transaction name is used for logging etc.
|
||||
StringBuffer txname = new StringBuffer(app.getName());
|
||||
txname.append(":").append(req.getMethod().toLowerCase()).append(":");
|
||||
txname.append((error == null) ? req.path : "error");
|
||||
txname.append((error == null) ? req.getPath() : "error");
|
||||
|
||||
// begin transaction
|
||||
localrtx.begin(txname.toString());
|
||||
|
@ -190,8 +190,8 @@ public final class RequestEvaluator implements Runnable {
|
|||
if (action == null) {
|
||||
throw new RuntimeException(error);
|
||||
}
|
||||
} else if ((req.path == null) ||
|
||||
"".equals(req.path.trim())) {
|
||||
} else if ((req.getPath() == null) ||
|
||||
"".equals(req.getPath().trim())) {
|
||||
currentElement = root;
|
||||
requestPath.add(null, currentElement);
|
||||
|
||||
|
@ -202,7 +202,7 @@ public final class RequestEvaluator implements Runnable {
|
|||
}
|
||||
} else {
|
||||
// march down request path...
|
||||
StringTokenizer st = new StringTokenizer(req.path,
|
||||
StringTokenizer st = new StringTokenizer(req.getPath(),
|
||||
"/");
|
||||
int ntokens = st.countTokens();
|
||||
|
||||
|
@ -674,7 +674,7 @@ public final class RequestEvaluator implements Runnable {
|
|||
wait(app.requestTimeout);
|
||||
|
||||
if (reqtype != NONE) {
|
||||
app.logEvent("Stopping Thread for Request " + app.getName() + "/" + req.path);
|
||||
app.logEvent("Stopping Thread for Request " + app.getName() + "/" + req.getPath());
|
||||
stopTransactor();
|
||||
res.reset();
|
||||
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) {
|
||||
this.functionName = functionName;
|
||||
this.reqtype = reqtype;
|
||||
req = new RequestTrans(reqtypeName);
|
||||
req.path = functionName;
|
||||
req = new RequestTrans(reqtypeName, functionName);
|
||||
session = new Session(functionName, app);
|
||||
res = new ResponseTrans(app, req);
|
||||
result = null;
|
||||
|
|
|
@ -134,7 +134,7 @@ public abstract class AbstractServletClient extends HttpServlet {
|
|||
protected void service (HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
|
||||
RequestTrans reqtrans = new RequestTrans(request, response);
|
||||
RequestTrans reqtrans = new RequestTrans(request, response, getPathInfo(request));
|
||||
|
||||
try {
|
||||
// get the character encoding
|
||||
|
@ -225,7 +225,7 @@ public abstract class AbstractServletClient extends HttpServlet {
|
|||
String nextPart = reqCookies[i].getValue();
|
||||
|
||||
if (sessionCookieName.equals(nextKey)) {
|
||||
reqtrans.session = nextPart;
|
||||
reqtrans.setSession(nextPart);
|
||||
} else {
|
||||
reqtrans.set(nextKey, nextPart);
|
||||
}
|
||||
|
@ -301,9 +301,6 @@ public abstract class AbstractServletClient extends HttpServlet {
|
|||
reqtrans.set("authorization", authorization);
|
||||
}
|
||||
|
||||
// response.setHeader ("Server", "Helma/"+helma.main.Server.version);
|
||||
reqtrans.path = getPathInfo(request);
|
||||
|
||||
ResponseTrans restrans = getApplication().execute(reqtrans);
|
||||
|
||||
// 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.getHeader("X-Forwarded-For"));
|
||||
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));
|
||||
}
|
||||
} else if (reqtrans.session == null) {
|
||||
} else if (reqtrans.getSession() == null) {
|
||||
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) -
|
||||
System.currentTimeMillis(), 36));
|
||||
|
||||
reqtrans.session = b.toString();
|
||||
Cookie cookie = new Cookie(sessionCookieName, reqtrans.session);
|
||||
reqtrans.setSession(b.toString());
|
||||
Cookie cookie = new Cookie(sessionCookieName, reqtrans.getSession());
|
||||
|
||||
cookie.setPath("/");
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue