/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package com.hwlcn.security.web.servlet; import com.hwlcn.security.util.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import javax.servlet.Filter; import javax.servlet.FilterConfig; import javax.servlet.ServletException; public abstract class AbstractFilter extends ServletContextSupport implements Filter { private static transient final Logger log = LoggerFactory.getLogger(AbstractFilter.class); protected FilterConfig filterConfig; public FilterConfig getFilterConfig() { return filterConfig; } public void setFilterConfig(FilterConfig filterConfig) { this.filterConfig = filterConfig; setServletContext(filterConfig.getServletContext()); } /** * @param paramName * @return */ protected String getInitParam(String paramName) { FilterConfig config = getFilterConfig(); if (config != null) { return StringUtils.clean(config.getInitParameter(paramName)); } return null; } public final void init(FilterConfig filterConfig) throws ServletException { setFilterConfig(filterConfig); try { onFilterConfigSet(); } catch (Exception e) { if (e instanceof ServletException) { throw (ServletException) e; } else { if (log.isErrorEnabled()) { log.error("Unable to start Filter: [" + e.getMessage() + "].", e); } throw new ServletException(e); } } } /** * 配置初始化函数 * * @throws Exception */ protected void onFilterConfigSet() throws Exception { } /** * servlet 停止时的操作 */ public void destroy() { } }