in modules/binding-gdata-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GdataBindingListenerServlet.java [165:382]
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// No authentication required for a get request
//System.out.println("[Debug Info]GdataBindingListenerServlet doGet() --- I am good here 00");
// Get the request path
String path = URLDecoder.decode(request.getRequestURI().substring(request.getServletPath().length()), "UTF-8");
//System.out.println("[Debug Info]GdataBindingListenerServlet doGet() --- request.getRequestURI(): " + request.getRequestURI());
//System.out.println("[Debug Info]GdataBindingListenerServlet doGet()--- path: " + path);
// FIXME: Log this get http request, commented out for testing
logger.fine("get " + request.getRequestURI());
// Handle an Atom request
if (path != null && path.equals("/atomsvc")) {
//FIXME: This needs to be fixed, for /atomsvc
/*
System.out.println("GdataBindingListenerServlet doGet(): I am good here brach 01");
// Return the Atom service document
response.setContentType("application/atomsvc+xml; charset=utf-8");
Service service = abderaFactory.newService();
// service.setText("service");
Workspace workspace = abderaFactory.newWorkspace();
workspace.setTitle("resource");
String href = request.getRequestURL().toString();
href = href.substring(0, href.length() - "/atomsvc".length());
Collection collection = workspace.addCollection("collection", "atom/feed");
collection.setTitle("entries");
collection.setAttributeValue("href", href);
collection.setAccept("entry");
collection.addCategories().setFixed(false);
workspace.addCollection(collection);
service.addWorkspace(workspace);
// FIXME add prettyPrint support
try {
service.getDocument().writeTo(response.getOutputStream());
} catch (IOException ioe) {
throw new ServletException(ioe);
}
*/
} else if (path == null || path.length() == 0 || path.equals("/")) {
// get HTTP request asking for a feed
//System.out.println("[Debug Info]GdataBindingListenerServlet doGet() --- I am good here brach 02");
// Return a feed containing the entries in the collection
com.google.gdata.data.Feed feed = null;
if (supportsFeedEntries) {
//System.out.println("[Debug Info]GdataBindingListenerServlet doGet() --- supportsFeedEntries: " + supportsFeedEntries);
// The service implementation supports feed entries, invoke its
// getFeed operation
Message requestMessage = messageFactory.createMessage();
Message responseMessage;
if (request.getQueryString() != null) {
//System.out.println("getQueryString != null");
requestMessage.setBody(new Object[] {request.getQueryString()});
responseMessage = queryInvoker.invoke(requestMessage);
} else {
//System.out.println("getQueryString == null");
responseMessage = getFeedInvoker.invoke(requestMessage);
}
if (responseMessage.isFault()) {
throw new ServletException((Throwable)responseMessage.getBody());
}
//System.out.println("response msg class:" + responseMessage.getBody().getClass());
feed = (com.google.gdata.data.Feed)responseMessage.getBody();
//System.out.println("feed title: " + feed.getTitle().getPlainText());
} else {
//System.out.println("GdataBindingListenerServlet doGet(): do not supportsFeedEntries");
// 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);
//System.out
// .println("GdataBindingListner.doGet(): get msg from getAllInvoker.invoke()" + responseMessage
// .getBody().toString());
}
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 = new com.google.gdata.data.Feed();
// Set the feed title
if (title != null) {
feed.setTitle(new PlainTextConstruct(title));
} else {
feed.setTitle(new PlainTextConstruct("Feed title"));
}
// Add entries to the feed
ArrayList<com.google.gdata.data.Entry> entries = new ArrayList<com.google.gdata.data.Entry>();
for (Entry<Object, Object> entry : collection) {
com.google.gdata.data.Entry feedEntry = feedEntry(entry, itemClassType, itemXMLType, mediator);
entries.add(feedEntry);
}
feed.setEntries(entries);
}
}
if (feed != null) {
// //System.out.println("feed(from the http response)is not
// null");
// Write a GData feed using Atom representation
response.setContentType("application/atom+xml; charset=utf-8");
// Generate the corresponding Atom representation of the feed
StringWriter stringWriter = new StringWriter();
com.google.gdata.util.common.xml.XmlWriter w =
new com.google.gdata.util.common.xml.XmlWriter(stringWriter);
feed.generateAtom(w, new ExtensionProfile());
w.flush();
// Write the Atom representation(XML) into Http response content
OutputStreamWriter osw = new OutputStreamWriter(response.getOutputStream());
PrintWriter out = new PrintWriter(response.getOutputStream());
out.println(stringWriter.toString());
out.close();
//System.out.println("Feed content in plain text:" + stringWriter.toString());
} else {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
}
} else if (path.startsWith("/")) {
// get HTTP request asking for an entry
// Return a specific entry in the collection
com.google.gdata.data.Entry feedEntry = null;
// 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 = (com.google.gdata.data.Entry)responseMessage.getBody();
//System.out.println("entry title: " + feedEntry.getTitle().getPlainText());
} 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());
// FIXME The line below needs to be fixed
// feedEntry = feedEntry(entry, itemClassType, itemXMLType,
// mediator, abderaFactory);
}
// Write the Gdata entry
if (feedEntry != null) {
// Write a GData entry using Atom representation
response.setContentType("application/atom+xml; charset=utf-8");
// Generate the corresponding Atom representation of the feed
StringWriter stringWriter = new StringWriter();
com.google.gdata.util.common.xml.XmlWriter w =
new com.google.gdata.util.common.xml.XmlWriter(stringWriter);
feedEntry.generateAtom(w, new ExtensionProfile());
w.flush();
// Write the Atom representation(XML) into Http response content
OutputStreamWriter osw = new OutputStreamWriter(response.getOutputStream());
PrintWriter out = new PrintWriter(response.getOutputStream());
out.println(stringWriter.toString());
out.close();
} else {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
}
} else {
// Path doesn't match any known pattern
response.sendError(HttpServletResponse.SC_NOT_FOUND);
}
}