Message requestMessage = messageFactory.createMessage();
Message responseMessage = getFeedInvoker.invoke(requestMessage);
if (responseMessage.isFault()) {
throw new ServletException((Throwable)responseMessage.getBody());
}
Feed feed = (Feed)responseMessage.getBody();
if (feed != null) {
// Write the Atom feed
response.setContentType("application/atom+xml; charset=utf-8");
feed.setFeedType(requestFeedType);
WireFeedOutput feedOutput = new WireFeedOutput();
try {
OutputStream output = response.getOutputStream();
feedOutput.output(feed, new PrintWriter(output));
} catch (FeedException e) {
throw new ServletException(e);
}
} else {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
}
} else if (path.startsWith("/")) {
// Return a specific entry in the collection
// Get the entry from the service implementation
Message requestMessage = messageFactory.createMessage();
String id = path.substring(1);
requestMessage.setBody(new Object[] {id});
Message responseMessage = getInvoker.invoke(requestMessage);
if (responseMessage.isFault()) {
throw new ServletException((Throwable)responseMessage.getBody());
}
Entry entry = responseMessage.getBody();
// Write the Atom entry
if (entry != null) {
response.setContentType("application/atom+xml; charset=utf-8");
try {
AtomEntryUtil.writeEntry(entry, feedType, response.getWriter());
} catch (FeedException e) {
throw new ServletException(e);
}
} else {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
}
} else {
// Path doesn't match any known pattern
response.sendError(HttpServletResponse.SC_NOT_FOUND);
}
} else {
// Handle an RSS request
if (path == null || path.length() == 0 || path.equals("/")) {
// Get the Feed from the service
Message requestMessage = messageFactory.createMessage();
Message responseMessage = getFeedInvoker.invoke(requestMessage);
if (responseMessage.isFault()) {
throw new ServletException((Throwable)responseMessage.getBody());
}
Feed feed = (Feed)responseMessage.getBody();
if (feed != null) {
// Convert to an RSS feed
response.setContentType("application/rss+xml; charset=utf-8");
feed.setFeedType("atom_1.0");
SyndFeed syndFeed = new SyndFeedImpl(feed);
syndFeed.setFeedType(requestFeedType);
SyndFeedOutput syndOutput = new SyndFeedOutput();
try {
OutputStream output = response.getOutputStream();