Author: dashorst Date: Wed Jan 31 09:22:04 2007 New Revision: 501911 URL: http://svn.apache.org/viewvc?view=rev&rev=501911 Log: WICKET-241, WICKET-240, all stages in requestcycle called again by wrapping methods that can generate exceptions in a try/catch block. Possible NPE's in calculation of size also captured, which was the cause of resource leaks (e.g. non-closed database connections when resource clean up is done in requestcycle.detach)
Modified: incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/RequestCycle.java incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/protocol/http/RequestLogger.java incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/util/lang/Objects.java Modified: incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/RequestCycle.java URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/RequestCycle.java?view=diff&rev=501911&r1=501910&r2=501911 ============================================================================== --- incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/RequestCycle.java (original) +++ incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/RequestCycle.java Wed Jan 31 09:22:04 2007 @@ -890,14 +890,6 @@ // clear the used pagemap for this thread, // maybe we can move this a few lines above to have a but more // concurrency (session.update) - try - { - session.requestDetached(); - } - catch(RuntimeException re) - { - log.error("there was an error detaching the request from the session " + session + ".", re); - } if (getResponse() instanceof BufferedWebResponse) { try @@ -910,12 +902,28 @@ } } - IRequestLogger requestLogger = getApplication().getRequestLogger(); - if (requestLogger != null) + try + { + IRequestLogger requestLogger = getApplication().getRequestLogger(); + if (requestLogger != null) + { + requestLogger.requestTime((System.currentTimeMillis() - startTime)); + } + } + catch(RuntimeException re) + { + log.error("there was an error in the RequestLogger ending.", re); + } + + try { - requestLogger.requestTime((System.currentTimeMillis() - startTime)); + session.requestDetached(); + } + catch(RuntimeException re) + { + log.error("there was an error detaching the request from the session " + session + ".", re); } - + try { onEndRequest(); Modified: incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/protocol/http/RequestLogger.java URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/protocol/http/RequestLogger.java?view=diff&rev=501911&r1=501910&r2=501911 ============================================================================== --- incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/protocol/http/RequestLogger.java (original) +++ incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/protocol/http/RequestLogger.java Wed Jan 31 09:22:04 2007 @@ -202,13 +202,20 @@ RequestData rd = (RequestData)currentRequest.get(); if(rd != null) { + synchronized (this) + { + if(active > 0) + { + rd.setActiveRequest(active--); + } + } Session session = Session.get(); String sessionId = session.getId(); rd.setSessionId(sessionId); - + Object sessionInfo = getSessionInfo(session); rd.setSessionInfo(sessionInfo); - + long sizeInBytes = -1; if(Application.get().getRequestLoggerSettings().getRecordSessionSize()) { @@ -216,14 +223,7 @@ } rd.setSessionSize(sizeInBytes); rd.setTimeTaken(timeTaken); - synchronized (this) - { - if(active > 0) - { - rd.setActiveRequest(active--); - } - } - + requests.add(0, rd); currentRequest.set(null); if(sessionId != null) Modified: incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/util/lang/Objects.java URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/util/lang/Objects.java?view=diff&rev=501911&r1=501910&r2=501911 ============================================================================== --- incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/util/lang/Objects.java (original) +++ incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/util/lang/Objects.java Wed Jan 31 09:22:04 2007 @@ -1052,6 +1052,7 @@ */ public static long sizeof(final Object object) { + if (object == null) return 0; try { final ByteCountingOutputStream out = new ByteCountingOutputStream(); @@ -1059,9 +1060,10 @@ out.close(); return out.size(); } - catch (IOException e) + catch (Exception e) { - return -1; + log.warn("Size of failed of object: " + object.getClass().getName(), e); + return 0; } }