ace-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r1368897 - /ace/sandbox/marrs/org.apache.ace.obr.servlet/src/org/apache/ace/obr/servlet/BundleServlet.java
Date Fri, 03 Aug 2012 11:40:37 GMT
Author: jawi
Date: Fri Aug  3 11:40:37 2012
New Revision: 1368897

URL: http://svn.apache.org/viewvc?rev=1368897&view=rev
Log:
- Fixed a possible resource leak when returning files from the OBR;
- implemented a HEAD implementation to allow the OBR to be tested for
  the existance of files without having to retrieve its contents.


Modified:
    ace/sandbox/marrs/org.apache.ace.obr.servlet/src/org/apache/ace/obr/servlet/BundleServlet.java

Modified: ace/sandbox/marrs/org.apache.ace.obr.servlet/src/org/apache/ace/obr/servlet/BundleServlet.java
URL: http://svn.apache.org/viewvc/ace/sandbox/marrs/org.apache.ace.obr.servlet/src/org/apache/ace/obr/servlet/BundleServlet.java?rev=1368897&r1=1368896&r2=1368897&view=diff
==============================================================================
--- ace/sandbox/marrs/org.apache.ace.obr.servlet/src/org/apache/ace/obr/servlet/BundleServlet.java
(original)
+++ ace/sandbox/marrs/org.apache.ace.obr.servlet/src/org/apache/ace/obr/servlet/BundleServlet.java
Fri Aug  3 11:40:37 2012
@@ -216,6 +216,52 @@ public class BundleServlet extends HttpS
                 sendResponse(response, SC_INTERNAL_SERVER_ERROR);
             }
             finally {
+                closeSafely(fileStream, request);
+                closeSafely(output, request);
+            }
+        }
+    }
+    
+    /**
+     * Responds to HEAD requests sent to http://host:port/obr/resource with a stream to the
specified filename.
+     * Will send out a response that contains one of the following status codes:
+     * <br>
+     * <li><code>HttpServletResponse.SC_BAD_REQUEST</code> - if no resource
is specified
+     * <li><code>HttpServletResponse.SC_INTERNAL_SERVER_ERROR</code> -
if there was a problem storing the resource
+     * <li><code>HttpServletResponse.SC_NOT_FOUND</code> - if the requested
resource does not exist
+     * <li><code>HttpServletResponse.SC_OK</code> - if all went fine
+     * <br>
+     * The response is empty in all situations.
+     */
+    @Override
+    protected void doHead(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
+        String path = request.getPathInfo();
+        if ((path == null) || (path.length() <= 1)) {
+            sendResponse(response, SC_BAD_REQUEST);
+        }
+        else {
+            // Remove leasing slash...
+            String id = path.substring(1);
+
+            ServletOutputStream output = null;
+            InputStream fileStream = null;
+            try {
+            	// TODO extend the store with an exists method???
+                fileStream = m_store.get(id);
+                if (fileStream == null) {
+                    sendResponse(response, HttpServletResponse.SC_NOT_FOUND);
+                }
+                else {
+                    sendResponse(response, HttpServletResponse.SC_OK);
+                }
+            }
+            catch (IOException ex) {
+                // ACE-260: all other exception are logged, as we might have a possible resource
leak...
+                m_log.log(LogService.LOG_WARNING, "Exception in request: " + request.getRequestURL(),
ex);
+                sendResponse(response, SC_INTERNAL_SERVER_ERROR);
+            }
+            finally {
+                closeSafely(fileStream, request);
                 closeSafely(output, request);
             }
         }



Mime
View raw message