On 2/3/2014 3:40 PM, Andrew Doyle wrote:
Our web services are using PKI authentication so we have a user DN, however
we're querying an external Solr which is managed via a proxy which is
expecting our server DN proxying the user DN. My question is, how do we add
an HTTP header to the request being made by SolrJ?
I looked through the source code and I see that we can specify an
HttpClient when we create a new instance of an HttpSolrServer. I can set
the header there, but that seems slightly hackey to me. I'd prefer to use a
servlet filter if possible.
Do you have any other suggestions?
I don't think there's any servlet information (like the filters you
mentioned) available in SolrJ. There is in Solr itself, which uses
SolrJ, but unless you're writing a servlet or custom server side code
for Solr, you won't have access to any of that. If you are writing a
servlet or custom server-side code, then they'll be available -- but not
from SolrJ.
I could be wrong about what I just said, but just now when I looked
through the code for HttpSolrServer and SolrServer, I did not see
anything about servlets or filters.
In my own SolrJ application, I create an HttpClient instance that is
used across dozens of HttpSolrServer instances. The following is part of
the constructor code for my custom "Core" class.
/*
* If this is the first time a Core has been created, create
the shared
* httpClient with some increased connection properties.
Synchronized to
* ensure thread safety.
*/
synchronized (firstInstance)
{
if (firstInstance)
{
ModifiableSolrParams params = new ModifiableSolrParams();
params.add(HttpClientUtil.PROP_MAX_CONNECTIONS_PER_HOST, "200");
params.add(HttpClientUtil.PROP_MAX_CONNECTIONS, "5000");
httpClient = HttpClientUtil.createClient(params);
firstInstance = false;
}
}
These are the static class members used in the above code:
/**
* A static boolean value indicating whether this is the first
instance of
* this object. Also used for thread synchronization.
*/
private static Boolean firstInstance = true;
/**
* A static http client to use on all Solr server objects.
*/
private static HttpClient httpClient = null;
Just so you know, the deprecations introduced by the recent upgrade to
HttpClient 4.3 might complicate things further when it comes to user
code. See SOLR-5604. I have some ideas about how to proceed on that
issue, but haven'thad a lot of time to look into it, and before I do
anything, I need to discuss it with people who are smarter than me.
https://issues.apache.org/jira/browse/SOLR-5604
Thanks,
Shawn