Re: [Actionframework-users] ANNOUNCE: ActionServlet 0.93.2c
Status: Inactive
Brought to you by:
ptoman
|
From: Petr T. <Pet...@pi...> - 2002-10-29 19:31:00
|
>> - bugfix: Velocity's error() was not overridden to call
>> ActionServlet.error()
>
> Thanks; unfortunately (and I should have caught this before) I still
> can't do transaction management. That is because cleanupRequest() is
> private, and doesn't pass in Context anyway. There is afterInvoke(),
> but it still happens before template merging. And velocity's
> requestCleanup() is not hooked by AS. Lastly, I can't deal with this
> by overriding doGet and doPost, because the superclass calls its
> cleanup which will invalidate my request-level components before I
> can do my own cleanup.
>
> So I don't see any way for request cleanup.
VelocityServlet (combining AS + Velocity) method calls are:
"HTTP request" -> doGet()/doPost() -> doRequest(...)
protected void doRequest(...) {
try {
handleRequest(request, response, context)
-> ActionServlet.handle(...)
if (template != null) {
mergeTemplate(template, context, response);
requestCleanup(request, response, context);
}
} catch (Exception e) {
error(request, response, e)
-> ActionServlet.error(...);
}
}
Conclusion from this schema: if ActionServlet.error() is not called
during the request, everything is ok. Therefore, you can override
doGet(), doPost() and error() in your servlet like this:
private Hashtable data = new Hashtable();
protected void doGet(HttpServletRequest req, HttpServletResponse res) {
super.doGet(req, res);
finishTransaction();
}
protected void doPost(HttpServletRequest req, HttpServletResponse res) {
super.doPost(req, res);
finishTransaction();
}
public Template error(Context context, String message, Throwable e) {
// get unique id for current thread (i.e. request)
Integer threadId =
new Integer(System.identityHashCode(Thread.currentThread()));
// save context (or set error flag - whatever you need)
data.put(threadId, context);
super.error(context, message, e);
}
private void finishTransaction() {
Integer threadId =
new Integer(System.identityHashCode(Thread.currentThread()));
// check for error
if (data.contains(threadId)) {
// rollback transaction
data.remove(threadId);
} else {
// commit transaction
}
}
But I think that adding ActionServlet.requestCleanup(Context ctx) is not
a bad idea - for AS 0.94 :)
Petr
--
[ http://dione.zcu.cz/~toman40 - Pet...@pi... - ICQ=22957959 ]
|