Summary Table
Categories |
Total Count |
PII |
0 |
URL |
0 |
DNS |
0 |
EKL |
0 |
IP |
0 |
PORT |
0 |
VsID |
0 |
CF |
0 |
AI |
0 |
VPD |
0 |
PL |
0 |
Other |
0 |
File Content
package gov.va.med.pbm.ampl.controller;
import org.springframework.security.web.firewall.RequestRejectedException;
import java.util.Optional;
import javax.servlet.http.HttpServletRequest;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
/**
*
* The SecurityErrorController is used to map {@link HttpStatus} codes to a given error.
* <p>
* This class should be reserved for catching application container exceptions, so they may be handled by the API.
*
* @author Ian Meinert
*
*/
@RestController
public class SecurityErrorController {
/**
* This method catches the RequestRejectedException thrown in context, then throws it to the API for proper handling.
*
* @param exception the {@link RequestRejectedException} thrown by container
* @param request the HTTP servlet request
*/
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
@RequestMapping("/errors/500")
public void handleRequestRejectedException(RequestRejectedException exception, HttpServletRequest request) {
Optional<Throwable> throwable = Optional.of((Throwable) request.getAttribute("javax.servlet.error.exception"));
if (throwable.isPresent()) {
throw new RequestRejectedException(throwable.get().getLocalizedMessage());
}
}
}