Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Demonstrating Error Handling.

  • Loading branch information...
commit bdb744cf93027411304782637554b4255fcaf4b1 1 parent 0201e5d
Daniel Bevenius danbev authored
11 src/main/java/org/jboss/aerogear/controller/demo/Error.java
View
@@ -2,7 +2,14 @@
public class Error {
- public void index() {
- System.out.println("Error page!");
+ public void index(Exception e) {
+ System.out.println("[Error] " + e);
+ }
+
+ public void security() {
+ }
+
+ public void throwException() {
+ throw new RuntimeException("Demo Exception");
}
}
13 src/main/java/org/jboss/aerogear/controller/demo/Routes.java
View
@@ -20,6 +20,7 @@
import org.jboss.aerogear.controller.demo.model.Car;
import org.jboss.aerogear.controller.demo.model.User;
import org.jboss.aerogear.controller.router.AbstractRoutingModule;
+import org.jboss.aerogear.security.exception.AeroGearSecurityException;
/**
* Routes are the core of aerogear-controller–demo.
@@ -39,8 +40,11 @@
public void configuration() {
route()
- .on(SecurityException.class)
- .to(Error.class).index();
+ .on(AeroGearSecurityException.class)
+ .to(Error.class).security();
+ route()
+ .on(Exception.class)
+ .to(Error.class).index(param(Exception.class));
route()
.from("/")
.on(RequestMethod.GET)
@@ -69,5 +73,10 @@ public void configuration() {
.from("/register")
.on(RequestMethod.POST)
.to(Register.class).register(param(User.class));
+
+ route()
+ .from("/throwException")
+ .on(RequestMethod.GET)
+ .to(Error.class).throwException();
}
}
4 src/main/webapp/WEB-INF/pages/Error/index.jsp
View
@@ -5,9 +5,7 @@
<hr />
</div>
<div class="sixteen columns">
- <p>maybe you should try the <a href="delorean">restricted delorean page</a></p>
- <p><a href="login">Login</a></p>
- <p><a href="register">Register</a></p>
+ <p>${requestScope['org.jboss.aerogear.controller.exception']}</p>
</div>
</div>
<jsp:include page="../../template/footer.jsp" />
13 src/main/webapp/WEB-INF/pages/Error/security.jsp
View
@@ -0,0 +1,13 @@
+<jsp:include page="../../template/header.jsp" />
+<div class="container">
+ <div class="sixteen columns">
+ <h1 class="remove-bottom" style="margin-top: 40px">Security error page</h1>
+ <hr />
+ </div>
+ <div class="sixteen columns">
+ <p>maybe you should try the <a href="delorean">restricted delorean page</a></p>
+ <p><a href="login">Login</a></p>
+ <p><a href="register">Register</a></p>
+ </div>
+</div>
+<jsp:include page="../../template/footer.jsp" />
3  src/main/webapp/WEB-INF/pages/Home/index.jsp
View
@@ -18,6 +18,9 @@
</ul>
</form>
</div>
+ <div class="sixteen columns">
+ <p>maybe you should try out the general <a href="throwException">error handling</a></p>
+ </div>
</div>
<jsp:include page="../../template/footer.jsp" />
Please sign in to comment.
Something went wrong with that request. Please try again.