Skip to content

Commit

Permalink
Tidy up HTML content and links, add demo5 page
Browse files Browse the repository at this point in the history
  • Loading branch information
paulc4 committed Oct 11, 2014
1 parent a2dba85 commit 017642c
Show file tree
Hide file tree
Showing 40 changed files with 850 additions and 396 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -4,6 +4,7 @@ target/*
.classpath
.settings/
bin/
Thumbs.db

# Package Files #
*.jar
Expand Down
12 changes: 9 additions & 3 deletions .springBeans
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<beansProjectDescription>
<version>1</version>
<pluginVersion><![CDATA[3.3.0.201307091516-RELEASE]]></pluginVersion>
<pluginVersion><![CDATA[3.6.0.201407080615-RELEASE]]></pluginVersion>
<configSuffixes>
<configSuffix><![CDATA[xml]]></configSuffix>
</configSuffixes>
Expand All @@ -10,8 +10,14 @@
<config>src/main/resources/mvc-configuration.xml</config>
<config>java:org.springframework.boot.actuate.autoconfigure.EndpointWebMvcAutoConfiguration</config>
<config>java:org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration</config>
<config>java:demo1.web.ExceptionConfiguration</config>
<config>java:demo.config.ExceptionConfiguration</config>
<config>java:demo.main.Main</config>
<config>java:demo.utils.BeanLogger</config>
<config>java:demo3.config.DemoExceptionConfiguration</config>
<config>java:demo.utils.LoggingUtilities</config>
</configs>
<autoconfigs>
</autoconfigs>
<configSets>
<configSet>
<name><![CDATA[system]]></name>
Expand All @@ -20,8 +26,8 @@
<configs>
<config>src/main/resources/mvc-configuration.xml</config>
<config>java:org.springframework.boot.actuate.autoconfigure.EndpointWebMvcAutoConfiguration</config>
<config>java:demo1.web.ExceptionConfiguration</config>
<config>java:org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration</config>
<config>java:demo.config.ExceptionConfiguration</config>
</configs>
<profiles>
</profiles>
Expand Down
12 changes: 3 additions & 9 deletions pom.xml
Expand Up @@ -19,7 +19,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.1.7.RELEASE</version>
<version>1.1.8.RELEASE</version>
</parent>

<!-- Spring boot automatically picks up any other dependencies that it recognises
Expand All @@ -42,16 +42,10 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

<!-- <dependency> -->
<!-- <groupId>org.scala-lang</groupId> -->
<!-- <artifactId>scala-library</artifactId> -->
<!-- <version>2.10.4</version> -->
<!-- </dependency> -->
</dependencies>

<build>
<!-- Specify entry-point class to run as a Java application -->
<!-- Specify entry-point class to run as a Java application
<pluginManagement>
<plugins>
<plugin>
Expand All @@ -63,7 +57,7 @@
</configuration>
</plugin>
</plugins>
</pluginManagement>
</pluginManagement>-->

<!-- Allow deployment to Cloud Foundry -->
<plugins>
Expand Down
166 changes: 0 additions & 166 deletions src/main/java/demo/config/DemoExceptionConfiguration.java

This file was deleted.

10 changes: 5 additions & 5 deletions src/main/java/demo/config/ExceptionConfiguration.java
Expand Up @@ -16,8 +16,8 @@
* Setup for exception handling using a {@link SimpleMappingExceptionResolver}
* bean.
* <p>
* If you prefer to do this in XML set the {@link Main#simpleMappingExceptionResolverConfig} property
* to <code>XML</code> (see <code>mvc-configuration.xml</code>).
* If you prefer to do this in XML set the {@link Main#activeProfile} property
* to <code>XML_CONFIG_PROFILE</code> (see <code>mvc-configuration.xml</code>).
* <p>
* The use of the JAVA_CONFIG profile here is for demonstration only. A real
* application wouldn't normally need to switch between XML or Java
Expand Down Expand Up @@ -52,7 +52,7 @@ public SimpleMappingExceptionResolver createSimpleMappingExceptionResolver() {
SimpleMappingExceptionResolver r = new SimpleMappingExceptionResolver();

Properties mappings = new Properties();
mappings.setProperty("DatabaseException", "databaseError");
mappings.setProperty("DatabaseException", "databaseException");
mappings.setProperty("InvalidCreditCardException", "creditCardError");

r.setExceptionMappings(mappings); // None by default
Expand All @@ -71,8 +71,8 @@ public SimpleMappingExceptionResolver createSimpleMappingExceptionResolver() {
*
* Here we are choosing to use SimpleMappingExceptionResolver since many
* Spring applications have used the approach since Spring V1. Normally
* we would specify the view as "error" to match Spring Boot, however
* so you can see what is happening, we are using a different page.
* we would specify the view as "error" to match Spring Boot, however so
* you can see what is happening, we are using a different page.
*/
r.setDefaultErrorView("defaultErrorPage");
return r;
Expand Down
33 changes: 30 additions & 3 deletions src/main/java/demo/config/ResponseDataControllerAdvice.java
Expand Up @@ -7,18 +7,25 @@
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.servlet.handler.SimpleMappingExceptionResolver;

