/favicon.ico 404 error

876 views
Skip to first unread message

James Ladd

unread,
Jun 26, 2012, 5:35:08 AM6/26/12
to dropwiz...@googlegroups.com
Hi All,

I keep getting a 404 error when requesting /favicon.ico from my service.

I have added a filter to forward requests under certain conditions.

However, after the first call of the filter it appears the subsequent call for /favicon.ico
doesnt go through the filter - maybe this is the cause of the 404?
My filter is below.

Suggestions?

- James.

    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        String path = request.getPathInfo();
        boolean shouldForward = false;

        if (!path.startsWith(ASSETS_PATH) && !path.startsWith(API_PATH))
            shouldForward = shouldForward(path);

        if (shouldForward) {
            path = ASSETS_PATH + path;
            if (path.endsWith(ROOT_PATH))
                path += "index.html";
            request.getRequestDispatcher(path).forward(servletRequest, servletResponse);
        } else {
            filterChain.doFilter(servletRequest, servletResponse);
        }
    }

James Ladd

unread,
Jun 26, 2012, 5:40:47 AM6/26/12
to dropwiz...@googlegroups.com
Ah - solved.
The filter was installed on '/' not on '/*' as it should be.
Now /favicon.ico is being found and returned by the assets servlet mounted on /assets/*

Danny Gershman

unread,
May 13, 2013, 12:29:20 PM5/13/13
to dropwiz...@googlegroups.com, ladd....@gmail.com
There is an easier way to do this, with 1 line of code.   

bootstrap.addBundle(new AssetsBundle("/favicon.ico"));  

Put this in your initialize() on your service class.
Reply all
Reply to author
Forward
0 new messages