// Return a 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;
if (request.getQueryString() != null) {
requestMessage.setBody(new Object[] {request.getQueryString()});
responseMessage = queryInvoker.invoke(requestMessage);
} else {
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 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());
}
Entry<Object, Object>[] collection =
(Entry<Object, Object>[])responseMessage.getBody();
if (collection != null) {
// Create the feed
feed = abderaFactory.newFeed();
// Set the feed title
if (title != null) {
feed.setTitle(title);
} else {
feed.setTitle("Feed");
}
// Add entries to the feed
for (Entry<Object, Object> entry: collection) {
org.apache.abdera.model.Entry feedEntry = feedEntry(entry, itemClassType, itemXMLType, mediator, abderaFactory);
feed.addEntry(feedEntry);
}
}
}
if (feed != null) {
// Write the Atom feed
response.setContentType("application/atom+xml; charset=utf-8");
try {
feed.getDocument().writeTo(response.getOutputStream());
} catch (IOException ioe) {
throw new ServletException(ioe);
}
} else {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
}
} else if (path.startsWith("/")) {
// Return a specific entry in the collection
org.apache.abdera.model.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
Entry<Object, Object> entry = new Entry<Object, Object>(id, responseMessage.getBody());
feedEntry = feedEntry(entry, itemClassType, itemXMLType, mediator, abderaFactory);
}
// Write the Atom entry
if (feedEntry != null) {