【发布时间】:2015-07-22 15:05:29
【问题描述】:
我正在尝试使用 Apache Camel 的 rss module 将基本身份验证保护的 RSS 提要用作 Endpoint。但是,我找不到任何文档如何将用户凭据传递给它。有人知道怎么做这个吗?好的解决方法也值得赞赏!
【问题讨论】:
标签: java rss apache-camel basic-authentication
我正在尝试使用 Apache Camel 的 rss module 将基本身份验证保护的 RSS 提要用作 Endpoint。但是,我找不到任何文档如何将用户凭据传递给它。有人知道怎么做这个吗?好的解决方法也值得赞赏!
【问题讨论】:
标签: java rss apache-camel basic-authentication
我认为目前是不可能的。 camel-rss 使用 rome 来阅读 RSS 源。
看一下org.apache.camel.component.rss.RssUtils的代码:
public static SyndFeed createFeed(String feedUri, ClassLoader classLoader) throws Exception {
ClassLoader tccl = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(classLoader);
InputStream in = new URL(feedUri).openStream();
SyndFeedInput input = new SyndFeedInput();
return input.build(new XmlReader(in));
} finally {
Thread.currentThread().setContextClassLoader(tccl);
}
}
要使用基本身份验证,必须有类似
public static SyndFeed createFeed(String feedUri, ClassLoader classLoader) throws Exception {
ClassLoader tccl = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(classLoader);
URL feedUrl = new URL(feedUri);
HttpURLConnection httpcon = (HttpURLConnection)feedUrl.openConnection();
String encoding = new sun.misc.BASE64Encoder().encode("username:password".getBytes());
httpcon.setRequestProperty ("Authorization", "Basic " + encoding);
SyndFeedInput input = new SyndFeedInput();
return input.build(new XmlReader(httpcon));
} finally {
Thread.currentThread().setContextClassLoader(tccl);
}
}
这是这里描述的方式 --> rome-xmlreader-not-reading-https-feed
我为此功能开了一张新票。 --> CAMEL-9009
【讨论】: