Search code examples
javasolrsolrjjsessionid

Session id to the Solr url


I am trying to send a query to a server running Solr as follows:

String solrServerUrl = //SomeBaseUrl
CommonsHttpSolrServer searchServer = new CommonsHttpSolrServer("http://"+solrServerUrl);
QueryResponse result = searchServer.query(query,SolrRequest.METHOD.POST);

In the query request that I send over to the Solr server,I append the sessionId string as follows(for logging purposes):

String solrServerUrl = SomeBaseUrl.concat("?sessionId");

When I run the server, I get the following exception:

nested exception is java.lang.RuntimeException: Invalid base url for solrj. The base URL must not contain parameters

Can somebody point out how I can forward the unique session-id to the Solr server so that the session-id is picked by the tomcat valves set up in the destination Solr-server for logging purposes?

Thanks


Solution

  • I don't think it's possible that way with the actual CommonsHttpSolrServer code, it doesn't matter if you're using POST or GET (even if rfeak's comment looks good).

    There's a condition like this in the main CommonsHttpSolrServer constructor:

    if( _baseURL.indexOf( '?' ) >=0 ) {
        throw new RuntimeException( "Invalid base url for solrj.  The base URL must not contain parameters: "+_baseURL );
    }
    

    I would try using the SolrQuery#setParam method. This way you might be able to add additional request parameters, which should just be ignored by the Solr request handler.