2017-05-04 69 views
0

我在Solr的配置自定义HTTP滤波器,它首先被调用(org.apache.solr.servlet.SolrDispatchFilter之前执行),选择那些命中solr的每个请求的定制请求头。自定义过滤器会在所有传入的solr请求中查找特定的请求标头,并且只有当它存在时,才会将其发送给solr进一步处理。设置使用SolrJ

我使用SolrJ进行某些查询。查询Solr到SolrJ时,有什么方法可以设置HTTP请求标头?

我的Solr和SorlJ版本是5.4.0

回答

0

您可以扩展HttpSolrClient创建自己的类MyHttpSolrClient和定制的executeMethod添加自定义请求头的行为。

public class MyHttpSolrClient extends HttpSolrClient { 

    public MyHttpSolrClient(String baseURL) { 
    super(baseURL); 
    } 

    public MyHttpSolrClient(String baseURL, HttpClient client) { 
    super(baseURL, client); 
    } 

    public MyHttpSolrClient(String baseURL, HttpClient client, ResponseParser parser) { 
    super(baseURL, client, parser); 
    } 

    protected NamedList<Object> executeMethod(HttpRequestBase method, final ResponseParser processor) throws SolrServerException { 

    // **Here you add your custom header** 
    method.addHeader("Name", "Value"); 

    return super.executeMethod(method, processor); 
    } 
}