-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Finished testing of Public Services.
- Loading branch information
Alfonso Vásquez
committed
Jun 26, 2014
1 parent
bf61b5a
commit 10db6d7
Showing
11 changed files
with
179 additions
and
109 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
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
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
This file was deleted.
Oops, something went wrong.
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
68 changes: 68 additions & 0 deletions
68
public-services/src/main/java/org/mytraffic/pub/rest/controllers/ExceptionHandlers.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,68 @@ | ||
package org.mytraffic.pub.rest.controllers; | ||
|
||
import org.craftercms.profile.api.exceptions.ProfileException; | ||
import org.craftercms.profile.exceptions.ProfileRestServiceException; | ||
import org.mytraffic.priv.api.exceptions.PrivateApiException; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.ControllerAdvice; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.context.request.ServletWebRequest; | ||
import org.springframework.web.context.request.WebRequest; | ||
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler; | ||
|
||
import java.util.Collections; | ||
|
||
/** | ||
* Advice for the REST controllers that includes response handling for all major exceptions. | ||
* | ||
* @author avasquez | ||
*/ | ||
@ControllerAdvice | ||
public class ExceptionHandlers extends ResponseEntityExceptionHandler { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(ExceptionHandlers.class); | ||
|
||
@ExceptionHandler(PrivateApiException.class) | ||
public ResponseEntity<Object> handlePrivateApiException(PrivateApiException e, WebRequest request) { | ||
return handleExceptionInternal(e, e.getErrorCode().getDefaultHttpStatus(), request); | ||
} | ||
|
||
@ExceptionHandler(ProfileRestServiceException.class) | ||
public ResponseEntity<Object> handleProfileRestServiceException(ProfileRestServiceException e, WebRequest request) { | ||
return handleExceptionInternal(e, e.getStatus(), request); | ||
} | ||
|
||
@ExceptionHandler(ProfileException.class) | ||
public ResponseEntity<Object> handleProfileException(ProfileException e, WebRequest request) { | ||
return handleExceptionInternal(e, HttpStatus.INTERNAL_SERVER_ERROR, request); | ||
} | ||
|
||
@Override | ||
protected ResponseEntity<Object> handleExceptionInternal(Exception ex, Object body, HttpHeaders headers, | ||
HttpStatus status, WebRequest request) { | ||
return handleExceptionInternal(ex, headers, status, request); | ||
} | ||
|
||
protected ResponseEntity<Object> handleExceptionInternal(Exception ex, HttpStatus status, WebRequest request) { | ||
return handleExceptionInternal(ex, new HttpHeaders(), status, request); | ||
} | ||
|
||
protected ResponseEntity<Object> handleExceptionInternal(Exception ex, HttpHeaders headers, HttpStatus status, | ||
WebRequest request) { | ||
logger.error("Request for " + ((ServletWebRequest) request).getRequest().getRequestURI() + " failed " + | ||
"with HTTP status " + status, ex); | ||
|
||
String message = ex.getMessage(); | ||
|
||
if (ex instanceof ProfileRestServiceException) { | ||
message = ((ProfileRestServiceException) ex).getDetailMessage(); | ||
} | ||
|
||
return new ResponseEntity<>(Collections.singletonMap("message", message), headers, status); | ||
} | ||
|
||
} |
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
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
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
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,19 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<configuration> | ||
|
||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> | ||
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"> | ||
<Pattern>%d{yyyy-MM-dd_HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n | ||
</Pattern> | ||
</encoder> | ||
</appender> | ||
|
||
<logger name="org.springframework" level="INFO"/> | ||
<logger name="org.craftercms" level="INFO"/> | ||
<logger name="org.mytraffic" level="DEBUG"/> | ||
|
||
<root level="ERROR"> | ||
<appender-ref ref="STDOUT"/> | ||
</root> | ||
|
||
</configuration> |
Oops, something went wrong.