public void handle(String beanName, String method, HttpServletRequest request,
HttpServletResponse response, Locale locale) throws Exception {
MethodInfo methodInfo = methodInfoCache.get(beanName, method);
SSEvent result = null;
SSEWriter sseWriter = new SSEWriter(response);
if (methodInfo != null) {
try {
Object[] parameters = configurationService.getParametersResolver()
.prepareParameters(request, response, locale, methodInfo,
sseWriter);
Object methodReturnValue;
if (configurationService.getConfiguration().isSynchronizeOnSession()
|| methodInfo.isSynchronizeOnSession()) {
HttpSession session = request.getSession(false);
if (session != null) {
Object mutex = WebUtils.getSessionMutex(session);
synchronized (mutex) {
methodReturnValue = ExtDirectSpringUtil.invoke(
configurationService.getApplicationContext(),
beanName, methodInfo, parameters);
}
}
else {
methodReturnValue = ExtDirectSpringUtil.invoke(
configurationService.getApplicationContext(), beanName,
methodInfo, parameters);
}
}
else {
methodReturnValue = ExtDirectSpringUtil.invoke(
configurationService.getApplicationContext(), beanName,
methodInfo, parameters);
}
if (methodReturnValue instanceof SSEvent) {
result = (SSEvent) methodReturnValue;
}
else if (methodReturnValue != null) {
result = new SSEvent();
result.setData(methodReturnValue.toString());
}
}
catch (Exception e) {
log.error("Error polling method '" + beanName + "." + method + "'",
e.getCause() != null ? e.getCause() : e);
Throwable cause;
if (e.getCause() != null) {
cause = e.getCause();
}
else {
cause = e;
}
result = new SSEvent();
result.setEvent("error");
result.setData(configurationService.getConfiguration().getMessage(cause));
if (configurationService.getConfiguration().isSendStacktrace()) {
result.setComment(ExtDirectSpringUtil.getStackTrace(cause));
}
}
}
else {
log.error("Error invoking method '" + beanName + "." + method
+ "'. Method or Bean not found");
result = new SSEvent();
result.setEvent("error");
result.setData(configurationService.getConfiguration()
.getDefaultExceptionMessage());
if (configurationService.getConfiguration().isSendStacktrace()) {
result.setComment("Bean or Method '" + beanName + "." + method
+ "' not found");
}
}
if (result != null) {