2016-04-24 48 views
1

我已經配置春季數據的Solr 1.5.4使用Apache Solr實現5.2.1,這是我的配置:Solr的NonRepeatableRequestException在保存操作

@Bean 
public SolrTemplate solrTemplate() { 
    return new SolrTemplate(solrServerFactory()); 
} 

@Bean 
public SolrServerFactory solrServerFactory() { 
    UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(username, password); 
return new HttpSolrServerFactory(solrServer(), "", credentials, "BASIC"); 
} 

@Bean 
public SolrServer solrServer() { 
    ModifiableSolrParams params = new ModifiableSolrParams(); 
    params.set(HttpClientUtil.PROP_ALLOW_COMPRESSION, true); 
    params.set(HttpClientUtil.PROP_BASIC_AUTH_USER, username); 
    params.set(HttpClientUtil.PROP_BASIC_AUTH_PASS, password); 
    params.set(HttpClientUtil.PROP_CONNECTION_TIMEOUT, 12345); 
    params.set(HttpClientUtil.PROP_FOLLOW_REDIRECTS, true); 
    params.set(HttpClientUtil.PROP_MAX_CONNECTIONS, 22345); 
    params.set(HttpClientUtil.PROP_MAX_CONNECTIONS_PER_HOST, 32345); 
    params.set(HttpClientUtil.PROP_SO_TIMEOUT, 42345); 
    params.set(HttpClientUtil.PROP_USE_RETRY, false); 
    HttpClient httpClient = HttpClientUtil.createClient(params); 
    HttpSolrServer httpSolrServer = new HttpSolrServer("http://" + host + ":" + port + "/solr/", httpClient); 
    return httpSolrServer; 
} 

但是當我要保存的文件,此異常情況:

14:28:45,863 Caused by: org.apache.http.client.NonRepeatableRequestException: Cannot retry request with a non-repeatable request entity. 

14:28:45,863 at org.apache.http.impl.client.DefaultRequestDirector.tryExecute(DefaultRequestDirector.java:660) 

14:28:45,863 at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:486) 

14:28:45,863 at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:863) 

請幫幫我。

回答

0

直到這是固定的, createClient之前實施PreemptiveAuthInterceptor和addRequestInterceptor

樣品可在 https://github.com/codelibs/solrlib/blob/master/src/main/java/org/codelibs/solr/lib/server/interceptor/PreemptiveAuthInterceptor.java

例如

ModifiableSolrParams params = new ModifiableSolrParams(); 
params.add(HttpClientUtil.PROP_BASIC_AUTH_USER, uname); 
params.add(HttpClientUtil.PROP_BASIC_AUTH_PASS, pwd); 
params.add(HttpClientUtil.PROP_BASIC_AUTH_PASS, pwd); 
HttpClientUtil.addRequestInterceptor(new  PreemptiveAuthInterceptor());  
CloseableHttpClient httpclient = HttpClientUtil.createClient(params);