001    /**
002     * Copyright (c) 2000-2011 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            @Override
037            protected Log getLog() {
038                    return _log;
039            }
040    
041            @Override
042            protected void processFilter(
043                            HttpServletRequest request, HttpServletResponse response,
044                            FilterChain filterChain)
045                    throws Exception {
046    
047                    try {
048                            processFilter(
049                                    AxisCleanUpFilter.class, request, response, filterChain);
050                    }
051                    finally {
052                            try {
053                                    ThreadLocal<?> cacheThreadLocal =
054                                            (ThreadLocal<?>)_cacheField.get(null);
055    
056                                    if (cacheThreadLocal != null) {
057                                            cacheThreadLocal.remove();
058                                    }
059                            }
060                            catch (Exception e) {
061                                    _log.error(e, e);
062                            }
063                    }
064            }
065    
066            private static Log _log = LogFactoryUtil.getLog(AxisCleanUpFilter.class);
067    
068            private static Field _cacheField;
069    
070            static {
071                    try {
072                            _cacheField = ReflectionUtil.getDeclaredField(
073                                    MethodCache.class, "cache");
074                    }
075                    catch (Exception e) {
076                            _log.error(e, e);
077                    }
078            }
079    
080    }