import demo.config.DemoExceptionConfiguration.SwitchableSimpleMappingExceptionResolver;
import demo.main.Main;
import demo3.web.SwitchableSimpleMappingExceptionResolver;

/**
* Adds useful data into to the model for every request.
* Adds useful data into to the model for every request. This is another use of
* a Controller Advice (besides exception handling).
*
* @author paulchapman
* @author Paul Chapman
*
*/
@ControllerAdvice
public class ResponseDataControllerAdvice {

public static final String SOURCE_ON_GITHUB = //
"https://github.com/paulc4/mvc-exceptions/blob/master/src/main";

public static final String BLOG_URL = //
"https://spring.io/blog/2013/11/01/exception-handling-in-spring-mvc";

private SimpleMappingExceptionResolver resolver;

/**
Expand Down Expand Up @@ -78,4 +85,24 @@ else if (resolver instanceof SwitchableSimpleMappingExceptionResolver) {
} else
return "on";
}

/**
* URL of this source on github.
*
* @return
*/
@ModelAttribute("gitHubSrc")
public String getGitHubSrcURL() {
return SOURCE_ON_GITHUB;
}

/**
* Add Blog URL to model for use in any web-page.
*
* @return URL of the Spring IO Blog article this demo relates to.
*/
@ModelAttribute("blogUrl")
public String getBlogUrl() {
return BLOG_URL;
}
}
18 changes: 18 additions & 0 deletions src/main/java/demo/exceptions/SupportInfoException.java
@@ -0,0 +1,18 @@
package demo.exceptions;

public class SupportInfoException extends RuntimeException {

/**
* Unique ID for Serialized object
*/
private static final long serialVersionUID = 4657491283614755649L;

public SupportInfoException(String msg) {
super(msg);
}

public SupportInfoException(String msg, Throwable t) {
super(msg, t);
}

}
18 changes: 0 additions & 18 deletions src/main/java/demo/main/HomeController.java

This file was deleted.

7 changes: 5 additions & 2 deletions src/main/java/demo/main/Main.java
Expand Up @@ -30,12 +30,12 @@
* @author Paul Chapman
*/
@EnableAutoConfiguration
@ComponentScan({ "demo", "demo1.web", "demo2", "demo3" })
@ComponentScan({ "demo", "demo1", "demo2", "demo3", "demo4" })
@ImportResource("classpath:mvc-configuration.xml")
public class Main extends SpringBootServletInitializer {

/**
* Hoe should a <code>SimpleMappingExceptionResolver</code> be created?
* How should a <code>SimpleMappingExceptionResolver</code> be created?
* <ul>
* <li>DEMO (default) - Java Config is used and a custom
* <code>SimpleMappingExceptionResolver</code> is setup that can be enabled
Expand All @@ -46,6 +46,9 @@ public class Main extends SpringBootServletInitializer {
* {@link ExceptionConfiguration}.
* <li>NONE - No <code>SimpleMappingExceptionResolver</code> is created.
* </ul>
* <p>
* Demo mode is the default - set to "java-config" or "xml-config" to match
* however you intend to use Spring for a mor realistic setup.
*
* @see Profiles
*/
Expand Down

0 comments on commit 017642c

Please sign in to comment.