This repository has been archived by the owner on Dec 15, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
131 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
group = 'org.springframework.issues' | ||
version = '1.0.0.SNAPSHOT' | ||
|
||
buildscript { | ||
ext { | ||
springBootVersion = '2.0.0.M2' | ||
} | ||
repositories { | ||
maven { | ||
url "http://repo.spring.io/libs-milestone" | ||
} | ||
mavenCentral() | ||
} | ||
dependencies { | ||
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") | ||
} | ||
} | ||
|
||
repositories { | ||
maven { | ||
url "http://repo.spring.io/libs-milestone" | ||
} | ||
mavenCentral() | ||
} | ||
apply plugin: 'java' | ||
apply plugin: 'eclipse' | ||
apply plugin: 'idea' | ||
apply plugin: 'org.springframework.boot' | ||
apply plugin: 'io.spring.dependency-management' | ||
|
||
sourceCompatibility = 1.8 | ||
targetCompatibility = 1.8 | ||
|
||
dependencies { | ||
compile("org.springframework.boot:spring-boot-starter-webflux") | ||
testCompile('org.springframework.boot:spring-boot-starter-test') | ||
} | ||
|
||
|
12 changes: 12 additions & 0 deletions
12
SPR-15701/src/main/java/org/springframework/issues/errorhandling/Application.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package org.springframework.issues.errorhandling; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
public class Application { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(Application.class, args); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
SPR-15701/src/main/java/org/springframework/issues/errorhandling/CustomException.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.springframework.issues.errorhandling; | ||
|
||
/** | ||
* Created by dorongold on 6/23/17. | ||
*/ | ||
public class CustomException extends RuntimeException { | ||
|
||
public CustomException(final String message, final Throwable cause) { | ||
super(message, cause); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
SPR-15701/src/main/java/org/springframework/issues/errorhandling/HelloController.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package org.springframework.issues.errorhandling; | ||
|
||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
public class HelloController { | ||
|
||
public static final String ERROR_MSG = "An error occurred!"; | ||
|
||
@RequestMapping("/hello") | ||
public String hello() { | ||
final NestedException nested = new NestedException("nested"); | ||
throw new CustomException("outer", nested); | ||
} | ||
|
||
@ExceptionHandler() | ||
public String handleCustomException(final CustomException e) { | ||
return ERROR_MSG; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
SPR-15701/src/main/java/org/springframework/issues/errorhandling/NestedException.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.springframework.issues.errorhandling; | ||
|
||
/** | ||
* Created by dorongold on 6/23/17. | ||
*/ | ||
public class NestedException extends Exception { | ||
|
||
public NestedException(final String message) { | ||
super(message); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
SPR-15701/src/test/java/org/springframework/issues/errorhandling/HelloControllerTest.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package org.springframework.issues.errorhandling; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.context.junit4.SpringRunner; | ||
import org.springframework.test.web.reactive.server.WebTestClient; | ||
|
||
/** | ||
* Created by dorongold on 6/24/17. | ||
*/ | ||
|
||
@RunWith(SpringRunner.class) | ||
@SpringBootTest | ||
@AutoConfigureWebTestClient | ||
public class HelloControllerTest { | ||
|
||
@Autowired | ||
private WebTestClient client; | ||
|
||
/* | ||
* fails because exception handler invocation fails with "java.lang.IllegalStateException: No suitable resolver | ||
* for argument 0 of type..." | ||
*/ | ||
@Test | ||
public void testHello() { | ||
|
||
final String response = client.get().uri("hello").exchange().expectBody(String.class).returnResult().getResponseBody(); | ||
assertEquals(HelloController.ERROR_MSG, response); | ||
} | ||
|
||
} |