private Object processRemotingRequest( HttpServletRequest request, HttpServletResponse response, Locale locale, ExtDirectRequest directRequest, MethodInfo methodInfo) throws Exception { Object[] parameters = configurationService .getParametersResolver() .resolveParameters(request, response, locale, directRequest, methodInfo); if (configurationService.getConfiguration().isSynchronizeOnSession() || methodInfo.isSynchronizeOnSession()) { HttpSession session = request.getSession(false); if (session != null) { Object mutex = WebUtils.getSessionMutex(session); synchronized (mutex) { return ExtDirectSpringUtil.invoke( configurationService.getApplicationContext(), directRequest.getAction(), methodInfo, parameters); } } } return ExtDirectSpringUtil.invoke( configurationService.getApplicationContext(), directRequest.getAction(), methodInfo, parameters); }
@SuppressWarnings("unchecked") public static Map<String, Object> createRequestJsonNamedParam( String action, String method, final int tid, Map<String, Object> data) { ExtDirectRequest dr = new ExtDirectRequest(); dr.setAction(action); dr.setMethod(method); dr.setTid(tid); dr.setType("rpc"); dr.setData(data); return mapper.convertValue(dr, LinkedHashMap.class); }
@SuppressWarnings("unchecked") public static Map<String, Object> createRequestJson( String action, String method, final boolean namedParameter, int tid, Object data) { ExtDirectRequest dr = new ExtDirectRequest(); dr.setAction(action); dr.setMethod(method); dr.setTid(tid); dr.setType("rpc"); if (namedParameter || data instanceof Object[] || data == null) { dr.setData(data); } else { dr.setData(new Object[] {data}); } return mapper.convertValue(dr, LinkedHashMap.class); }
@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; }