WebDAV: don't log ERROR-level stack trace for badly formed XML request body.

* Not an error condition as such, it's a bad request, and we handle it properly.
* Debug-level logging shows appropriate message (e.g. Malformed request body)
* Trace-level logging shows message and prints stack trace



git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@35678 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Matt Ward
2012-04-25 13:45:03 +00:00
parent 19d1da8cd8
commit 4d9e699858

View File

@@ -78,6 +78,7 @@ import org.w3c.dom.Document;
import org.xml.sax.Attributes; import org.xml.sax.Attributes;
import org.xml.sax.InputSource; import org.xml.sax.InputSource;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
/** /**
@@ -315,14 +316,43 @@ public abstract class WebDAVMethod
/** /**
* Executes the method, wrapping the call to {@link #executeImpl()} in an appropriate transaction * Executes the method, wrapping the call to {@link #executeImpl()} in an appropriate transaction
* and handling the error conditions. * and handling the error conditions.
* @throws IOException
*/ */
public void execute() throws WebDAVServerException public void execute() throws WebDAVServerException, IOException
{ {
// Parse the HTTP headers // Parse the HTTP headers
parseRequestHeaders(); parseRequestHeaders();
// Parse the HTTP body // Parse the HTTP body
parseRequestBody(); try
{
parseRequestBody();
}
catch (WebDAVServerException e)
{
if (e.getCause() != null && e.getCause() instanceof SAXParseException)
{
SAXParseException saxParseEx = (SAXParseException) e.getCause();
if (logger.isTraceEnabled())
{
// Include stack trace.
logger.trace("Malformed request body", saxParseEx);
}
else if (logger.isDebugEnabled())
{
// Log message only.
logger.debug("Malformed request body: " + saxParseEx.getMessage());
}
m_response.sendError(e.getHttpStatusCode());
// Halt processing.
return;
}
else
{
// Rethrow the exception, as we haven't dealt with it here.
throw e;
}
}
m_userAgent = m_request.getHeader(WebDAV.HEADER_USER_AGENT); m_userAgent = m_request.getHeader(WebDAV.HEADER_USER_AGENT);
@@ -403,18 +433,26 @@ public abstract class WebDAVMethod
} }
finally finally
{ {
// Remove temporary file if created cleanUp();
if (this.m_requestBody != null) }
}
/**
* Clean up resources if about to finish processing the request.
*/
private void cleanUp()
{
// Remove temporary file if created
if (this.m_requestBody != null)
{
try
{ {
try this.m_requestBody.delete();
{ this.m_requestBody = null;
this.m_requestBody.delete(); }
this.m_requestBody = null; catch (Throwable t)
} {
catch (Throwable t) WebDAVMethod.logger.error("Failed to delete temp file", t);
{
WebDAVMethod.logger.error("Failed to delete temp file", t);
}
} }
} }
} }