Spring Security Filter无法运行

时间:2016-08-28 11:28:37

标签: java spring spring-mvc spring-security

我创建了自定义过滤器类

public void init(final FilterConfig filterConfig) throws ServletException
    {
        this.filterConfig = filterConfig;
        loginForm = this.filterConfig.getInitParameter("Admin_login_form");
    }

    public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain)
            throws IOException, ServletException
    {

        final HttpServletRequest httpRequest = (HttpServletRequest) request;
        //final HttpSession session = httpRequest.getSession();

        String url = httpRequest.getRequestURL().toString();
        final String queryString = httpRequest.getQueryString();
        request.setCharacterEncoding("UTF-8");
        if (queryString != null && url != null && url.contains("my-sortiment/detail"))
        {
            LOG.info("Previous ExpiryFilter :--" + url + " queryString : " + queryString); //
            //queryString = URLEncoder.encode(queryString, "UTF-8");
            url = url + "?" + replaceSpecialCharacters(queryString);
            LOG.info("ExpiryFilter :--" + url); //response.sendRedirect(url);
            filterConfig.getServletContext().getRequestDispatcher(url).forward(request, response);
        }
        else
        {
            chain.doFilter(request, response);
        }



        /*
         * ControlPanelUser adminUser = (ControlPanelUser) session.getAttribute(PageConstants.CONTROL_PANEL_USER);
         * 
         * if ((adminUser == null || adminUser.getBoId() < 1)) { //Send user to login form
         * filterConfig.getServletContext().getRequestDispatcher(loginForm).forward(request, response); } else {// Send
         * user to requested page chain.doFilter(request,response); }
         */

    }

    public void destroy()
    {
        this.filterConfig = null;
    }

我还在spring config中提到了bean。文件

<bean id="mswCustomCharacterEncodingFilter" class="com.msw.storefront.filters.CustomCharacterEncodingFilter" >
    </bean>

还在web.xml中设置过滤器

<filter>
        <filter-name>characterEncodingFilter</filter-name>
        <filter-class>com.msw.storefront.filters.CustomCharacterEncodingFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>characterEncodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

但是当我执行我的url模式时,那时我会低于Exception

SEVERE: Servlet.service() for servlet [DispatcherServlet] in context with path [] threw exception
java.lang.IllegalArgumentException: Path http://localhost:9001/my-sortiment/detail?name=test&listView=false does not start with a "/" character
        at org.apache.catalina.core.ApplicationContext.getRequestDispatcher(ApplicationContext.java:458)
        at org.apache.catalina.core.ApplicationContextFacade.getRequestDispatcher(ApplicationContextFacade.java:221)
        at com.msw.storefront.filters.CustomCharacterEncodingFilter.doFilter(CustomCharacterEncodingFilter.java:55)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
        at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
        at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)
        at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
        at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
        at java.lang.Thread.run(Thread.java:745)

请给我解决方案。 在此先感谢

0 个答案:

没有答案