Skip to content

Commit

Permalink
Uncaught exceptions may cause LogFilter to fail, with dire consequenc…
Browse files Browse the repository at this point in the history
…es. Issue #931. Reported and contributed by Tal Liron.
  • Loading branch information
Thierry Boileau committed Aug 8, 2014
1 parent 436c544 commit 4975911
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 15 deletions.
4 changes: 3 additions & 1 deletion build/tmpl/text/changes.txt
Expand Up @@ -6,7 +6,9 @@ Changes log
- @version-full@ (@release-date@)
- Bugs fixed
- Fixed potential NPE in odata extension when schema ComplexType in a
document does not declare a schema attribute (issue #932).
document does not declare a schema attribute. Issue #932.
- Uncaught exceptions may cause LogFilter to fail, with dire consequences.
Issue #931. Reported and contributed by Tal Liron.

- Enhancements
- Added targetRef support to templates, allow reference variables to
Expand Down
Expand Up @@ -153,9 +153,6 @@ public void handle(ServerCall httpCall) {
getAdapter().commit(response);
} catch (Exception e) {
getLogger().log(Level.WARNING,
"Error while handling an HTTP server call: ",
e.getMessage());
getLogger().log(Level.INFO,
"Error while handling an HTTP server call", e);
} finally {
Engine.clearThreadLocalVariables();
Expand Down
17 changes: 11 additions & 6 deletions modules/org.restlet/src/org/restlet/engine/log/LogFilter.java
Expand Up @@ -99,12 +99,17 @@ public LogFilter(Context context, LogService logService) {
*/
@Override
protected void afterHandle(Request request, Response response) {
if (request.isLoggable() && this.logLogger.isLoggable(Level.INFO)) {
long startTime = (Long) request.getAttributes().get(
"org.restlet.startTime");
int duration = (int) (System.currentTimeMillis() - startTime);
this.logLogger.log(Level.INFO,
this.logService.getResponseLogMessage(response, duration));
try {
if (request.isLoggable() && this.logLogger.isLoggable(Level.INFO)) {
long startTime = (Long) request.getAttributes().get(
"org.restlet.startTime");
int duration = (int) (System.currentTimeMillis() - startTime);
this.logLogger.log(Level.INFO,
this.logService.getResponseLogMessage(response, duration));
}
} catch (Throwable e) {
// Error while logging the call, cf issue #931
getLogger().log(Level.SEVERE, "Cannot log call", e);
}
}

Expand Down
19 changes: 14 additions & 5 deletions modules/org.restlet/src/org/restlet/service/LogService.java
Expand Up @@ -33,6 +33,7 @@

package org.restlet.service;

import java.util.logging.Level;
import java.util.logging.LogManager;

import org.restlet.Context;
Expand All @@ -41,6 +42,7 @@
import org.restlet.data.Method;
import org.restlet.data.Reference;
import org.restlet.data.Status;
import org.restlet.engine.Engine;
import org.restlet.engine.log.LogFilter;
import org.restlet.representation.Representation;
import org.restlet.resource.ClientResource;
Expand Down Expand Up @@ -237,11 +239,18 @@ protected String getDefaultResponseLogMessage(Response response,
// Append the received size
sb.append('\t');

if (request.getEntity() == null) {
sb.append('0');
} else {
sb.append((request.getEntity().getSize() == -1) ? "-" : Long
.toString(request.getEntity().getSize()));
try {
if (request.getEntity() == null) {
sb.append('0');
} else {
sb.append((request.getEntity().getSize() == -1) ? "-"
: Long.toString(request.getEntity().getSize()));
}
} catch (Throwable t) {
// Error while getting the request's entity, cf issue #931
Engine.getLogger(LogService.class).log(Level.SEVERE,
"Cannot retrieve size of request's entity", t);
sb.append("-");
}

// Append the duration
Expand Down

0 comments on commit 4975911

Please sign in to comment.