Moved to Maven layout

This commit is contained in:
Rachel Walker
2012-11-29 11:46:51 -08:00
parent 3b6747cc50
commit a1bf666b54
94 changed files with 766 additions and 2121 deletions

57
sample/pom.xml Executable file
View File

@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.raychatter</groupId>
<artifactId>sample</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>A demo app that shows custom exception handling</name>
<url>https://github.com/raychatter/spring-restful-exception-handler</url>
<parent>
<groupId>com.raychatter</groupId>
<artifactId>spring-restful-exception-handler-parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<properties>
<spring.version>3.1.1.RELEASE</spring.version>
</properties>
<dependencies>
<!-- Spring 3 dependencies -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.raychatter</groupId>
<artifactId>spring-restful-exception-handler</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<finalName>sample</finalName>
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.2</version>
</plugin>
</plugins>
</build>
</project>

View File

@@ -0,0 +1,32 @@
package com.raychatter.common.controller;
import com.raychatter.common.exception.MyNegativeArraySizeException;
import com.raychatter.common.exception.CustomException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class HelloController {
@RequestMapping(value = "/welcome", method = RequestMethod.GET)
@ResponseBody
public Object welcome() {
return "Hello World";
}
@RequestMapping(value = "/custom404", method = RequestMethod.GET)
@ResponseBody
public Object custom404() throws Exception {
throw new CustomException("It's broken!");
}
@RequestMapping(value = "/custom500", method = RequestMethod.GET)
@ResponseBody
public Object custom500() throws Exception {
throw new MyNegativeArraySizeException("oops");
}
}

View File

@@ -0,0 +1,13 @@
package com.raychatter.common.exception;
import com.raychatter.common.annotation.ExceptionHandler;
import org.springframework.http.HttpStatus;
@ExceptionHandler(httpStatus = HttpStatus.NOT_FOUND, contentType = "text/html")
public class CustomException extends Exception {
public CustomException(final String s) {
super(s);
}
}

View File

@@ -0,0 +1,11 @@
package com.raychatter.common.exception;
import com.raychatter.common.annotation.ExceptionHandler;
import org.springframework.http.HttpStatus;
@ExceptionHandler(httpStatus = HttpStatus.INTERNAL_SERVER_ERROR, contentType = "application/json")
public class MyNegativeArraySizeException extends NegativeArraySizeException {
public MyNegativeArraySizeException(String s) {
super(s);
}
}

View File

@@ -0,0 +1 @@
{ "errors": "%s" }

View File

@@ -0,0 +1,25 @@
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:annotation-config />
<context:component-scan base-package="com.raychatter.common.controller" />
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/pages/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
<bean id="exceptionResolver" class="com.raychatter.common.exception.AnnotationHandler" />
</beans>

View File

@@ -0,0 +1,5 @@
<html>
<body>
<h1>Message : ${message}</h1>
</body>
</html>

View File

@@ -0,0 +1,28 @@
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Spring Web MVC Application</display-name>
<servlet>
<servlet-name>mvc-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mvc-dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/mvc-dispatcher-servlet.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>