1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.util.axis;
16  
17  import com.liferay.portal.kernel.log.Log;
18  import com.liferay.portal.kernel.log.LogFactoryUtil;
19  import com.liferay.portal.kernel.servlet.BaseFilter;
20  import com.liferay.portal.kernel.util.ReflectionUtil;
21  
22  import java.lang.reflect.Field;
23  
24  import javax.servlet.FilterChain;
25  import javax.servlet.http.HttpServletRequest;
26  import javax.servlet.http.HttpServletResponse;
27  
28  import org.apache.axis.utils.cache.MethodCache;
29  
30  /**
31   * <a href="AxisCleanUpFilter.java.html"><b><i>View Source</i></b></a>
32   *
33   * @author Shuyang Zhou
34   * @author Brian Wing Shun Chan
35   */
36  public class AxisCleanUpFilter extends BaseFilter {
37  
38      protected Log getLog() {
39          return _log;
40      }
41  
42      protected void processFilter(
43              HttpServletRequest request, HttpServletResponse response,
44              FilterChain filterChain)
45          throws Exception {
46  
47          try {
48              processFilter(
49                  AxisCleanUpFilter.class, request, response, filterChain);
50          }
51          finally {
52              try {
53                  ThreadLocal<?> cacheThreadLocal =
54                      (ThreadLocal<?>)_cacheField.get(null);
55  
56                  if (cacheThreadLocal != null) {
57                      cacheThreadLocal.remove();
58                  }
59              }
60              catch (Exception e) {
61                  _log.error(e, e);
62              }
63          }
64      }
65  
66      private static Log _log = LogFactoryUtil.getLog(AxisCleanUpFilter.class);
67  
68      private static Field _cacheField;
69  
70      static {
71          try {
72              _cacheField = ReflectionUtil.getDeclaredField(
73                  MethodCache.class, "cache");
74          }
75          catch (Exception e) {
76              _log.error(e, e);
77          }
78      }
79  
80  }