@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(); } writeJsonResponse(response, directPollResponse, jsonView, streamResponse); }
@SuppressWarnings({"rawtypes", "unchecked"}) ExtDirectResponse handleMethodCall( ExtDirectRequest directRequest, HttpServletRequest request, HttpServletResponse response, Locale locale) { ExtDirectResponse directResponse = new ExtDirectResponse(directRequest); MethodInfo methodInfo = MethodInfoCache.INSTANCE.get(directRequest.getAction(), directRequest.getMethod()); if (methodInfo != null) { try { directResponse.setStreamResponse(methodInfo.isStreamResponse()); Object result = processRemotingRequest(request, response, locale, directRequest, methodInfo); if (result != null) { ModelAndJsonView modelAndJsonView = null; if (result instanceof ModelAndJsonView) { modelAndJsonView = (ModelAndJsonView) result; result = modelAndJsonView.getModel(); } if (methodInfo.isType(ExtDirectMethodType.FORM_LOAD) && !ExtDirectFormLoadResult.class.isAssignableFrom(result.getClass())) { ExtDirectFormLoadResult formLoadResult = new ExtDirectFormLoadResult(result); if (result instanceof JsonViewHint) { formLoadResult.setJsonView(((JsonViewHint) result).getJsonView()); } result = formLoadResult; } else if ((methodInfo.isType(ExtDirectMethodType.STORE_MODIFY) || methodInfo.isType(ExtDirectMethodType.STORE_READ)) && !ExtDirectStoreReadResult.class.isAssignableFrom(result.getClass()) && !ExtDirectStoreResult.class.isAssignableFrom(result.getClass()) && configurationService.getConfiguration().isAlwaysWrapStoreResponse()) { if (result instanceof Collection) { result = new ExtDirectStoreResult((Collection) result); } else { result = new ExtDirectStoreResult(result); } } directResponse.setResult(result); if (modelAndJsonView != null) { directResponse.setJsonView(getJsonView(modelAndJsonView, methodInfo.getJsonView())); } else { directResponse.setJsonView(getJsonView(result, methodInfo.getJsonView())); } } else { if (methodInfo.isType(ExtDirectMethodType.STORE_MODIFY) || methodInfo.isType(ExtDirectMethodType.STORE_READ)) { directResponse.setResult(Collections.emptyList()); } } } catch (Exception e) { log.error( "Error calling method: " + directRequest.getMethod(), e.getCause() != null ? e.getCause() : e); directResponse.setResult(handleException(methodInfo, directResponse, e, request)); } } else { log.error( "Error invoking method '" + directRequest.getAction() + "." + directRequest.getMethod() + "'. Method or Bean not found"); handleMethodNotFoundError( directResponse, directRequest.getAction(), directRequest.getMethod()); } return directResponse; }