X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=webapp-backend%2Fsrc%2Fmain%2Fjava%2Forg%2Foranosc%2Fric%2Fportal%2Fdash%2Fcontroller%2FSimpleErrorController.java;fp=webapp-backend%2Fsrc%2Fmain%2Fjava%2Forg%2Foranosc%2Fric%2Fportal%2Fdash%2Fcontroller%2FSimpleErrorController.java;h=0000000000000000000000000000000000000000;hb=f660cae7a447b60d84ef75f7c2bcbf62412d4579;hp=f7180d3a6baab7f966c609359c4cfa935462b6f2;hpb=0f3312b36f849df0e1671c333e0072aca3a1acf6;p=portal%2Fric-dashboard.git diff --git a/webapp-backend/src/main/java/org/oranosc/ric/portal/dash/controller/SimpleErrorController.java b/webapp-backend/src/main/java/org/oranosc/ric/portal/dash/controller/SimpleErrorController.java deleted file mode 100644 index f7180d3a..00000000 --- a/webapp-backend/src/main/java/org/oranosc/ric/portal/dash/controller/SimpleErrorController.java +++ /dev/null @@ -1,100 +0,0 @@ -/*- - * ========================LICENSE_START================================= - * ORAN-OSC - * %% - * Copyright (C) 2019 AT&T Intellectual Property and Nokia - * %% - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ========================LICENSE_END=================================== - */ -package org.oranosc.ric.portal.dash.controller; - -import java.util.Map; - -import javax.servlet.http.HttpServletRequest; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.web.servlet.error.ErrorAttributes; -import org.springframework.boot.web.servlet.error.ErrorController; -import org.springframework.util.Assert; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.context.request.ServletWebRequest; -import org.springframework.web.context.request.WebRequest; - -import springfox.documentation.annotations.ApiIgnore; - -/** - * Returns JSON on error within the Spring-managed context. Does not fire for - * anything else; e.g., resource not found outside the context. If trace is - * requested via request parameter ("?trace=true") and available, adds stack - * trace information to the standard JSON error response. - * - * Excluded from Swagger API documentation. - * - * https://stackoverflow.com/questions/25356781/spring-boot-remove-whitelabel-error-page - * https://www.baeldung.com/spring-boot-custom-error-page - */ -@ApiIgnore -@RestController -public class SimpleErrorController implements ErrorController { - - private static final String ERROR_PATH = "/error"; - private static final String TRACE = "trace"; - private final ErrorAttributes errorAttributes; - - /** - * Constructor - * - * @param errorAttributes - * error attributes must not be null - */ - @Autowired - public SimpleErrorController(ErrorAttributes errorAttributes) { - Assert.notNull(errorAttributes, "ErrorAttributes must not be null"); - this.errorAttributes = errorAttributes; - } - - @Override - public String getErrorPath() { - return ERROR_PATH; - } - - /** - * Builds a map with error details - * - * @param aRequest - * HttpServletRequest - * @return Map of String to Object - */ - @RequestMapping(ERROR_PATH) - public Map error(HttpServletRequest aRequest) { - Map body = getErrorAttributes(aRequest, getTraceParameter(aRequest)); - body.put("decorated-by", SimpleErrorController.class.getName()); - body.computeIfPresent(TRACE, (key, value) -> body.put(TRACE, ((String) value).split("\n\t"))); - return body; - } - - private boolean getTraceParameter(HttpServletRequest request) { - String parameter = request.getParameter(TRACE); - if (parameter == null) - return false; - return !"false".equalsIgnoreCase(parameter); - } - - private Map getErrorAttributes(HttpServletRequest aRequest, boolean includeStackTrace) { - WebRequest webRequest = new ServletWebRequest(aRequest); - return errorAttributes.getErrorAttributes(webRequest, includeStackTrace); - } - -}