Servlet Filter with location="before-dispatch" - /mvc and strange behavior

Dear community members,

I just discovered a really strange behavior with a refapp plugin that I developed and installed on Bitbucket. The first thing I discovered was, that the following url pattern didn’t match for seemingly fitting requests:

        <url-pattern>/projects/*</url-pattern>      // not working for example-bitbucket.com/projects/TEST

After a bit of debugging I noticed that the URL that gets passed to the servlet filter is /mvc/projects/…, so there is an additional /mvc added. This only happens when using location=“before-dispatch”. When using location=“before-decoration” this doesn’t happen and the url pattern from above matches. That somehow makes sense to me, as MVC is part of the decoration, although this only happens internally and adding the /mvc prefix in the browser results in 404.
But now to the strange part: No matter what I do in the servlet filter it messes up bitbucket, as in almost every requests (even /dashboard) is answered with a 404 error. Even if I just pass everything untouched along the filter chain:

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        filterChain.doFilter(servletRequest, servletResponse);
    }

Does anyone know what is happening in Bitbucket that gets messed up when adding a servlet filter with location=“before-dispatch”? The plugin works well in Jira and Confluence, so it seems to be Bitbucket related. Looking forward to hear from you!

Best regards

Johannes

1 Like