简体   繁体   中英

Apache Camel RSS module with basic authentication

I am trying to use Apache Camel's rss module to use an basic authentication protected RSS feed as Endpoint . However, I can't find any documentation how to pass it the user credentials . Does anybody know how to do this? Good workarounds are also appreciated!

I think it's not possible at the moment. camel-rss uses rome to read RSS Feeds. Take a look to the code of 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);
    }
}

To use basic authentication there must be something like

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);
    }
}

This is the way described here --> rome-xmlreader-not-reading-https-feed

I opened a new ticket for this feature. --> CAMEL-9009

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM