001// Copyright 2005 The Apache Software Foundation 002// 003// Licensed under the Apache License, Version 2.0 (the "License"); 004// you may not use this file except in compliance with the License. 005// You may obtain a copy of the License at 006// 007// http://www.apache.org/licenses/LICENSE-2.0 008// 009// Unless required by applicable law or agreed to in writing, software 010// distributed under the License is distributed on an "AS IS" BASIS, 011// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 012// See the License for the specific language governing permissions and 013// limitations under the License. 014 015package org.apache.tapestry.services.impl; 016 017import java.io.IOException; 018 019import org.apache.hivemind.ErrorLog; 020import org.apache.hivemind.HiveMind; 021import org.apache.tapestry.services.ResetEventHub; 022import org.apache.tapestry.services.WebRequestServicer; 023import org.apache.tapestry.services.WebRequestServicerFilter; 024import org.apache.tapestry.web.WebRequest; 025import org.apache.tapestry.web.WebResponse; 026 027/** 028 * Filter whose job is to invoke 029 * {@link org.apache.tapestry.services.ResetEventHub#fireResetEvent()}after the request has 030 * been processed. This filter is only contributed into the 031 * tapestry.request.WebRequestServicerPipeline configuration if the 032 * org.apache.tapestry.disable-caching system property is true. 033 * 034 * @author Howard M. Lewis Ship 035 * @since 4.0 036 */ 037public class DisableCachingFilter implements WebRequestServicerFilter 038{ 039 private ErrorLog _errorLog; 040 041 private ResetEventHub _resetEventHub; 042 043 public void service(WebRequest request, WebResponse response, WebRequestServicer servicer) 044 throws IOException 045 { 046 try 047 { 048 servicer.service(request, response); 049 } 050 finally 051 { 052 fireResetEvent(); 053 } 054 055 } 056 057 private void fireResetEvent() 058 { 059 try 060 { 061 _resetEventHub.fireResetEvent(); 062 } 063 catch (Exception ex) 064 { 065 _errorLog.error(ImplMessages.errorResetting(ex), HiveMind.getLocation(ex), ex); 066 } 067 } 068 069 public void setResetEventHub(ResetEventHub resetEventCoordinator) 070 { 071 _resetEventHub = resetEventCoordinator; 072 } 073 074 public void setErrorLog(ErrorLog errorLog) 075 { 076 _errorLog = errorLog; 077 } 078}