我正在玩 Apache Camel,并且在从“琐碎示例”阶段过渡到“但有这些恼人的细节”阶段时遇到了一些问题。至关重要的是,如何明确地进入和修改端点。
在这种情况下,我需要为 http 客户端设置一个 auth cookie。我有一个 cookie 存储对象,但不知道如何强制客户端使用它。我试过使用HttpClientConfigurer
,但HttpClient
没有暴露 cookie 存储,而且它似乎也没有被调用。
我当前的代码:
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 => client.setCookieStore(cs)
}
}
}
并由以下人员调用:
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&delay=0&period=10000")
.to("https4://rt/REST/1.0/ticket/335729/show")
.to("file://test")
}
}
context.addRoutes(routes)
context.start()
System.in.read()
context.stop()
知道如何为"https4://rt/REST/1.0/ticket/335729/show"
端点设置 cookie 存储吗?