-
-
Save olivermt/1284534 to your computer and use it in GitHub Desktop.
Weird behavior in grails redirecting
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //controller Page, with the 404 mapping in UrlMappings.groovy: "404"(controller:"page", action:"notFound") | |
| @Secured(['IS_AUTHENTICATED_ANONYMOUSLY']) | |
| def notFound () { | |
| def msg = | |
| [code:"404", | |
| descriptor:"page not found", | |
| strong: "The page you requested cannot be found", | |
| text:"If you got to this page by following a link, please notify an administrator."] | |
| render (view: "/shared/status", model: [msg:msg]) | |
| } | |
| //action that sends 404 response | |
| @Secured(['IS_AUTHENTICATED_ANONYMOUSLY']) | |
| def show () { | |
| withPage { Page page -> | |
| if(page.wikiPage) { | |
| redirect(action:"wiki", id:page.pageName) | |
| } | |
| if(page.secured && !isLoggedIn()) { | |
| redirect(controller:"auth", action:"login") | |
| } | |
| if(page.frontPage) { | |
| render(view:"frontpage", model:[page:page,activePage:'home', activeSubPage:page.pageName]) | |
| } | |
| else { | |
| render(view:"show", model:[page:page, activePage:page.pageName]) | |
| } | |
| } | |
| } | |
| //helper | |
| private def withPage(id="id", Closure c) { | |
| def issue = Page.findByPageName(params.id) | |
| if(issue) { | |
| c.call issue | |
| } | |
| else { | |
| response.sendError(404) | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //this is the view i render | |
| <head> | |
| <meta name="layout" content="main" /> | |
| <title> | |
| ${msg.code} | |
| </title> | |
| </head> | |
| <body> | |
| <div class="page-header"> | |
| <h1>${msg.code} <small>${msg.descriptor}</small></h1> | |
| </div> | |
| <div class="alert-message block-message error"> | |
| <p><strong>${msg.strong}!</strong> ${msg.text}</p> | |
| <div class="alert-actions"> | |
| <%=msg.link%> | |
| <g:link class="btn small" controller="news" action="index">Main page</g:link> | |
| </div> | |
| </div> | |
| </body> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //the proper response if you just type in some garbled url like http://safaridb.com/adas | |
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <title>Safari - | |
| 404 | |
| </title> | |
| <meta name="layout" content="main"/> | |
| <title> | |
| 404 | |
| </title> | |
| <script src="/static/plugins/jquery-1.6.1.1/js/jquery/jquery-1.6.1.min.js" type="text/javascript" ></script> | |
| <link href="/static/bundle-bundle_core_head.css" type="text/css" rel="stylesheet" media="screen, projection" /> | |
| <link href="http://twitter.github.com/bootstrap/1.3.0/bootstrap.min.css" type="text/css" rel="stylesheet" media="screen, projection" /> | |
| </head> | |
| <body> | |
| <div class="topbar"> | |
| <div class="fill"> | |
| <div class="container"> | |
| <a href="/" class="brand">Safari</a> | |
| <ul class="uppercase"> | |
| <li class=""><a href="/">Home</a></li> | |
| <li class="" ><a href="/page/show/member-area">Member area</a></li> | |
| </ul> | |
| <form id="login" method="post" class="pull-right" action="/static/j_spring_security_check"> | |
| <span class="topbar-login">Login: </span><input type="text" name="j_username" class="xLarge" id="j_username" value="" /> | |
| <span class="topbar-login">Password: </span><input type="password" name="j_password" class="input-small" id="j_password" value="" /> | |
| <span class="topbar-login">Remember me: </span><input type="hidden" name="__spring_security_remember_me" /><input type="checkbox" name="_spring_security_remember_me" id="_spring_security_remember_me" /> | |
| <button class="btn" type="submit">Sign in</button> | |
| <input type="hidden" name="spring-security-redirect" value="" id="spring-security-redirect" /> | |
| </form> | |
| </div> | |
| </div> | |
| </div> | |
| <div id="bodywrapper"> | |
| <div id="container-background"> | |
| <div id="safariheader"> | |
| </div> | |
| <div id="main-container" class="container"> | |
| <div class="page-header"> | |
| <h1>404 <small>page not found</small></h1> | |
| </div> | |
| <div class="alert-message block-message error"> | |
| <p><strong>The page you requested cannot be found!</strong> If you got to this page by following a link, please notify an administrator.</p> | |
| <div class="alert-actions"> | |
| <a href="/" class="btn small">Main page</a> | |
| </div> | |
| </div> | |
| </div> | |
| <div id="footer" class="container"> | |
| <em>Copyright © 2010-2011 - Uni CIPR</em> | | |
| <a href="http://jigsaw.w3.org/css-validator/check/referer">CSS</a> and <a href="http://validator.w3.org/check?uri=referer">XHTML</a> | |
| </div> | |
| </div> | |
| </div> | |
| </body> | |
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //what I get rendered if I go to http://safaridb.com/page/show/adasdasfas | |
| <head> | |
| <meta name="layout" content="main"/> | |
| <title> | |
| 404 | |
| </title> | |
| </head> | |
| <body> | |
| <div class="page-header"> | |
| <h1>404 <small>page not found</small></h1> | |
| </div> | |
| <div class="alert-message block-message error"> | |
| <p><strong>The page you requested cannot be found!</strong> If you got to this page by following a link, please notify an administrator.</p> | |
| <div class="alert-actions"> | |
| <a href="/" class="btn small">Main page</a> | |
| </div> | |
| </div> | |
| </body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment