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);
  }
 public void writeJsonResponse(
     HttpServletRequest request,
     HttpServletResponse response,
     Object responseObject,
     Class<?> jsonView)
     throws IOException, JsonGenerationException, JsonMappingException {
   writeJsonResponse(
       response,
       responseObject,
       jsonView,
       configurationService.getConfiguration().isStreamResponse(),
       ExtDirectSpringUtil.isMultipart(request));
 }
  @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);
  }
  @RequestMapping(value = "/router", method = RequestMethod.POST, params = "extAction")
  public String router(
      HttpServletRequest request,
      HttpServletResponse response,
      @RequestParam("extAction") String extAction,
      @RequestParam("extMethod") String extMethod)
      throws IOException {

    ExtDirectResponse directResponse = new ExtDirectResponse(request);
    MethodInfo methodInfo = MethodInfoCache.INSTANCE.get(extAction, extMethod);
    Class<?> jsonView = null;
    boolean streamResponse;

    if (methodInfo != null && methodInfo.getForwardPath() != null) {
      return methodInfo.getForwardPath();
    } else if (methodInfo != null && methodInfo.getHandlerMethod() != null) {
      streamResponse =
          configurationService.getConfiguration().isStreamResponse()
              || methodInfo.isStreamResponse();

      HandlerMethod handlerMethod = methodInfo.getHandlerMethod();
      try {

        ModelAndView modelAndView = null;

        if (configurationService.getConfiguration().isSynchronizeOnSession()
            || methodInfo.isSynchronizeOnSession()) {
          HttpSession session = request.getSession(false);
          if (session != null) {
            Object mutex = WebUtils.getSessionMutex(session);
            synchronized (mutex) {
              modelAndView = handlerAdapter.handle(request, response, handlerMethod);
            }
          } else {
            modelAndView = handlerAdapter.handle(request, response, handlerMethod);
          }
        } else {
          modelAndView = handlerAdapter.handle(request, response, handlerMethod);
        }

        ExtDirectFormPostResult formPostResult =
            (ExtDirectFormPostResult) modelAndView.getModel().get("extDirectFormPostResult");
        directResponse.setResult(formPostResult.getResult());
        directResponse.setJsonView(getJsonView(formPostResult, methodInfo.getJsonView()));
      } catch (Exception e) {
        log.error("Error calling method: " + extMethod, e.getCause() != null ? e.getCause() : e);
        directResponse.setResult(handleException(methodInfo, directResponse, e, request));
      }
    } else {
      streamResponse = configurationService.getConfiguration().isStreamResponse();
      log.error(
          "Error invoking method '" + extAction + "." + extMethod + "'. Method  or Bean not found");
      handleMethodNotFoundError(directResponse, extAction, extMethod);
    }
    writeJsonResponse(
        response,
        directResponse,
        jsonView,
        streamResponse,
        ExtDirectSpringUtil.isMultipart(request));

    return null;
  }