@RequestMapping(value = "/poll/{beanName}/{method}/{event}")
public void poll(@PathVariable("beanName") String beanName, @PathVariable("method") String method,
@PathVariable("event") String event, HttpServletRequest request, HttpServletResponse response, Locale locale)
throws Exception {
ExtDirectPollResponse directPollResponse = new ExtDirectPollResponse();
directPollResponse.setName(event);
MethodInfo methodInfo = MethodInfoCache.INSTANCE.get(beanName, method);
boolean streamResponse;
Class<?> jsonView = null;
if (methodInfo != null) {
streamResponse = configurationService.getConfiguration().isStreamResponse()
|| methodInfo.isStreamResponse();
try {
Object[] parameters = configurationService.getParametersResolver().prepareParameters(request, response,
locale, methodInfo);
if (configurationService.getConfiguration().isSynchronizeOnSession()
|| methodInfo.isSynchronizeOnSession()) {
HttpSession session = request.getSession(false);
if (session != null) {
Object mutex = WebUtils.getSessionMutex(session);
synchronized (mutex) {
Object result = ExtDirectSpringUtil.invoke(configurationService.getApplicationContext(),
beanName, methodInfo, parameters);
if (result instanceof ModelAndJsonView) {
ModelAndJsonView modelAndJsonView = (ModelAndJsonView) result;
directPollResponse.setData(modelAndJsonView.getModel());
jsonView = getJsonView(modelAndJsonView, methodInfo.getJsonView());
} else {
directPollResponse.setData(result);
jsonView = getJsonView(result, methodInfo.getJsonView());
}
}
} else {
Object result = ExtDirectSpringUtil.invoke(configurationService.getApplicationContext(),
beanName, methodInfo, parameters);
if (result instanceof ModelAndJsonView) {
ModelAndJsonView modelAndJsonView = (ModelAndJsonView) result;
directPollResponse.setData(modelAndJsonView.getModel());
jsonView = getJsonView(modelAndJsonView, methodInfo.getJsonView());
} else {
directPollResponse.setData(result);
jsonView = getJsonView(result, methodInfo.getJsonView());
}
}
} else {
Object result = ExtDirectSpringUtil.invoke(configurationService.getApplicationContext(), beanName,
methodInfo, parameters);
if (result instanceof ModelAndJsonView) {
ModelAndJsonView modelAndJsonView = (ModelAndJsonView) result;
directPollResponse.setData(modelAndJsonView.getModel());
jsonView = getJsonView(modelAndJsonView, methodInfo.getJsonView());
} else {
directPollResponse.setData(result);
jsonView = getJsonView(result, methodInfo.getJsonView());
}
}
} catch (Exception e) {
log.error("Error polling method '" + beanName + "." + method + "'", e.getCause() != null ? e.getCause()
: e);
directPollResponse.setData(handleException(methodInfo, directPollResponse, e, request));
}
} else {
log.error("Error invoking method '" + beanName + "." + method + "'. Method or Bean not found");
handleMethodNotFoundError(directPollResponse, beanName, method);
streamResponse = configurationService.getConfiguration().isStreamResponse();