title: Apache camel: set cookies for http4 client
body: <p>I'm having a play around with Apache Camel, and having a few problems transitioning from the 'trivial examples' stage to the 'but with these irritating details' stage. Crucially, how to go in and modify the endpoints explicitly.</p>
  
  <p>In this case, I need to set an auth cookie for the http client. I have a cookie store object, but don't know how to force the client to use it. I've tried using an <code>HttpClientConfigurer</code>, but <code>HttpClient</code> doesn't expose the cookie store, and it doesn't seem to be being called anyway.</p>
  
  <p>My current code:</p>
  
  <pre><code>class CookieClientConfigurer(cs: CookieStore) extends HttpClientConfigurer {
    /**
     * Not very nice, relying on a runtime type check. But what can you do?
     */
    def configureHttpClient(client: HttpClient) {
      client match {
        case client: AbstractHttpClient =&gt; client.setCookieStore(cs)
      }
    }
  }
  </code></pre>
  
  <p>And invoked by: </p>
  
  <pre><code>val username = args(0)
  val password = args(1)
  
  val context = new DefaultCamelContext
  
  locally {
    // First we need to grab some authentication cookie stuff!
    val httpClient = new DefaultHttpClient
    val post = new HttpPost("https://rt")
    val nvps = List(new BasicNameValuePair("username", username), new BasicNameValuePair("password", password))
    post.setEntity(new UrlEncodedFormEntity(asJavaList(nvps)))
    httpClient.execute(post)
    val ccc = new CookieClientConfigurer(httpClient.getCookieStore())
    val httpComp = context.getComponent("https4", classOf[HttpComponent])
    httpComp.setHttpClientConfigurer(ccc)
  }
  
  val routes = new RouteBuilder {
    def configure() = {
      from("timer://foo?fixedRate=true&amp;delay=0&amp;period=10000")
      .to("https4://rt/REST/1.0/ticket/335729/show")
      .to("file://test")
  
    }
  }
  context.addRoutes(routes)
  context.start()
  System.in.read()
  context.stop()
  </code></pre>
  
  <p>Any idea how I set the cookie store for the <code>"https4://rt/REST/1.0/ticket/335729/show"</code> endpoint?</p>