void invoke ( RequestImpl req , ResponseImpl rsp , Object node ) throws IOException , ServletException { if ( node == null ) { // node is null if ( ! Dispatcher . isTraceEnabled ( req ) ) { rsp . sendError ( SC_NOT_FOUND ) ; } else { // show error page rsp . setStatus ( SC_NOT_FOUND ) ; rsp . setContentType ( "text/html;charset=UTF-8" ) ; PrintWriter w = rsp . getWriter ( ) ; w . println ( "<html><body>" ) ; w . println ( "<h1>404 Not Found</h1>" ) ; w . println ( "<p>Stapler processed this HTTP request as follows, but couldn't find the resource to consume the request" ) ; w . println ( "<pre>" ) ; EvaluationTrace . get ( req ) . printHtml ( w ) ; w . println ( "<font color=red>-&gt; unexpected null!</font>" ) ; w . println ( "</pre>" ) ; w . println ( "<p>If this 404 is unexpected, double check the last part of the trace to see if it should have evaluated to null." ) ; w . println ( "</body></html>" ) ; } return ; } if ( tryInvoke ( req , rsp , node ) ) return ; // done // we really run out of options. if ( ! Dispatcher . isTraceEnabled ( req ) ) { rsp . sendError ( SC_NOT_FOUND ) ; } else { // show error page rsp . setStatus ( SC_NOT_FOUND ) ; rsp . setContentType ( "text/html;charset=UTF-8" ) ; PrintWriter w = rsp . getWriter ( ) ; w . println ( "<html><body>" ) ; w . println ( "<h1>404 Not Found</h1>" ) ; w . println ( "<p>Stapler processed this HTTP request as follows, but couldn't find the resource to consume the request" ) ; w . println ( "<pre>" ) ; EvaluationTrace . get ( req ) . printHtml ( w ) ; w . printf ( "<font color=red>-&gt; No matching rule was found on &lt;%s&gt; for \"%s\"</font>\n" , escape ( node . toString ( ) ) , req . tokens . assembleOriginalRestOfPath ( ) ) ; w . println ( "</pre>" ) ; w . printf ( "<p>&lt;%s&gt; has the following URL mappings, in the order of preference:" , escape ( node . toString ( ) ) ) ; w . println ( "<ol>" ) ; MetaClass metaClass = webApp . getMetaClass ( node ) ; for ( Dispatcher d : metaClass . dispatchers ) { w . println ( "<li>" ) ; w . println ( d . toString ( ) ) ; } w . println ( "</ol>" ) ; w . println ( "</body></html>" ) ; } }
Try to dispatch the request against the given node and if it fails report an error to the client .