001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.util.axis;
016    
017    import com.liferay.portal.kernel.log.Log;
018    import com.liferay.portal.kernel.log.LogFactoryUtil;
019    import com.liferay.portal.kernel.servlet.BaseFilter;
020    import com.liferay.portal.kernel.util.ReflectionUtil;
021    
022    import java.lang.reflect.Field;
023    
024    import javax.servlet.FilterChain;
025    import javax.servlet.http.HttpServletRequest;
026    import javax.servlet.http.HttpServletResponse;
027    
028    import org.apache.axis.utils.cache.MethodCache;
029    
030    /**
031     * @author Shuyang Zhou
032     * @author Brian Wing Shun Chan
033     */
034    public class AxisCleanUpFilter extends BaseFilter {
035    
036            protected Log getLog() {
037                    return _log;
038            }
039    
040            protected void processFilter(
041                            HttpServletRequest request, HttpServletResponse response,
042                            FilterChain filterChain)
043                    throws Exception {
044    
045                    try {
046                            processFilter(
047                                    AxisCleanUpFilter.class, request, response, filterChain);
048                    }
049                    finally {
050                            try {
051                                    ThreadLocal<?> cacheThreadLocal =
052                                            (ThreadLocal<?>)_cacheField.get(null);
053    
054                                    if (cacheThreadLocal != null) {
055                                            cacheThreadLocal.remove();
056                                    }
057                            }
058                            catch (Exception e) {
059                                    _log.error(e, e);
060                            }
061                    }
062            }
063    
064            private static Log _log = LogFactoryUtil.getLog(AxisCleanUpFilter.class);
065    
066            private static Field _cacheField;
067    
068            static {
069                    try {
070                            _cacheField = ReflectionUtil.getDeclaredField(
071                                    MethodCache.class, "cache");
072                    }
073                    catch (Exception e) {
074                            _log.error(e, e);
075                    }
076            }
077    
078    }