ace-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r1325685 - in /ace/trunk/ace-obr-servlet/src/main/java/org/apache/ace/obr/servlet: Activator.java BundleServlet.java
Date Fri, 13 Apr 2012 09:33:16 GMT
Author: jawi
Date: Fri Apr 13 09:33:15 2012
New Revision: 1325685

URL: http://svn.apache.org/viewvc?rev=1325685&view=rev
Log:
ACE-260: lowered the loglevel for EOFExceptions that occur quite frequently while adding/uploading
artifacts. The exception is explainable due to the fact that ArtifactRecognizers only download
parts of an artifact.

Modified:
    ace/trunk/ace-obr-servlet/src/main/java/org/apache/ace/obr/servlet/Activator.java
    ace/trunk/ace-obr-servlet/src/main/java/org/apache/ace/obr/servlet/BundleServlet.java

Modified: ace/trunk/ace-obr-servlet/src/main/java/org/apache/ace/obr/servlet/Activator.java
URL: http://svn.apache.org/viewvc/ace/trunk/ace-obr-servlet/src/main/java/org/apache/ace/obr/servlet/Activator.java?rev=1325685&r1=1325684&r2=1325685&view=diff
==============================================================================
--- ace/trunk/ace-obr-servlet/src/main/java/org/apache/ace/obr/servlet/Activator.java (original)
+++ ace/trunk/ace-obr-servlet/src/main/java/org/apache/ace/obr/servlet/Activator.java Fri
Apr 13 09:33:15 2012
@@ -19,7 +19,6 @@
 package org.apache.ace.obr.servlet;
 
 import javax.servlet.Servlet;
-import javax.servlet.http.HttpServlet;
 
 import org.apache.ace.obr.storage.BundleStore;
 import org.apache.felix.dm.DependencyActivatorBase;

Modified: ace/trunk/ace-obr-servlet/src/main/java/org/apache/ace/obr/servlet/BundleServlet.java
URL: http://svn.apache.org/viewvc/ace/trunk/ace-obr-servlet/src/main/java/org/apache/ace/obr/servlet/BundleServlet.java?rev=1325685&r1=1325684&r2=1325685&view=diff
==============================================================================
--- ace/trunk/ace-obr-servlet/src/main/java/org/apache/ace/obr/servlet/BundleServlet.java
(original)
+++ ace/trunk/ace-obr-servlet/src/main/java/org/apache/ace/obr/servlet/BundleServlet.java
Fri Apr 13 09:33:15 2012
@@ -18,20 +18,24 @@
  */
 package org.apache.ace.obr.servlet;
 
+import static javax.servlet.http.HttpServletResponse.SC_NOT_FOUND;
+
+import java.io.Closeable;
+import java.io.EOFException;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.Dictionary;
+
 import javax.servlet.ServletOutputStream;
 import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+
 import org.apache.ace.obr.storage.BundleStore;
 import org.osgi.service.cm.ConfigurationException;
 import org.osgi.service.cm.ManagedService;
 import org.osgi.service.log.LogService;
 
