3
我使用ROME來生成RSS feed並將Jersey作爲REST服務。如何使用REST服務返回RSS?
這是我的RSS提要生成。
public SyndFeed generate()
{
SyndFeed feed = new SyndFeedImpl();
feed.setFeedType("rss_2.0");
feed.setTitle("My Site");
feed.setLink("http://example.com");
feed.setDescription("Test Site.");
List<SyndEntry> entries = new ArrayList<SyndEntry>();
SyndEntry entry = null;
SyndContent description = null;
entry = new SyndEntryImpl();
entry.setTitle("Entry1");
entry.setLink("http://example.com/entry1");
entry.setPublishedDate(new Date());
description = new SyndContentImpl();
description.setType("text/html");
description.setValue("This is the content of entry 1.");
entry.setDescription(description);
entries.add(entry);
feed.setEntries(entries);
return feed;
}
並獲得
@GET
@Path("/getFeed")
@Produces(MediaType.APPLICATION_XML)
public SyndFeed getFeed()
{
RSSFeed rssFeed = new RSSFeed();
return rssFeed.generate();
}
我得到一個錯誤的不兼容的類型身體作家飼料的方法。如何使服務返回XML與飼料?