I'm newbie in developing with GWT. I started to maintain a GWT (2.7) application and need to revise the logging. So I decided to make use of MDC (MappedDiagnosticContext) and wrote a servlet Filter to put the user name in MDC, like this:

public class MDCServletFilter implements Filter {

    /* (non-Javadoc)
     * @see javax.servlet.Filter#destroy()
     */
    public void destroy() {}

    /* (non-Javadoc)
     * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)
     */
    public void doFilter(ServletRequest aRequest, ServletResponse aResponse, FilterChain aFilterChain)
            throws IOException, ServletException {
        try {
            // get the session from the request ...
            HttpServletRequest tempRequest = (HttpServletRequest)aRequest;
            HttpSession tempSession = tempRequest.getSession();
            // get the currently logged in user ...
            String tempUser = (String)tempSession.getAttribute(Authorizer.USER_KEY);
            // if user is logged in, put the name into the MDC ...
            if (tempUser != null && tempUser.trim().length() > 0) {
                MDC.put(Authorizer.USER_KEY, tempUser);
            }
            // at least call the other filter ..
            aFilterChain.doFilter(tempRequest, aResponse);
        } finally {
            // finally remove the user name from the MDC ...
            MDC.remove(Authorizer.USER_KEY);
        }
    }

    /* (non-Javadoc)
     * @see javax.servlet.Filter#init(javax.servlet.FilterConfig)
     */
    public void init(FilterConfig arg0) throws ServletException {}

}

The web.xml:

<web-app>
    <!-- MDC Filter -->
    <filter>
        <filter-name>MDCServletFilter</filter-name>
        <filter-class>
            foo.bar.filter.MDCServletFilter
        </filter-class>
    </filter>
    <filter-mapping>
        <filter-name>MDCServletFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <!-- MDC Filter END -->

Now when I start the application in my eclipse (June) I get the warning:

[WARN] Server class 'foo.bar.filter.MDCServletFilter' could not be found in the web app, but was found on the system classpath

The filter class resides in a "common" project, not in the GWT project, because we have some more GWT projects which make use of some common classes. If I put the filter class in to the GWT project, no warning occur.

So, how do I have to setup the GWT project to use other project's classes without any warnings?

Thanks in advance!

2

There are 2 best solutions below

0
On BEST ANSWER

The details depend on your build tool and/or IDE, but the goal is to have all server-side classes in the webapp's WEB-INF (either in WEB-INF/classes, which is probably the case for your GWT project, or in a JAR in WEB-INF/lib).

This will be necessary anyway when deploying the webapp to a servlet container (unless you intend to deploy your "common" project as a shared lib in your servlet container).

0
On

I solved it by linking the source folder of the common project into the GWT project:

GWT Project's Properties -> JavaBuild Path -> "Link source..." ->

setting the "Linked folder location:" to "WORKSPACE_LOC/someSecondProject/src", then renaming "Folder name:" from "src" to e.g. "CommonGWT.src".

This settings compile all the sources of the other project into "WEB-INF/classes" of the GWT project and the Eclipse GWT is satisfied.