[BAEL-4084] Code Upload

This commit is contained in:
sergio41
2020-06-20 13:09:32 +02:00
parent dbb4a85c10
commit cb26154fe0
7 changed files with 165 additions and 0 deletions
@@ -0,0 +1,25 @@
package com.baeldung.exceptiontesting;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.scheduling.annotation.EnableScheduling;
/**
* Main Application Class - uses Spring Boot. Just run this as a normal Java
* class to run up a Jetty Server (on http://localhost:8082/spring-rest-full)
*
*/
@EnableScheduling
@EnableAutoConfiguration
@ComponentScan("com.baeldung.exceptiontesting")
@SpringBootApplication
public class ExceptionTestingApplication extends SpringBootServletInitializer {
public static void main(final String[] args) {
SpringApplication.run(ExceptionTestingApplication.class, args);
}
}
@@ -0,0 +1,31 @@
package com.baeldung.exceptiontesting.controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import com.baeldung.exceptiontesting.exception.BadArgumentsException;
import com.baeldung.exceptiontesting.exception.InternalException;
import com.baeldung.exceptiontesting.exception.ResourceNotFoundException;
@RestController
public class ExceptionController {
@GetMapping("/exception/{exception_id}")
public void getSpecificException(@PathVariable("exception_id") String pException) {
if("not_found".equals(pException)) {
throw new ResourceNotFoundException("resource not found");
}
else if("bad_arguments".equals(pException)) {
throw new BadArgumentsException("bad arguments");
}
else {
throw new InternalException("internal error");
}
}
@GetMapping("/exception/throw")
public void getException() throws Exception {
throw new Exception("error");
}
}
@@ -0,0 +1,13 @@
package com.baeldung.exceptiontesting.exception;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
@SuppressWarnings("serial")
@ResponseStatus(HttpStatus.BAD_REQUEST)
public class BadArgumentsException extends RuntimeException {
public BadArgumentsException(String message) {
super(message);
}
}
@@ -0,0 +1,13 @@
package com.baeldung.exceptiontesting.exception;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
@SuppressWarnings("serial")
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public class InternalException extends RuntimeException {
public InternalException(String message) {
super(message);
}
}
@@ -0,0 +1,13 @@
package com.baeldung.exceptiontesting.exception;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
@SuppressWarnings("serial")
@ResponseStatus(HttpStatus.NOT_FOUND)
public class ResourceNotFoundException extends RuntimeException {
public ResourceNotFoundException(String message) {
super(message);
}
}