You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by "Sanders, Marshall (CAI - Atlanta)" <Ma...@coxautoinc.com> on 2017/08/04 14:59:14 UTC

Cookies with SOLRJ?

Is there a way to easily set/get a cookie from a solrj request/response or an example of this someone can share?

The types of queries our application uses could greatly benefit from stickying our application to a specific solr instance and I'd like to read the load balancer cookie and then send it with subsequent requests.  This would mostly just be used for /select get queries, not updates or anything like that if it makes a difference.


Marshall Sanders
Technical Lead - Software Engineering
Autotrader


Re: Cookies with SOLRJ?

Posted by Shawn Heisey <ap...@elyograg.org>.
On 8/4/2017 8:59 AM, Sanders, Marshall (CAI - Atlanta) wrote:
> Is there a way to easily set/get a cookie from a solrj request/response or an example of this someone can share?
>
> The types of queries our application uses could greatly benefit from stickying our application to a specific solr instance and I'd like to read the load balancer cookie and then send it with subsequent requests.  This would mostly just be used for /select get queries, not updates or anything like that if it makes a difference.

SolrJ (4.0 and later) uses the HttpClient library from Apache
HttpComponents.  It does not expose much of that library's configuration
options.

There is an 8 year old thread from this list with a similar question:

http://marc.info/?t=125061419900003&r=1&w=2

The beginning of the response from Chris Hostetter on 2009-08-21 sounds
like HttpClient might manage cookies for you, so you can try the idea below.

You can create a custom HttpClient object that can be used to build your
solr client object, and give that object the cookie policy you want it
to have, but I do not know if SolrJ is coded in a way that would
actually use any cookies received.

See section 3.3 on this page for information on how to build a custom
HttpClient object with a particular cookie policy:

https://hc.apache.org/httpcomponents-client-ga/tutorial/html/statemgmt.html

I do see that there is code in the BasicHttpSolrClientTest class for
cookies, but I do not know what that code is doing.

If SolrJ does not currently have the ability to do this, it would be an
excellent feature request to open in Jira.

I'm just guessing here.  I really have no idea whether any of what I
said above will be helpful.

Thanks,
Shawn