Skip to content

Commit

Permalink
fix: refactor code to eliminate two minor sonar reported bugs (jhipst…
Browse files Browse the repository at this point in the history
  • Loading branch information
SudharakaP authored Oct 31, 2020
1 parent c802ece commit ef1346e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.Paths;
import java.util.EnumSet;
import java.util.List;
import javax.servlet.DispatcherType;
import javax.servlet.FilterRegistration;
import javax.servlet.ServletContext;
Expand Down Expand Up @@ -150,7 +151,8 @@ private void initCachingHttpHeadersFilter(ServletContext servletContext, EnumSet
public CorsFilter corsFilter() {
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
CorsConfiguration config = jHipsterProperties.getCors();
if (config.getAllowedOrigins() != null && !config.getAllowedOrigins().isEmpty()) {
List<String> allowedOrigins = config.getAllowedOrigins();
if (allowedOrigins != null && !allowedOrigins.isEmpty()) {
log.debug("Registering CORS filter");
source.registerCorsConfiguration("/api/**", config);
source.registerCorsConfiguration("/management/**", config);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import io.github.jhipster.web.util.HeaderUtil;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
Expand Down Expand Up @@ -64,6 +65,12 @@ public ResponseEntity<Problem> process(@Nullable ResponseEntity<Problem> entity,
if (entity == null) {
return entity;
}

HttpServletRequest nativeRequest = request.getNativeRequest(HttpServletRequest.class);
if (nativeRequest == null) {
return entity;
}

Problem problem = entity.getBody();
if (!(problem instanceof ConstraintViolationProblem || problem instanceof DefaultProblem)) {
return entity;
Expand All @@ -73,7 +80,7 @@ public ResponseEntity<Problem> process(@Nullable ResponseEntity<Problem> entity,
.withType(Problem.DEFAULT_TYPE.equals(problem.getType()) ? ErrorConstants.DEFAULT_TYPE : problem.getType())
.withStatus(problem.getStatus())
.withTitle(problem.getTitle())
.with(PATH_KEY, request.getNativeRequest(HttpServletRequest.class).getRequestURI());
.with(PATH_KEY, nativeRequest.getRequestURI());

if (problem instanceof ConstraintViolationProblem) {
builder
Expand Down

0 comments on commit ef1346e

Please sign in to comment.