0

I am attempting to debug a server which uses Spring Web 4.1.6. No matter what URL I direct requests to, I get a 404, The Request Resource is not available.

No output gets written to the console when running in Tomcat on Eclipse. I have no idea where to put a breakpoint to understand what is happening and can think of no approach to debugging.

I note that when I send a request to the admin port, I do see "Invalid command '' received" so the server is not completely inert but attempts to go to a URL on the http port configured for Eclipse show no results. I assume this means something like Spring Web is "absorbing" all http requests.

EDIT: I note that even a Tomcat server without any war file will give 404s and there is no log output whereas requests sent to the admin port do result in output. So the question maybe is, how do you determine why Tomcat is returning 404 for a URL that should work?

EDIT (2): It was pointed out to me that indeed Tomcat does log this information but in a separate file. I see in logs directory under .metadata (in Eclipse) multiple local_access_log..txt files. This I would guess is the default for Eclipse but that Tomcat could also be configured to output to the console. So this was not so mysterious after all.

1 Answer 1

1

First, you could try enable TRACE logging on Spring MVC to see whether something works there. Here is an example for logback:

<logger name="org.springframework.web.servlet.mvc">
    <level value="TRACE"/>
</logger>

If something appears in logs, at least Spring MVC is coming into play

Another approach to debug (that would work even if the application is not deployed, but Tomcat is started) would be to set a breakpoint at Tomcat's HttpServletResponse implementation's sendError(int) and sendError(int, String) to see what code sets that 404 code. I believe this should be org.apache.catalina.connector.Response https://tomcat.apache.org/tomcat-7.0-doc/api/org/apache/catalina/connector/Response.html

This would allow to see who sets that 404: Springn MVC, other code in your application, or Tomcat itself.

If your application is deployed successfully and receives request, you could add your custom filter to filter chain as lately as possible. That filter would do nothing but proceeding the chain:

public void doFilter(ServletRequest req, ServletResponse resp,
        FilterChain chain) throws IOException, ServletException {
    chain.doFilter(req, resp);
}

But it would allow you to set a breakpoint. If it triggers, you can walk further through the code as it executes.

If this breakpoint does not trigger, try putting that filter first in the filter chain, then catch control with a breakpoint on it and trace the execution.

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks very much. Please tell me the name of the file for setting level to TRACE. (I am very new to a fairly complex application with many files.)
This depends on what logging framework you use. Is it logback, log4j, log4j2, or something else? Please add your POM to the question, this will help to find this out.
the log info did not apparently reveal anything new. Can you explain how I would set a breakpoint in Response as you indicate in your original message? I understand that breaks can be set in third-party code but I don't see how to get to Response to do this.
Some information may be found here. blogs.mulesoft.com/dev/tomcat-tcat-server/… The author explains how to debug your application code or Tomcat code using a standalone Tomcat instance.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.