Skip to content

Commit

Permalink
Merge pull request #2 from puncha/release/v0.2.0
Browse files Browse the repository at this point in the history
Release v0.2.0
  • Loading branch information
PunChaFeng committed Mar 28, 2016
2 parents 08577de + 24e9900 commit 4fed4ba
Show file tree
Hide file tree
Showing 19 changed files with 156 additions and 42 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Pet Clinic by Spring Boot in Java v0.1.0
# Pet Clinic by Spring Boot in Java v0.2.0

------

Expand Down Expand Up @@ -26,6 +26,8 @@ gradle check
- Heroku Demo: http://petclinic.herokuapp.com
- Official Site: http://projects.spring.io/spring-roo/

## Change logs
## Change Logs
- v0.2.0:
- Error page is implemented.
- v0.1.0:
- Index page is implemented.
25 changes: 25 additions & 0 deletions src/main/java/tk/puncha/configuration/WebConfig.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,41 @@
package tk.puncha.configuration;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.config.annotation.ViewResolverRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.handler.SimpleMappingExceptionResolver;

import java.util.List;
import java.util.Properties;

@Configuration
public class WebConfig extends WebMvcConfigurerAdapter {

@Bean Properties exceptionMappings(){
Properties mappings = new Properties();
mappings.put("OopsException", "exception/oops");
return mappings;
}

@Bean
public HandlerExceptionResolver handlerExceptionResolver(){
SimpleMappingExceptionResolver resolver = new SimpleMappingExceptionResolver();
resolver.setDefaultErrorView("exception/default");
resolver.setExceptionAttribute("exception");
resolver.setExceptionMappings(exceptionMappings());
return resolver;
}

@Override
public void configureViewResolvers(ViewResolverRegistry registry) {
super.configureViewResolvers(registry);
registry.jsp("/WEB-INF/jsp/", ".jsp");
}

@Override
public void configureHandlerExceptionResolvers(List<HandlerExceptionResolver> exceptionResolvers) {
exceptionResolvers.add(handlerExceptionResolver());
}
}
22 changes: 22 additions & 0 deletions src/main/java/tk/puncha/controllers/ErrorController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package tk.puncha.controllers;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import tk.puncha.exceptions.OopsException;

@Controller
@RequestMapping("/errors")
public class ErrorController {
@RequestMapping(path = {"", "index", "default"}, method = RequestMethod.GET)
public String index() {
final String msg = "Expected: controller used to showcase what happens when an exception is thrown";
throw new RuntimeException(msg);
}

@RequestMapping(path = "/oops", method = RequestMethod.GET)
public String oops() {
throw new OopsException();
}

}
14 changes: 0 additions & 14 deletions src/main/java/tk/puncha/controllers/OopController.java

This file was deleted.

8 changes: 8 additions & 0 deletions src/main/java/tk/puncha/exceptions/OopsException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package tk.puncha.exceptions;

public class OopsException extends RuntimeException {
@Override
public String getMessage() {
return "Oops!";
}
}
20 changes: 0 additions & 20 deletions src/main/resources/static/css/petclinic.css

This file was deleted.

3 changes: 2 additions & 1 deletion src/main/webapp/WEB-INF/jsp/common/footer.jsp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<hr/>
<div class="container">
<img class="pull-right" src="../images/spring-pivotal-logo.png"/>
<img class="pull-right" src="/resources/images/spring-pivotal-logo.png"/>
</div>
2 changes: 1 addition & 1 deletion src/main/webapp/WEB-INF/jsp/common/header.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

<link rel="stylesheet" href="//cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap.min.css">
<link rel="stylesheet" href="//cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">
<link rel="stylesheet" href="../css/petclinic.css">
<link rel="stylesheet" href="/resources/css/petclinic.css">

</head>
16 changes: 13 additions & 3 deletions src/main/webapp/WEB-INF/jsp/common/nav.jsp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<div class="container">
<img src="../images/banner-graphic.png"/>
<img src="/resources/images/banner-graphic.png"/>

<nav class="navbar navbar-default">
<div class="navbar-header">
Expand All @@ -17,8 +18,17 @@
<li><a href="/"><i class="glyphicon glyphicon-home"></i> Home</a></li>
<li><a href="/owners"><i class="glyphicon glyphicon-search"></i> Find owners</a></li>
<li><a href="/vets"><i class="glyphicon glyphicon-th-list"></i> Veterinarians</a></li>
<li><a href="/oops" title="trigger a RuntimeException to see how it is handled">
<i class="glyphicon glyphicon-warning-sign"></i> Error</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
<i class="glyphicon glyphicon-warning-sign"></i>
<span> Errors</span>
<span class="caret"></span>
</a>
<ul class="dropdown-menu">
<li><a href="/errors">Default exception</a></li>
<li><a href="/errors/oops">Oops exception</a></li>
</ul>
</li>
</ul>
</div>
</nav>
Expand Down
22 changes: 22 additions & 0 deletions src/main/webapp/WEB-INF/jsp/exception/default.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<%--@elvariable id="exception" type="java.lang.exception"--%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<!DOCTYPE html>

<html lang="en">
<jsp:include page="../common/header.jsp"/>
<body>
<jsp:include page="../common/nav.jsp"/>

<div class="container">
<img src="/resources/images/pets.png"/>
<h2>Something happened...</h2>
<p>${exception.message}</p>
</div>

<jsp:include page="../common/footer.jsp"/>
<jsp:include page="../common/scripts.jsp"/>

</body>
</html>
28 changes: 28 additions & 0 deletions src/main/webapp/WEB-INF/jsp/exception/oops.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<%--@elvariable id="exception" type="java.lang.exception"--%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<!DOCTYPE html>

<html lang="en">
<jsp:include page="../common/header.jsp"/>
<body>
<jsp:include page="../common/nav.jsp"/>

<div class="container">
<div class="panel panel-danger panel-exception">
<div class="panel-heading">Exceptions: ${exception.getMessage()} </div>
<div class="panel-body">
<c:set var="stack" value="${exception.getStackTrace()}"/>
<c:forEach var="stackItem" items='${stack}'>
${stackItem}
</c:forEach>
</div>
</div>
</div>

<jsp:include page="../common/footer.jsp"/>
<jsp:include page="../common/scripts.jsp"/>

</body>
</html>
3 changes: 2 additions & 1 deletion src/main/webapp/WEB-INF/jsp/home/welcome.jsp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<div class="container">
<h2>Welcome</h2>
<img src="../images/pets.png"/>
<img src="<c:url value="/resources/images/pets.png"/>"/>
</div>
29 changes: 29 additions & 0 deletions src/main/webapp/resources/css/petclinic.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
.container {
padding-top: 10px;
width: 700px;
}

.form-horizontal {
width: 100%;
}

input[type="text"] {
height: 25px;
}

nav {
width: 601px;
}

.navbar .nav > li > a {
color: #000000;
}

.form-horizontal .control-label {
text-align: left;
}

.panel-exception > .panel-body {
height: 500px;
overflow: scroll;
}
File renamed without changes

0 comments on commit 4fed4ba

Please sign in to comment.