title: How to set basic authentication with apache camel and http4
body: <p>I'm trying to use Apache Camel's Http4 component to connect to a HTTP URL that needs Basic authentication. I'm setting credentials from a camel processor through <strong>Exchange.HTTP_QUERY</strong> header. I configure my route like this:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;blueprint ...&gt;
  
  &lt;bean id=&quot;myProcessor&quot;
      class=&quot;com.myCompany.Bean&quot;
      factory-method=&quot;myProcessorBean&quot;&gt;
  &lt;/bean&gt;
  
  &lt;camelContext id=&quot;myContext&quot; xmlns=&quot;http://camel.apache.org/schema/blueprint&quot;&gt;
      
      &lt;route id=&quot;myRoute&gt;
          &lt;from uri=&quot;activemq:queue:myQueue&quot; /&gt;
          &lt;process ref=&quot;myProcessor&quot; /&gt;
          &lt;to uri=&quot;http4://oldhost&quot;/&gt;
      &lt;/route&gt;
          
  &lt;/camelContext&gt;
  
  &lt;/blueprint&gt;
  </code></pre>
  <p>and my processor looks like:</p>
  <pre><code>public void process(Exchange exchange) throws Exception {
    String user = getUserFromDB();
    String pwd = getPasswordFromDB();
  
    String queryParameters = &quot;authMethod=Basic&amp;authPassword=&quot;+pwd+&quot;authUsername=&quot;+user;
    exchange.getIn().setHeader(Exchange.HTTP_QUERY, queryParameters);
    exchange.getIn().setHeader(Exchange.HTTP_URI, &quot;api.abc_company.com/service/to/consume&quot;);
    ....
  }
  </code></pre>
  <p>It results in:</p>
  <pre><code>Error myContext: org.apache.camel.http.common.HttpOperationFailedException: HTTP operation failed invoking https://api.abc_company.com/service/to/consume?authMethod=Basic&amp;authPassword=xxxxxx&amp;authUsername=test with statusCode: 401
  
  </code></pre>
  <p>It seems that <strong>password was changed to xxxxxx</strong> but I'm not sure.</p>
  <p>When I try hardcoding user and password in the URI it works well, however I need a way to set these values programmatically due to user and password are stored it the DB.</p>