Reviewers: dev-remailer_shindig.apache.org,
Message:
I am thinking of adding a protected method to move the logic after
rendering done in GadgetRenderingServlet.
Hopefully this will result in less work/code duplication for developers
when customizing the GadgetRenderingServlet behavior. Developers can
just extend from GadgetRenderingServlet and override the
GadgetRenderingServlet.postGadgetRendering method to override the
default behavior.
Thoughts?
- Henry
Description:
Move the post rendering logic to a protected method to allow developers
to extend from GadgetRenderingServlet but adding its own custom logic to
process the rendering results.
This will help reduce the amount of code developers need to code to just
have additional logic after rendering the gadget.
Please review this at http://codereview.appspot.com/1665054/show
Affected files:
java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/GadgetRenderingServlet.java
Index:
java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/GadgetRenderingServlet.java
===================================================================
---
java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/GadgetRenderingServlet.java
(revision 966415)
+++
java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/GadgetRenderingServlet.java
(working copy)
@@ -77,6 +77,26 @@
initialized = true;
}
+ @Override
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
+ // If an If-Modified-Since header is ever provided, we always say
+ // not modified. This is because when there actually is a change,
+ // cache busting should occur.
+ UriStatus urlstatus = getUrlStatus(req);
+ if (req.getHeader("If-Modified-Since") != null &&
+ !"1".equals(req.getParameter("nocache")) &&
+ urlstatus == UriStatus.VALID_VERSIONED) {
+ resp.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
+ return;
+ }
+ render(req, resp, urlstatus);
+ }
+
+ @Override
+ protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
+ render(req, resp, getUrlStatus(req));
+ }
+
private void render(HttpServletRequest req, HttpServletResponse resp,
UriStatus urlstatus)
throws IOException {
if (req.getHeader(HttpRequest.DOS_PREVENTION_HEADER) != null) {
@@ -92,6 +112,17 @@
GadgetContext context = new HttpGadgetContext(req);
RenderingResults results = renderer.render(context);
+
+ // process the rendering results
+ postGadgetRendering(req, resp, urlstatus, context, results);
+ }
+
+ /**
+ * Overrideable method to allow post processing after gadget rendering.
+ *
+ */
+ protected void postGadgetRendering(HttpServletRequest req,
HttpServletResponse resp,
+ UriStatus urlstatus, GadgetContext context, RenderingResults
results) throws IOException {
switch (results.getStatus()) {
case OK:
if (context.getIgnoreCache() ||
@@ -127,26 +158,6 @@
}
}
- @Override
- protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
- // If an If-Modified-Since header is ever provided, we always say
- // not modified. This is because when there actually is a change,
- // cache busting should occur.
- UriStatus urlstatus = getUrlStatus(req);
- if (req.getHeader("If-Modified-Since") != null &&
- !"1".equals(req.getParameter("nocache")) &&
- urlstatus == UriStatus.VALID_VERSIONED) {
- resp.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
- return;
- }
- render(req, resp, urlstatus);
- }
-
- @Override
- protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
- render(req, resp, getUrlStatus(req));
- }
-
private UriStatus getUrlStatus(HttpServletRequest req) {
return iframeUriManager.validateRenderingUri(new
UriBuilder(req).toUri());
}