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);
  }
 /**
  * Null safe means for retrieving the {@link Map} from the specified session keyed by {@link
  * #SESSION_ATTRIBUTE__PORTLET_FAILURE_CAUSE_MAP}.
  *
  * @param request HttpServletRequest
  * @return a never null {@link Map} in the session for storing portlet failure causes.
  */
 @SuppressWarnings("unchecked")
 protected Map<IPortletWindowId, Exception> getPortletErrorMap(HttpServletRequest request) {
   final HttpSession session = request.getSession();
   synchronized (WebUtils.getSessionMutex(session)) {
     Map<IPortletWindowId, Exception> portletFailureMap =
         (Map<IPortletWindowId, Exception>)
             session.getAttribute(SESSION_ATTRIBUTE__PORTLET_FAILURE_CAUSE_MAP);
     if (portletFailureMap == null) {
       portletFailureMap = new ConcurrentHashMap<IPortletWindowId, Exception>();
       session.setAttribute(SESSION_ATTRIBUTE__PORTLET_FAILURE_CAUSE_MAP, portletFailureMap);
     }
     return portletFailureMap;
   }
 }
  @SuppressWarnings("unchecked")
  protected PortletWindowCache<PortletWindowData> getPortletWindowDataMap(
      HttpServletRequest request, boolean create) {
    request = portalRequestUtils.getOriginalPortalRequest(request);
    final HttpSession session = request.getSession(create);
    if (!create && session == null) {
      return null;
    }

    PortletWindowCache<PortletWindowData> windowCache;

    final Object mutex = WebUtils.getSessionMutex(session);
    synchronized (mutex) {
      windowCache =
          (PortletWindowCache<PortletWindowData>)
              session.getAttribute(PORTLET_WINDOW_DATA_ATTRIBUTE);
      if (windowCache == null) {
        windowCache = new PortletWindowCache<PortletWindowData>();
        session.setAttribute(PORTLET_WINDOW_DATA_ATTRIBUTE, windowCache);
      }
    }

    return windowCache;
  }
  @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;
  }