/**
   * Handles requests with message handler implementation. Previously sets Http request method as
   * header parameter.
   *
   * @param method
   * @param requestEntity
   * @return
   */
  private ResponseEntity<String> handleRequestInternal(
      HttpMethod method, HttpEntity<String> requestEntity) {
    Map<String, ?> httpRequestHeaders = headerMapper.toHeaders(requestEntity.getHeaders());
    Map<String, String> customHeaders = new HashMap<String, String>();
    for (Entry<String, List<String>> header : requestEntity.getHeaders().entrySet()) {
      if (!httpRequestHeaders.containsKey(header.getKey())) {
        customHeaders.put(
            header.getKey(), StringUtils.collectionToCommaDelimitedString(header.getValue()));
      }
    }

    HttpServletRequest request =
        ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
    UrlPathHelper pathHelper = new UrlPathHelper();

    customHeaders.put(CitrusHttpMessageHeaders.HTTP_REQUEST_URI, pathHelper.getRequestUri(request));
    customHeaders.put(
        CitrusHttpMessageHeaders.HTTP_CONTEXT_PATH, pathHelper.getContextPath(request));

    String queryParams = pathHelper.getOriginatingQueryString(request);
    customHeaders.put(
        CitrusHttpMessageHeaders.HTTP_QUERY_PARAMS, queryParams != null ? queryParams : "");

    customHeaders.put(CitrusHttpMessageHeaders.HTTP_REQUEST_METHOD, method.toString());

    Message<?> response =
        messageHandler.handleMessage(
            MessageBuilder.withPayload(requestEntity.getBody())
                .copyHeaders(convertHeaderTypes(httpRequestHeaders))
                .copyHeaders(customHeaders)
                .build());

    return generateResponse(response);
  }
  protected void addCategoryToModel(HttpServletRequest request, ModelMap model) {
    Category rootCategory = null;
    if (getRootCategoryId() != null) {
      rootCategory = catalogService.findCategoryById(getRootCategoryId());
    } else if (getRootCategoryName() != null) {
      rootCategory = catalogService.findCategoryByName(getRootCategoryName());
    }

    if (rootCategory == null) {
      throw new IllegalStateException(
          "Catalog Controller configured incorrectly - rootId category not found: "
              + rootCategoryId);
    }

    String url =
        pathHelper.getRequestUri(request).substring(pathHelper.getContextPath(request).length());
    String categoryId = request.getParameter("categoryId");
    if (categoryId != null) {
      Category category = catalogService.findCategoryById(new Long(categoryId));
      if (category != null) {
        url = category.getUrl();
      }
    }

    List<Long> categoryIdList =
        catalogService.getChildCategoryURLMapByCategoryId(rootCategory.getId()).get(url);
    List<Category> categoryList = null;
    if (categoryIdList != null) {
      categoryList = new ArrayList<Category>(categoryIdList.size());
      for (Long id : categoryIdList) {
        categoryList.add(catalogService.findCategoryById(id));
      }
    }

    addCategoryListToModel(categoryList, rootCategory, url, model);
    model.addAttribute("rootCategory", rootCategory);
  }