Skip to content

Commit

Permalink
Fixed issue where the old version of metacat-client was failing to ge…
Browse files Browse the repository at this point in the history
…t the detailed error message. Upgraded to Spring Boot 2.3.3.RELEASE and Spring cloud Hoxton.SR8. (#409)
  • Loading branch information
ajoymajumdar committed Sep 25, 2020
1 parent 72ad793 commit c7ceed0
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 31 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ configure(javaProjects) {
dependency("net.snowflake:snowflake-jdbc:3.4.2")
dependency("com.esotericsoftware.kryo:kryo:2.22")
dependency("org.apache.iceberg:iceberg-spark-runtime:${iceberg_version}")
dependency("com.datastax.cassandra:cassandra-driver-core:3.7.2")
}
}

Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
## Spring Dependency Versions

# Used in documentation and for including the Gradle plugin
spring_boot_version=2.2.5.RELEASE
spring_cloud_version=Hoxton.SR7
spring_boot_version=2.3.3.RELEASE
spring_cloud_version=Hoxton.SR8
google_guice_version=4.1.0
spock_version=1.3-groovy-2.5

Expand Down
1 change: 1 addition & 0 deletions metacat-main/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ dependencies {
compile("org.springframework.boot:spring-boot-starter-hateoas")
compile("org.springframework.boot:spring-boot-starter-logging")
compile("org.springframework.boot:spring-boot-starter-tomcat")
compile("javax.validation:validation-api")

/*******************************
* Provided Dependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package com.netflix.metacat.main.api;

import org.springframework.boot.autoconfigure.web.servlet.error.AbstractErrorController;
import org.springframework.boot.web.error.ErrorAttributeOptions;
import org.springframework.boot.web.servlet.error.ErrorAttributes;
import org.springframework.boot.autoconfigure.web.ErrorProperties;
import org.springframework.boot.autoconfigure.web.servlet.error.ErrorViewResolver;
Expand Down Expand Up @@ -57,20 +58,44 @@ public MetacatErrorController(final ErrorAttributes errorAttributes, final Error
@RequestMapping
@ResponseBody
public ResponseEntity<Map<String, Object>> error(final HttpServletRequest request) {
final Map<String, Object> body = getErrorAttributes(request, isIncludeStackTrace(request));
final Map<String, Object> body = getErrorAttributes(request, getErrorAttributeOptions(request));
final HttpStatus status = getStatus(request);
return new ResponseEntity<>(body, status);
}

/**
* Determine if the stacktrace attribute should be included.
* @param request the source request
* @return if the stacktrace attribute should be included
*/
private boolean isIncludeStackTrace(final HttpServletRequest request) {
final ErrorProperties.IncludeStacktrace include = this.errorProperties.getIncludeStacktrace();
return include == ErrorProperties.IncludeStacktrace.ALWAYS
|| include == ErrorProperties.IncludeStacktrace.ON_TRACE_PARAM && getTraceParameter(request);
private ErrorAttributeOptions getErrorAttributeOptions(final HttpServletRequest request) {
ErrorAttributeOptions options = ErrorAttributeOptions.defaults();
if (includeStackTrace(request)) {
options = options.including(ErrorAttributeOptions.Include.STACK_TRACE);
}
if (includeMessage(request)) {
options = options.including(ErrorAttributeOptions.Include.MESSAGE);
}
return options;
}

@SuppressWarnings("deprecation")
private boolean includeStackTrace(final HttpServletRequest request) {
switch (this.errorProperties.getIncludeStacktrace()) {
case ALWAYS:
return true;
case ON_PARAM:
case ON_TRACE_PARAM:
return getBooleanParameter(request, "trace");
default:
return false;
}
}

private boolean includeMessage(final HttpServletRequest request) {
switch (this.errorProperties.getIncludeMessage()) {
case ALWAYS:
return true;
case ON_PARAM:
return getBooleanParameter(request, "message");
default:
return false;
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@

import com.netflix.metacat.main.api.ApiFilter;
import com.netflix.metacat.main.api.MetacatErrorController;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.boot.web.error.ErrorAttributeOptions;
import org.springframework.boot.web.servlet.error.DefaultErrorAttributes;
import org.springframework.boot.web.servlet.error.ErrorAttributes;
import org.springframework.boot.autoconfigure.web.ErrorProperties;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand Down Expand Up @@ -91,36 +92,25 @@ public ErrorAttributes errorAttributes() {
* {@inheritDoc}
*/
@Override
public Map<String, Object> getErrorAttributes(
final WebRequest webRequest,
final boolean includeStackTrace
) {
public Map<String, Object> getErrorAttributes(final WebRequest webRequest,
final ErrorAttributeOptions options) {
final Map<String, Object> errorAttributes
= super.getErrorAttributes(webRequest, includeStackTrace);
= super.getErrorAttributes(webRequest, options);
errorAttributes.put("error", errorAttributes.get("message"));
return errorAttributes;
}
};
}

/**
* Returns the default error properties.
* @return default error properties.
*/
@Bean
public ErrorProperties errorProperties() {
return new ErrorProperties();
}

/**
* Returns the error controller.
* @param errorAttributes error attributes
* @param errorProperties error properties
* @param serverProperties server properties
* @return error controller
*/
@Bean
public MetacatErrorController metacatErrorController(final ErrorAttributes errorAttributes,
final ErrorProperties errorProperties) {
return new MetacatErrorController(errorAttributes, errorProperties);
final ServerProperties serverProperties) {
return new MetacatErrorController(errorAttributes, serverProperties.getError());
}
}
3 changes: 2 additions & 1 deletion metacat-main/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ netflix:

server:
error:
includeStacktrace: on_trace_param
includeStacktrace: on_param
includeMessage: always

spring:
application:
Expand Down

0 comments on commit c7ceed0

Please sign in to comment.