public void handleContinuation(String id,
List params,
Redirector redirector) throws Exception {
if (!initialized)
initialize();
WebContinuation parentwk = continuationsMgr.lookupWebContinuation(id, getInterpreterID());
if (parentwk == null) {
/*
* Throw an InvalidContinuationException to be handled inside the
* < map:handle-errors > sitemap element.
*/
throw new InvalidContinuationException("The continuation ID " + id + " is invalid.");
}
Continuation parentContinuation = (Continuation) parentwk.getContinuation();
ContinuationContext parentContext = (ContinuationContext) parentContinuation.getContext();
ContinuationContext context = new ContinuationContext();
context.setObject(parentContext.getObject());
context.setMethod(parentContext.getMethod());
context.setAvalonContext(avalonContext);
context.setLogger(getLogger());
context.setServiceManager(manager);
context.setRedirector(redirector);
Parameters parameters = new Parameters();
for(Iterator i=params.iterator(); i.hasNext();) {
Argument argument = (Argument)i.next();
parameters.setParameter(argument.name, argument.value);
}
context.setParameters(parameters);
Continuation continuation = new Continuation(parentContinuation, context);
Request request = ContextHelper.getRequest(this.avalonContext);
Session session = request.getSession(true);
HashMap userScopes = (HashMap) session.getAttribute(USER_GLOBAL_SCOPE);
Continuable flow = (Continuable) context.getObject();
Method method = context.getMethod();
WebContinuation wk = continuationsMgr.createWebContinuation(
continuation, parentwk, timeToLive, getInterpreterID(), null);
FlowHelper.setWebContinuation(ContextHelper.getObjectModel(this.avalonContext), wk);
continuation.registerThread();
try {
method.invoke(flow, new Object[0]);
} catch (InvocationTargetException ite) {
if (ite.getTargetException() != null) {
if (ite.getTargetException() instanceof Exception)
throw (Exception) ite.getTargetException();
else if (ite.getTargetException() instanceof Error)
throw new ProcessingException("An internal error occured", ite.getTargetException());
else if (ite.getTargetException() instanceof RuntimeException)
throw (RuntimeException) ite.getTargetException();
else
throw ite;
} else {
throw ite;
}
} finally {
// remove last object reference, which is not needed to reconstruct
// the invocation path
if (continuation.isCapturing())
continuation.getStack().popReference();
continuation.deregisterThread();
}
userScopes.put(method.getDeclaringClass(), flow);
session.setAttribute(USER_GLOBAL_SCOPE, userScopes);
}
|