Author: fmui
Date: Thu Aug 18 11:13:27 2016
New Revision: 1756756
URL: http://svn.apache.org/viewvc?rev=1756756&view=rev
Log:
Server: don't flush the response if there was an IOException
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/CmisAtomPubServlet.java
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/CmisBrowserBindingServlet.java
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/CmisAtomPubServlet.java
URL:
http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/CmisAtomPubServlet.java?rev=1756756&r1=1756755&r2=1756756&view=diff
==============================================================================
---
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/CmisAtomPubServlet.java
(original)
+++
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/CmisAtomPubServlet.java
Thu Aug 18 11:13:27 2016
@@ -77,7 +77,6 @@ import org.apache.chemistry.opencmis.com
import org.apache.chemistry.opencmis.commons.server.CallContext;
import org.apache.chemistry.opencmis.commons.server.CmisService;
import org.apache.chemistry.opencmis.server.impl.ServerVersion;
-import
org.apache.chemistry.opencmis.server.impl.browser.AbstractBrowserServiceCall;
import org.apache.chemistry.opencmis.server.shared.AbstractCmisHttpServlet;
import org.apache.chemistry.opencmis.server.shared.Dispatcher;
import org.apache.chemistry.opencmis.server.shared.ExceptionHelper;
@@ -175,8 +174,9 @@ public class CmisAtomPubServlet extends
@Override
protected void service(HttpServletRequest request, HttpServletResponse
response) throws ServletException,
IOException {
-
CallContext context = null;
+
+ boolean flush = true;
try {
// CSRF token check
if (!METHOD_GET.equals(request.getMethod()) &&
!METHOD_HEAD.equals(request.getMethod())) {
@@ -209,13 +209,19 @@ public class CmisAtomPubServlet extends
response.setHeader("WWW-Authenticate", "Basic realm=\"CMIS\",
charset=\"UTF-8\"");
response.sendError(HttpServletResponse.SC_UNAUTHORIZED,
"Authorization Required");
} else if (e instanceof CmisPermissionDeniedException) {
- if ((context == null) || (context.getUsername() == null)) {
+ if (context == null || (context.getUsername() == null)) {
response.setHeader("WWW-Authenticate", "Basic
realm=\"CMIS\", charset=\"UTF-8\"");
response.sendError(HttpServletResponse.SC_UNAUTHORIZED,
"Authorization Required");
} else {
-
response.sendError(getErrorCode((CmisPermissionDeniedException) e),
e.getMessage());
+ printError(e, request, response);
}
} else {
+ // an IOException usually indicates that reading the request or
+ // sending the response failed
+ // flushing will probably fail and raise a new exception ->
+ // avoid flushing
+ flush = !(e instanceof IOException);
+
printError(e, request, response);
}
@@ -234,15 +240,18 @@ public class CmisAtomPubServlet extends
} catch (Exception te) {
// we tried to send an error message but it failed.
// there is nothing we can do...
+ flush = false;
}
throw t;
} finally {
// we are done.
- try {
- response.flushBuffer();
- } catch (IOException ioe) {
- LOG.error("Could not flush resposne: {}", ioe.toString(), ioe);
+ if (flush) {
+ try {
+ response.flushBuffer();
+ } catch (IOException ioe) {
+ LOG.error("Could not flush resposne: {}", ioe.toString(),
ioe);
+ }
}
}
}
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/CmisBrowserBindingServlet.java
URL:
http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/CmisBrowserBindingServlet.java?rev=1756756&r1=1756755&r2=1756756&view=diff
==============================================================================
---
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/CmisBrowserBindingServlet.java
(original)
+++
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/CmisBrowserBindingServlet.java
Thu Aug 18 11:13:27 2016
@@ -221,6 +221,7 @@ public class CmisBrowserBindingServlet e
IOException {
CallContext context = null;
+ boolean flush = true;
try {
// CSRF token check
String method = request.getMethod();
@@ -271,6 +272,12 @@ public class CmisBrowserBindingServlet e
printError(context, e, request, response);
}
} else {
+ // an IOException usually indicates that reading the request or
+ // sending the response failed
+ // flushing will probably fail and raise a new exception ->
+ // avoid flushing
+ flush = !(e instanceof IOException);
+
printError(context, e, request, response);
}
} catch (Throwable t) {
@@ -288,6 +295,7 @@ public class CmisBrowserBindingServlet e
} catch (Exception te) {
// we tried to send an error message but it failed.
// there is nothing we can do...
+ flush = false;
}
throw t;
@@ -305,10 +313,12 @@ public class CmisBrowserBindingServlet e
}
// we are done.
- try {
- response.flushBuffer();
- } catch (IOException ioe) {
- LOG.error("Could not flush resposne: {}", ioe.toString(), ioe);
+ if (flush) {
+ try {
+ response.flushBuffer();
+ } catch (IOException ioe) {
+ LOG.error("Could not flush resposne: {}", ioe.toString(),
ioe);
+ }
}
}
}