3

ここで基本認証を設定するためのこのシーケンスを見つけました:

HttpClient client = new HttpClient();

client.getState().setCredentials(
   new AuthScope("www.domain.com", 443, "realm"),
   new UsernamePasswordCredentials("username", "password") );

スプリング構成を使用してこれをどのように達成できますか?背後にある理由は、スプリング統合HttpOutboundGatewayの認証を有効にする必要があるためです。このトピックで私が見つけた唯一の情報はこれです

  • 問題は、スプリング構成をどのように行うかです。
  • 次に、HttpClientをスプリング統合に注入するにはどうすればよいですか?
4

2 に答える 2

5

まあ、それはそのようなものかもしれません:(注、何もテストされていません-それは単なる一連のランダムな考えです:))

<bean id="httpOutbound" class="org.springframework.integration.http.HttpOutboundEndpoint" >
    <property name="requestExecutor" ref="executor" />
</bean>

<bean id="executor" class="org.springframework.integration.http.CommonsHttpRequestExecutor">
    <property name="httpClient">
        <bean factory-bean="clientFactory" factory-method="getHttpClient">
    </property>
</bean>

<bean id="clientFactory" class="bla.bla.bla.HttpClientFactoryBean">
    <constructor-arg ref="httpClient" />
    <constructor-arg ref="credentials" />
</bean>

<bean id="httpClient" class="org.apache.commons.httpclient.HttpClient">
    <constructor-arg ref="httpClientParams" />
</bean>

<bean id="httpClientParams" class="org.apache.commons.httpclient.params.HttpClientParams">
    <property name="authenticationPreemptive" value="true" />
    <property name="connectionManagerClass" value="org.apache.commons.httpclient.MultiThreadedHttpConnectionManager" />
</bean>

<bean id="credentials" class="org.apache.commons.httpclient.UsernamePasswordCredentials">
    <constructor-arg value="user" />
    <constructor-arg value="password" />
</bean>


public class HttpClientFactoryBean{
    private HttpClient httpClient;
    public HttpClientFactoryBean(HttpClient httpClient, Credentials credentials){
        this.httpClient = httpClient;
        httpClient.getState().setCredentials(AuthScope.ANY, credentials);
    }

    public HttpClient getHttpClient(){
        return httpClient;
    }
}
于 2010-11-16T15:19:56.520 に答える
1

FactoryBean好きな設定で HttpClient インスタンスを返す独自のクラスを作成します。

于 2010-11-16T14:59:36.780 に答える