if (collection != null) {
// Create the feed
feed = new Feed();
feed.setTitle("Feed");
for (org.apache.tuscany.sca.implementation.data.collection.Entry<Object, Object> entry: collection) {
Entry feedEntry = createFeedEntry(entry);
feed.getEntries().add(feedEntry);
}
}
}
if (feed != null) {
// Write the Atom feed
response.setContentType("application/atom+xml; charset=utf-8");
feed.setFeedType(requestFeedType);
WireFeedOutput feedOutput = new WireFeedOutput();
try {
feedOutput.output(feed, getWriter(response));
} 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
Entry feedEntry;
// Invoke the get operation on 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());
}
if (supportsFeedEntries) {
// The service implementation returns a feed entry
feedEntry = responseMessage.getBody();
} else {
// The service implementation only returns a data item, create an entry
// from it
feedEntry = createFeedEntry(new org.apache.tuscany.sca.implementation.data.collection.Entry<Object, Object>(id, responseMessage.getBody()));
}
// Write the Atom entry
if (feedEntry != null) {
response.setContentType("application/atom+xml; charset=utf-8");
try {
AtomFeedEntryUtil.writeFeedEntry(feedEntry, feedType, getWriter(response));
} 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("/")) {
// Return an RSS feed containing the entries in the collection
Feed feed = null;
if (supportsFeedEntries) {
// The service implementation supports feed entries, invoke its getFeed operation
Message requestMessage = messageFactory.createMessage();
Message responseMessage = getFeedInvoker.invoke(requestMessage);
if (responseMessage.isFault()) {
throw new ServletException((Throwable)responseMessage.getBody());
}
feed = (Feed)responseMessage.getBody();
} else {
// The service implementation does not support feed entries, invoke its
// getAll operation to get the data item collection. then create feed entries
// from the data items
Message requestMessage = messageFactory.createMessage();
Message responseMessage;
if (request.getQueryString() != null) {
requestMessage.setBody(new Object[] {request.getQueryString()});
responseMessage = queryInvoker.invoke(requestMessage);
} else {
responseMessage = getAllInvoker.invoke(requestMessage);
}
if (responseMessage.isFault()) {
throw new ServletException((Throwable)responseMessage.getBody());
}
org.apache.tuscany.sca.implementation.data.collection.Entry<Object, Object>[] collection =
(org.apache.tuscany.sca.implementation.data.collection.Entry<Object, Object>[])responseMessage.getBody();
if (collection != null) {
// Create the feed
feed = new Feed();
feed.setTitle("Feed");
for (org.apache.tuscany.sca.implementation.data.collection.Entry<Object, Object> entry: collection) {
Entry feedEntry = createFeedEntry(entry);
feed.getEntries().add(feedEntry);
}
}
}