Skip to content

Commit

Permalink
EA-3407 resgister exception handling, fix beans
Browse files Browse the repository at this point in the history
  • Loading branch information
SrishtiSingh-eu committed Feb 14, 2024
1 parent bb13ef6 commit f90c6d5
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 36 deletions.
20 changes: 0 additions & 20 deletions api/src/main/java/eu/europeana/fulltext/api/config/BeanConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,8 @@
import eu.europeana.fulltext.service.AnnotationApiRestService;
import java.util.Optional;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.core.convert.ConversionService;
import org.springframework.core.convert.support.DefaultConversionService;
import org.springframework.format.support.DefaultFormattingConversionService;
import org.springframework.format.support.FormattingConversionService;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;

@Configuration
public class BeanConfig {
Expand All @@ -38,17 +31,4 @@ public AnnotationApiRestService annotationApiRestService() {
Optional.empty(), settings.getMaxBufferMb()),
settings.getAnnotationsApiKey());
}

//A component required a bean named 'mvcConversionService' that could not be found.
//Caused by: org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'mvcConversionService' is expected to be of type 'org.springframework.format.support.FormattingConversionService'
// but was actually of type 'org.springframework.core.convert.support.DefaultConversionService'
@Bean
public ConversionService mvcConversionService() {
return new FormattingConversionService();
}

@Bean
public RequestMappingHandlerMapping requestMappingHandlerMapping() {
return new RequestMappingHandlerMapping();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@
@Component
public class RequestPathServiceConfig extends AbstractRequestPathMethodService {

//https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.7-Release-Notes#spring-mvcs-requestmappinghandlermapping-is-no-longer-primary
protected RequestPathServiceConfig(WebApplicationContext applicationContext) {
super(applicationContext);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,18 @@ public ErrorAttributes errorAttributes() {
}


/** Setup CORS for all GET, HEAD and OPTIONS, requests.
// TODO Access-Control-Allow-Origin not coming through
/**
* Setup CORS for all GET, HEAD and OPTIONS, requests.
* Now we are using Spring boot version 2.7.x hence no need to add
* WebMvcAutoConfiguration and beans in FTApplication for Cors
* */
*/
@Override
@SuppressWarnings({"external_findsecbugs:PERMISSIVE_CORS", "PERMISSIVE_CORS", "java:S5122"}) //the API is public
public void addCorsMappings(CorsRegistry registry) {
registry
.addMapping("/**")
.allowedOrigins("*") //NOSONAR api available for public use//
.allowedOrigins("*")
.allowedMethods("*")
.allowedHeaders("*")
.allowCredentials(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@
/**
* Created by luthien on 2019-08-13.
*/
//@RestController
@RestController
public class FTErrorController extends AbstractErrorController {

public FTErrorController(ErrorAttributes errorAttributes) {
super(errorAttributes);
}

//
// @RequestMapping(value = "/error", produces = {AcceptUtils.MEDIA_TYPE_JSON, AcceptUtils.MEDIA_TYPE_JSONLD})
// @ResponseBody
// public Map<String, Object> error(final HttpServletRequest request) {
// return this.getErrorAttributes(request, ErrorAttributeOptions.defaults());
// }

@RequestMapping(value = "/error", produces = {AcceptUtils.MEDIA_TYPE_JSON, AcceptUtils.MEDIA_TYPE_JSONLD})
@ResponseBody
public Map<String, Object> error(final HttpServletRequest request) {
return this.getErrorAttributes(request, ErrorAttributeOptions.defaults());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;

/**
* Handles all uncaught exceptions thrown by the application.
*/
@ControllerAdvice
@EnableWebMvc
public class FTExceptionHandler extends EuropeanaGlobalExceptionHandler {

@ExceptionHandler(HttpMessageNotReadableException.class)
Expand Down
8 changes: 5 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
<!-- upgraded to 2.5.14 as 2.6.x is not compatible with swagger (springfox-swagger-ui)-->
<!-- org.apache.tomcat.embed version 9.0.56 is included uptill 2.6.3 which is vulnerable. See : CVE-2022-23181 -->
<!-- <spring-boot.version>2.5.14</spring-boot.version>-->
<spring-boot.version>2.7.12</spring-boot.version>
<!-- spring doc 1.7.0 is coampatible with 2.7.10 spring boot See - https://mvnrepository.com/artifact/org.springdoc/springdoc-openapi-ui/1.7.0-->
<spring-boot.version>2.7.10</spring-boot.version>
<spring-batch.version>4.3.6</spring-batch.version>
<spring-security.version>5.7.8</spring-security.version>
<jackson.version>2.14.0</jackson.version>
Expand All @@ -61,7 +62,8 @@
<junit-jupiter.version>5.6.0</junit-jupiter.version>
<mockito.version>3.7.0</mockito.version>
<unitils.version>3.4.6</unitils.version>
<springdoc.version>1.6.13</springdoc.version>
<!-- <springdoc.version>1.6.13</springdoc.version>-->
<springdoc.version>1.7.0</springdoc.version>
<tomcat.version>9.0.58</tomcat.version>
<mock-webserver.version>4.9.0</mock-webserver.version>
<testcontainers.version>1.16.0</testcontainers.version>
Expand Down Expand Up @@ -224,7 +226,7 @@
<version>${dependency-check-maven.version}</version>
<configuration>
<assemblyAnalyzerEnabled>false</assemblyAnalyzerEnabled>
<failBuildOnCVSS>10</failBuildOnCVSS>
<failBuildOnCVSS>8</failBuildOnCVSS>
<suppressionFiles>
<suppressionFile>owasp-suppress.xml</suppressionFile>
</suppressionFiles>
Expand Down

0 comments on commit f90c6d5

Please sign in to comment.