Skip to content

Commit

Permalink
Fix compile errors with spring boot 2.5 #609
Browse files Browse the repository at this point in the history
- Former deprecated method ErrorController#getErrorPath was removed
  in Spring Boot 2.5.
  see spring-projects/spring-boot#19844
- setting now `server.error.path` in PDS and SecHub server and using
  the variable inside error controller implementations
  • Loading branch information
de-jcup committed Jul 2, 2021
1 parent 2a37e3f commit 3f35bfc
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,20 @@ public class PDSServerErrorController implements ErrorController {

private static final Logger LOG = LoggerFactory.getLogger(PDSServerErrorController.class);

private static final String PATH = "/error"; // NOSONAR

@PDSMustBeDocumented(value="When enabled, additional debug information are returned in case of failures. Do NOT use this in production.",scope="development")
@Value("${sechub.pds.server.debug:false}")
private boolean debug;

@Autowired
private ErrorAttributes errorAttributes;

@RequestMapping(value = PATH, produces = { "application/json" })
@RequestMapping(value = "${server.error.path}", produces = { "application/json" })
ResponseEntity<PDSServerError> error(HttpServletRequest request, HttpServletResponse response) {
LOG.info("handling error on rest side");

return ResponseEntity.status(response.getStatus()).body(new PDSServerError(response.getStatus(), getErrorAttributes(request, debug)));
}

@Override
public String getErrorPath() {
return PATH;
}

private Map<String, Object> getErrorAttributes(HttpServletRequest request, boolean includeStackTrace) {
ServletWebRequest webRequest = new ServletWebRequest(request);
ErrorAttributeOptions options = ErrorAttributeOptions.defaults();
Expand Down
2 changes: 2 additions & 0 deletions sechub-pds/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ security:
# - SSL setup (default)
# --------------------------------------
server:
error:
path: "/error"
port:
8444
ssl:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,14 @@
@RestController
public class ServerErrorController implements ErrorController {


private static final String PATH = "/error"; // NOSONAR

@MustBeDocumented("When debug flag is set, rest call reponse error messages do also contain stacktraces.")
@Value("${sechub.server.debug:false}")
private boolean debug;

@Autowired
private ErrorAttributes errorAttributes;

@RequestMapping(value = PATH)
@RequestMapping(value = "${server.error.path}")
ResponseEntity<ServerError> error(HttpServletRequest request, HttpServletResponse response){
return ResponseEntity.status(response.getStatus())
.body(
Expand All @@ -39,12 +36,6 @@ ResponseEntity<ServerError> error(HttpServletRequest request, HttpServletRespons
);
}


@Override
public String getErrorPath() {
return PATH;
}

private Map<String, Object> getErrorAttributes(HttpServletRequest request, boolean includeStackTrace) {
ServletWebRequest webRequest = new ServletWebRequest(request);
ErrorAttributeOptions options = ErrorAttributeOptions.defaults();
Expand Down
4 changes: 3 additions & 1 deletion sechub-server/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,12 @@ security:
# - SSL setup (default)
# --------------------------------------
server:
error:
path: "/error"
port:
8443
ssl:
enabled: true # alwasy enabled
enabled: true # always enabled
protocol: TLS
enabled-protocols: TLSv1.2,TLSv1.3
# keystore, alias etc. must be defined outside
Expand Down

0 comments on commit 3f35bfc

Please sign in to comment.