Uploaded image for project: 'Solr'
  1. Solr
  2. SOLR-1944

Add HttpServletRequest and HttpServletResponse to SolrQueryRequest and SolrQueryResponse

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Resolved
    • Minor
    • Resolution: Duplicate
    • 1.4
    • None
    • None
    • None

    Description

      I am implementing several custom request handlers and response writers. All of them need access to HTTP headers and cookies. In scanning google for mailing lists and forums it seems others have had this same need.

      I worked around it by creating a custom dispatch filter which extends SolrDispatchFilter and does the following:

        public static final String CONTEXT_SERVLET_REQUEST = "servletRequest";
        public static final String CONTEXT_SERVLET_RESPONSE = "servletResponse";
      
        @Override
        public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
          request.setAttribute("response", response);
          super.doFilter(request, response, chain);
        }
      
        @Override
        protected void execute(HttpServletRequest servletRequest, SolrRequestHandler handler, SolrQueryRequest solrRequest, SolrQueryResponse solrResponse) {
          Object servletResponse = servletRequest.getAttribute("response");
          servletRequest.removeAttribute("response");
          solrRequest.getContext().put(CONTEXT_SERVLET_REQUEST, servletRequest);
          solrRequest.getContext().put(CONTEXT_SERVLET_RESPONSE, servletResponse);
          super.execute(servletRequest, handler, solrRequest, solrResponse);
        }
      

      I then had to write a step in my deployment script to crack open the solr war file, sed the web.xml and replace the SolrDispatchFilter with my own. Others have worked around the issue in the same way. This seems like an ugly workaround and would be simpler and cleaner if the SolrQueryRequest and SolrQueryResponse just included a reference to their http counterparts.

      Attachments

        1. HttpServletRequest.patch
          4 kB
          Army Brown

        Issue Links

          Activity

            People

              Unassigned Unassigned
              abrown Army Brown
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: