/**
   * Handles the HTTP request by generating a Message and sending it to the request channel. If this
   * gateway's 'expectReply' property is true, it will also generate a response from the reply
   * Message once received. That response will be written by the {@link HttpMessageConverter}s.
   */
  public final void handleRequest(
      HttpServletRequest servletRequest, HttpServletResponse servletResponse)
      throws ServletException, IOException {
    Object responseContent = null;
    Message<?> responseMessage;

    final ServletServerHttpRequest request = new ServletServerHttpRequest(servletRequest);
    final ServletServerHttpResponse response = new ServletServerHttpResponse(servletResponse);

    try {
      responseMessage = super.doHandleRequest(servletRequest, servletResponse);
      if (responseMessage != null) {
        responseContent = setupResponseAndConvertReply(response, responseMessage);
      }
    } catch (Exception e) {
      responseContent = handleExceptionInternal(e);
    }
    if (responseContent != null) {

      if (responseContent instanceof HttpStatus) {
        response.setStatusCode((HttpStatus) responseContent);
      } else {
        this.writeResponse(responseContent, response, request.getHeaders().getAccept());
      }
    }
  }
 private String getPath(ServletServerHttpRequest request) {
   String path =
       (String)
           request
               .getServletRequest()
               .getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
   return (path == null ? "" : path);
 }
 private void beforeBodyWrite(Object body, ServletServerHttpRequest request) {
   Object pattern =
       request
           .getServletRequest()
           .getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
   if (pattern != null && body instanceof ResourceSupport) {
     beforeBodyWrite(pattern.toString(), (ResourceSupport) body);
   }
 }