grails and debugging UrlMappings
Asked Answered
C

1

11

In grails, how can I add some code to the UrlMappings.groovy (ex: println) so that I can figure out what the request URI is and which mapping is getting hit (if any)?

Background:

In this situation, there are two servers which serve different things based on file extension. So, the two servers need to always see file extensions for error processing to continue. Otherwise, the servers get confused and 1 serves up a 404 page instead of our 500 page.

The bigger picture involves taking a 500 response due to something like a NullPointerException and tracing it through the code to see what is happening.

I added code like the following which is at http://jetlet.blogspot.com/2010/08/grails-exception-handling-with-response.html :

"500" (controller: "error", action: "internalError")

In testing this, I am throwing a NullPointerException (NPE) on purpose. The 500 handling is called and 500 page is served up when entering in the URL into the browser's address bar. However, when posting a form to the server and having the processing code blow up on purpose with a NPE, the "500" handling code does not get called. The URL in the form's action seems to end with an extension. So, not sure why the difference in behavior between the GET (browser URL) and POST (form submission).

Thanks for insights and thoughts on tracking this down !

Caudell answered 25/1, 2011 at 2:48 Comment(4)
sorry, your word are rather vague to me. Could you mind giving more detailed example?Savoury
Code to illustrate your question would be very welcomed hereJurgen
Thank you for your interest in this question and your replies. In a nutshell, when I am working locally on my box with my single jetty server everything works fine. When submitting a form, code throwing a NullPointerException goes through the error processing code as expected. When not on my box but in a more involved environment, I get a 404 page. This more involved environment has 1 server which looks for extensions in a request to decide whether or not to pass the request on through to server number 2. At this point, I need to someone be able to trace through what is happening.Caudell
What additional code would help? Form code? Thanks! :)Caudell
V
11

In your Config.groovy you can modify your log4j settings for url mapping events by adding

all 'org.codehaus.groovy.grails.web.mapping'

to your existing log4j settings. all is the most verbose setting so it can be tuned back if that starts giving you too much. You can find more information in the official grails documentation here : http://grails.org/doc/latest/guide/3.%20Configuration.html

Vinavinaceous answered 25/1, 2011 at 21:24 Comment(2)
Thanks for the logging! What's weird is that I do not see associated logging for handling a 500. In other words, I set up localhost:8080/KataIt/cool/something to throw a NullPointerException and the only difference I see between code throwing an exception and not is: errors.GrailsExceptionResolver null and then the stack trace and some forwarding information that is the same regardless of whether you are throwing a NPE or not: filter.UrlMappingsFilter Matched URI [/cool/something] to URL mapping [/()/()? /(*)?], forwarding to [/grails/cool/something.dispatch] with ..<clip>Caudell
'org.grails.web.mapping' if it is Grails 3Whydah

© 2022 - 2024 — McMap. All rights reserved.