-import static javax.servlet.http.HttpServletResponse.*;
-
 public class BundleServlet extends HttpServlet implements ManagedService {
     public static final String TEXT_MIMETYPE = "text/plain";
 
@@ -41,6 +45,16 @@ public class BundleServlet extends HttpS
     private volatile LogService m_log; /* will be injected by dependencymanager */
     private volatile BundleStore m_store; /* will be injected by dependencymanager */
 
+    @Override
+    public String getServletInfo() {
+        return "Apache ACE OBR Servlet";
+    }
+
+    @SuppressWarnings("unchecked")
+    public void updated(Dictionary settings) throws ConfigurationException {
+        // nothing needs to be done, settings are propagated by the dependency manager
+    }
+
     /**
      * Responds to POST requests sent to http://host:port/obr/resource by writing the received
data to the bundle store.
      * Will send out a response that contains one of the following status codes:
@@ -90,6 +104,7 @@ public class BundleServlet extends HttpS
             sendResponse(response, HttpServletResponse.SC_BAD_REQUEST);
         }
         else {
+            // Remove leading slash...
             String id = path.substring(1);
             try {
                 if (m_store.remove(id)) {
@@ -124,48 +139,54 @@ public class BundleServlet extends HttpS
             sendResponse(response, HttpServletResponse.SC_BAD_REQUEST);
         }
         else {
+            // Remove leasing slash...
             String id = path.substring(1);
+
             ServletOutputStream output = null;
+            InputStream fileStream = null;
             try {
-                InputStream fileStream = null;
-                try {
-                    fileStream = m_store.get(id);
-                    if (fileStream != null) {
-                        // send the bundle as stream to the caller
-                        response.setContentType(TEXT_MIMETYPE);
-                        output = response.getOutputStream();
-                        byte[] buffer = new byte[COPY_BUFFER_SIZE];
-                        for (int bytes = fileStream.read(buffer); bytes != -1; bytes = fileStream.read(buffer))
{
-                            output.write(buffer, 0, bytes);
-                        }
-                    }
-                    else {
-                        sendResponse(response, HttpServletResponse.SC_NOT_FOUND);
-                    }
+                fileStream = m_store.get(id);
+                if (fileStream == null) {
+                    sendResponse(response, HttpServletResponse.SC_NOT_FOUND);
                 }
-                finally {
-                    if (fileStream != null) {
-                        try {
-                            fileStream.close();
-                        }
-                        catch (IOException ioe) {
-                            m_log.log(LogService.LOG_WARNING, "Exception closing the stream
" + request.getRequestURL(), ioe);
-                        }
+                else {
+                    // send the bundle as stream to the caller
+                    response.setContentType(TEXT_MIMETYPE);
+
+                    output = response.getOutputStream();
+                    byte[] buffer = new byte[COPY_BUFFER_SIZE];
+                    for (int bytes = fileStream.read(buffer); bytes != -1; bytes = fileStream.read(buffer))
{
+                        output.write(buffer, 0, bytes);
                     }
                 }
             }
+            catch (EOFException ex) {
+                // ACE-260: lower log-level of this exception; as it is probably because
the remote hung up early...
+                m_log.log(LogService.LOG_DEBUG, "EOF Exception in request: " + request.getRequestURL()
+ "; probably the remote hung up early.");
+            }
             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);
             }
             finally {
-                try {
-                    if (output != null) {
-                        output.close();
-                    }
-                }
-                catch (Exception ex) {
-                    m_log.log(LogService.LOG_WARNING, "Exception trying to close stream after
request: " + request.getRequestURL(), ex);
-                }
+                closeSafely(fileStream, request);
+                closeSafely(output, request);
+            }
+        }
+    }
+    
+    private void closeSafely(Closeable resource, HttpServletRequest request) {
+        if (resource != null) {
+            try {
+                resource.close();
+            }
+            catch (EOFException ex) {
+                // ACE-260: lower log-level of this exception; as it is probably because
the remote hung up early...
+                m_log.log(LogService.LOG_DEBUG, "EOF Exception trying to close stream: "
+ request.getRequestURL() + "; probably the remote hung up early.");
+            }
+            catch (Exception ex) {
+                // ACE-260: all other exception are logged, as we might have a possible resource
leak...
+                m_log.log(LogService.LOG_WARNING, "Exception trying to close stream: " +
request.getRequestURL(), ex);
             }
         }
     }
@@ -184,14 +205,4 @@ public class BundleServlet extends HttpS
             m_log.log(LogService.LOG_WARNING, "Unable to send response with status code '"
+ statusCode + "'", e);
         }
     }
-
-    @Override
-    public String getServletInfo() {
-        return "Apache ACE OBR Servlet";
-    }
-
-    @SuppressWarnings("unchecked")
-    public void updated(Dictionary settings) throws ConfigurationException {
-        // nothing needs to be done, settings are propagated by the dependency manager
-    }
 }
\ No newline at end of file



Mime
View raw message