title: outbound-gateway with Basic Authentication in spring-integration
body: <p>With spring-integration I would like to call an outbound-gateway with an Basic Authentication.
  I have something like this :</p>
  
  <pre><code>&lt;int-http:inbound-gateway id="versionRequestGateway" 
      supported-methods="POST" request-channel="requestVersionChannel"
      reply-channel="requestTransformerVersionChannel" 
      path="/consultersite" reply-timeout="10000" request-payload-type="java.lang.String"&gt;
  &lt;/int-http:inbound-gateway&gt;
  &lt;int-http:outbound-gateway order="1" request-channel="requestVersionChannel"
      url-expression="@urlExpressionGateway.getUrlFor(payload) + '/consultersite'"
      reply-channel="responseVersionChannel"
      http-method="POST" 
      expected-response-type="java.lang.String" &gt;
  &lt;/int-http:outbound-gateway&gt;
  </code></pre>
  
  <p>The URL of outbound-gateway is dynamic.</p>
  
  <p>I decide to use rest-template attribute on the outbound-gateway, with this :</p>
  
  <pre><code>&lt;bean id="httpClientParams" class="org.apache.commons.httpclient.params.HttpClientParams"&gt;
      &lt;property name="authenticationPreemptive" value="true"/&gt;
      &lt;property name="connectionManagerClass" value="org.apache.commons.httpclient.MultiThreadedHttpConnectionManager"/&gt;
  &lt;/bean&gt;
  &lt;bean id="httpClient" class="org.apache.commons.httpclient.HttpClient"&gt;
      &lt;constructor-arg ref="httpClientParams"/&gt;
  &lt;/bean&gt;
  &lt;bean id="httpClientFactory" class="org.springframework.http.client.CommonsClientHttpRequestFactory"&gt;
      &lt;constructor-arg ref="httpClient"/&gt;
  &lt;/bean&gt;
  &lt;bean id="restTemplate" class="org.springframework.web.client.RestTemplate"&gt;
      &lt;constructor-arg ref="httpClientFactory"/&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>It's work when I inject an UsernamePasswordCredentials in an ApplicationListener after spring application context is loaded.</p>
  
  <pre><code>HttpClient client = ctx.getBean("httpClient", HttpClient.class);
  UsernamePasswordCredentials credentials = new UsernamePasswordCredentials("username", "password");
  client.getState().setCredentials(AuthScope.ANY, credentials);
  </code></pre>
  
  <p>But according the url of outbound-gateway, username and password are different.
  How can I do to use the good username/password according the url outbound-gateway ?</p>
  
  <p>It was necessary to implement my own BasicSecureSimpleClientHttpRequestFactory extends SimpleClientHttpRequestFactory to map information Credentials according to the URL of connection. Hope an implementation Spring will be available one day ...
  Thanks.</p>