diff --git a/commons-error/src/main/java/eu/europeana/api/commons/error/EuropeanaApiErrorAttributes.java b/commons-error/src/main/java/eu/europeana/api/commons/error/EuropeanaApiErrorAttributes.java index b5c626f7..857868cb 100644 --- a/commons-error/src/main/java/eu/europeana/api/commons/error/EuropeanaApiErrorAttributes.java +++ b/commons-error/src/main/java/eu/europeana/api/commons/error/EuropeanaApiErrorAttributes.java @@ -54,7 +54,7 @@ private void addPathRequestParameters(Map errorAttributes, WebRe String paramName = it.next(); s.append(paramName); String paramValue = webRequest.getParameter(paramName); - if (!StringUtils.isEmpty(paramValue)) { + if (StringUtils.hasText(paramValue)) { s.append("=").append(paramValue); } } diff --git a/commons-web/pom.xml b/commons-web/pom.xml index 1fe78c87..e4248d0c 100644 --- a/commons-web/pom.xml +++ b/commons-web/pom.xml @@ -74,7 +74,7 @@ ${version.springBoot} provided - + org.apache.logging.log4j log4j-core diff --git a/commons-web/src/main/java/eu/europeana/api/commons/web/controller/BaseRestController.java b/commons-web/src/main/java/eu/europeana/api/commons/web/controller/BaseRestController.java index 044b2e3d..c9f1afcb 100644 --- a/commons-web/src/main/java/eu/europeana/api/commons/web/controller/BaseRestController.java +++ b/commons-web/src/main/java/eu/europeana/api/commons/web/controller/BaseRestController.java @@ -79,8 +79,7 @@ public String generateETag(Date timestamp, String format, String version) { serialCode += "0.0.1-SNAPSHOT".hashCode(); } - // see also https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/ETag - return "W/\"" + Long.toHexString(serialCode) + "\""; + return "\"" + Long.toHexString(serialCode) + "\""; } /** @@ -90,10 +89,13 @@ public String generateETag(Date timestamp, String format, String version) { */ protected String getMethodsForRequestPattern(HttpServletRequest request, AbstractRequestPathMethodService requestMethodService) { - Optional methodsForRequestPattern = + if(requestMethodService != null) { + Optional methodsForRequestPattern = requestMethodService.getMethodsForRequestPattern(request); - - return methodsForRequestPattern.orElse(request.getMethod()); + return methodsForRequestPattern.orElse(request.getMethod()); + }else { + return request.getMethod(); + } } } diff --git a/commons-web/src/main/java/eu/europeana/api/commons/web/exception/EuropeanaGlobalExceptionHandler.java b/commons-web/src/main/java/eu/europeana/api/commons/web/exception/EuropeanaGlobalExceptionHandler.java index 1110d956..9a5e4a1e 100644 --- a/commons-web/src/main/java/eu/europeana/api/commons/web/exception/EuropeanaGlobalExceptionHandler.java +++ b/commons-web/src/main/java/eu/europeana/api/commons/web/exception/EuropeanaGlobalExceptionHandler.java @@ -216,11 +216,23 @@ public ResponseEntity handleMethodArgNotValidExceptio protected HttpHeaders createHttpHeaders(HttpServletRequest httpRequest) { HttpHeaders headers = new HttpHeaders(); + //enforce application/json as content type, it is the only serialization supported for exceptions headers.setContentType(MediaType.APPLICATION_JSON); - if(requestPathMethodService!=null) { - String allowHeaderValue = requestPathMethodService.getMethodsForRequestPattern(httpRequest).orElse(httpRequest.getMethod()); + + //autogenerate allow header if the service is configured + if(getRequestPathMethodService()!=null) { + String allowHeaderValue = getRequestPathMethodService().getMethodsForRequestPattern(httpRequest).orElse(httpRequest.getMethod()); headers.add(HttpHeaders.ALLOW, allowHeaderValue); } return headers; } + + /** + * The bean needs to be defined in the individual APIs + * + * @return + */ + AbstractRequestPathMethodService getRequestPathMethodService() { + return requestPathMethodService; + } }