开发者

Configuring HttpClient in Spring using Basic Authentication

I'm implem开发者_运维百科enting a SOLR server in our application. We use the CommonsHttpSolrServer in the SolrJ package to connect to our solr server which uses the commons-httpclient. We also use Spring.

Now our sysadmin secured the solr server (with good reason) and used Basic Auth.

How can I instantiate a HttpClient with Basic Auth to be injected in the SolrJ?

e.g.

<bean id="httpSolrServer" class="org.apache.solr.client.solrj.impl.CommonsHttpSolrServer">
    <constructor-arg value="${solrserver_path}" />
    <constructor-arg ref="solrHttpClient" />
</bean>

Thanks!


Unfortunately, you have to use a factory that creates the client. There is no bean property for credentials in the classes involved in authentication, namely HttpState.setCredentials(AuthScope, Credentials) which isn't a bean property.

I uploaded my HttpClientFactory to github. Se also the snippet for the spring context.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