Solr
  1. Solr
  2. SOLR-578

Binary stream response for request

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Major Major
    • Resolution: Won't Fix
    • Affects Version/s: 1.3
    • Fix Version/s: 1.3
    • Component/s: None
    • Labels:
      None

      Description

      Allow sending binary response back from request. This is not the same as encoding in binary such as BinaryQueryResponseWriter. Simply need access to servlet response stream for sending something like a Lucene segment.

        Activity

        Hide
        Jason Rutherglen added a comment -

        Maybe this will work. The request handler implements it.

        public interface BinaryRequestHandler {
          public void handleRequest(SolrQueryRequest req, HttpServletResponse servletResponse);
        }
        
        Show
        Jason Rutherglen added a comment - Maybe this will work. The request handler implements it. public interface BinaryRequestHandler { public void handleRequest(SolrQueryRequest req, HttpServletResponse servletResponse); }
        Hide
        Jason Rutherglen added a comment -

        Or place it in SolrQueryResponse.

        Show
        Jason Rutherglen added a comment - Or place it in SolrQueryResponse.
        Hide
        Noble Paul added a comment -

        The BinaryQueryResponseWriter is the interface you must implement and the 'out' parameter is an instance of ServletOutputStream. Using that you can send out any binary data (even a lucene segment).

        The implementation code is as follows in SolrDispatchFilter

         if (responseWriter instanceof BinaryQueryResponseWriter) {
             BinaryQueryResponseWriter binWriter = (BinaryQueryResponseWriter) responseWriter;
              binWriter.write(response.getOutputStream(), solrReq, solrRsp);
         }
        

        Is there any specific reason why you must have access to the HttpServletResponse object ?

        Show
        Noble Paul added a comment - The BinaryQueryResponseWriter is the interface you must implement and the 'out' parameter is an instance of ServletOutputStream. Using that you can send out any binary data (even a lucene segment). The implementation code is as follows in SolrDispatchFilter if (responseWriter instanceof BinaryQueryResponseWriter) { BinaryQueryResponseWriter binWriter = (BinaryQueryResponseWriter) responseWriter; binWriter.write(response.getOutputStream(), solrReq, solrRsp); } Is there any specific reason why you must have access to the HttpServletResponse object ?
        Hide
        Jason Rutherglen added a comment -

        It is incongruous to have SolrQueryRequest.getContentStreams() but nothing similar for SolrQueryResponse. If BinaryQueryResponseWriter is used, the logic for handling the request would go in the class that implements it, what is the purpose of the RequestHandler in this case? The purpose of BinaryQueryResponseWriter is to allow encoding the normal Solr result objects into a binary format. A RequestHandler that only returns binary and does not use the SolrQueryResponse.add() or similar methods for encoding objects is out of place using BinaryQueryResponseWriter.

        Show
        Jason Rutherglen added a comment - It is incongruous to have SolrQueryRequest.getContentStreams() but nothing similar for SolrQueryResponse. If BinaryQueryResponseWriter is used, the logic for handling the request would go in the class that implements it, what is the purpose of the RequestHandler in this case? The purpose of BinaryQueryResponseWriter is to allow encoding the normal Solr result objects into a binary format. A RequestHandler that only returns binary and does not use the SolrQueryResponse.add() or similar methods for encoding objects is out of place using BinaryQueryResponseWriter.
        Hide
        Noble Paul added a comment -

        It is by design that SOLR keep the requesthandlers and response writers loosely coupled. The responsibilities are clearly defined

        • RequestHandler : Takes in the request parameters , do the necessary operations and prepare a response to be written back to the client
        • ResponseWriter : Take in the response object and write it down in a format of client's choice

        If your Handler can write out data only using a specific writer, you have the flexibility of overriding the 'wt' in the handler. Register your own writer in solrconfig.xml.

        We are implementing SOLR-561 using the same strategy .

        • We have a handler which reads an index file (or a part of it) and puts the stream object into the SolrQueryResponse rsp.add("stream", inputstreamobject)
        • It sets a custom writer . (solrparams.Params.set("wt", "filestream")).
        • The custom binary writer then take the inputstream object (rsp.get("stream")) and pipe the data to the outputstream.
        Show
        Noble Paul added a comment - It is by design that SOLR keep the requesthandlers and response writers loosely coupled. The responsibilities are clearly defined RequestHandler : Takes in the request parameters , do the necessary operations and prepare a response to be written back to the client ResponseWriter : Take in the response object and write it down in a format of client's choice If your Handler can write out data only using a specific writer, you have the flexibility of overriding the 'wt' in the handler. Register your own writer in solrconfig.xml. We are implementing SOLR-561 using the same strategy . We have a handler which reads an index file (or a part of it) and puts the stream object into the SolrQueryResponse rsp.add("stream", inputstreamobject) It sets a custom writer . (solrparams.Params.set("wt", "filestream")). The custom binary writer then take the inputstream object (rsp.get("stream")) and pipe the data to the outputstream.
        Hide
        Hoss Man added a comment -

        If your Handler can write out data only using a specific writer, you have the flexibility of overriding the 'wt' in the handler. Register your own writer in solrconfig.xml.

        Correct.

        (a handler can even go so far as to "fail" in the inform(SolrCore) method if the writer it expects is not present)

        The ShowFileRequestHandler and RawResponseWriter are good examples of this model (although it would probably make sense to change RawResponseWriter to implement BinaryQueryResponseWriter at some point)

        It is incongruous to have SolrQueryRequest.getContentStreams() but nothing similar for SolrQueryResponse.

        Only if you are use to thinking of things in terms of the servlet API : )

        generally speaking, the majority of Request Handlers shouldn't be dealing with raw character or binary streams ... they should be dealing with simple objects and deferring rendering of those objects to the QueryResponseWriter to decide how to render them based on the wishes of the client ... there are exceptions to every rule however, hence the approach described here where the Handler "forces" a particular response writer.

        Show
        Hoss Man added a comment - If your Handler can write out data only using a specific writer, you have the flexibility of overriding the 'wt' in the handler. Register your own writer in solrconfig.xml. Correct. (a handler can even go so far as to "fail" in the inform(SolrCore) method if the writer it expects is not present) The ShowFileRequestHandler and RawResponseWriter are good examples of this model (although it would probably make sense to change RawResponseWriter to implement BinaryQueryResponseWriter at some point) It is incongruous to have SolrQueryRequest.getContentStreams() but nothing similar for SolrQueryResponse. Only if you are use to thinking of things in terms of the servlet API : ) generally speaking, the majority of Request Handlers shouldn't be dealing with raw character or binary streams ... they should be dealing with simple objects and deferring rendering of those objects to the QueryResponseWriter to decide how to render them based on the wishes of the client ... there are exceptions to every rule however, hence the approach described here where the Handler "forces" a particular response writer.
        Hide
        Jason Rutherglen added a comment -

        Ok

        Show
        Jason Rutherglen added a comment - Ok

          People

          • Assignee:
            Unassigned
            Reporter:
            Jason Rutherglen
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development