summaryrefslogtreecommitdiffstats
path: root/models-base/src/main/java/org/onap
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@est.tech>2019-03-26 09:26:00 +0000
committerliamfallon <liam.fallon@est.tech>2019-03-26 09:26:00 +0000
commit35c6f2df3df2de7f54f717c2167f7b170494cdc9 (patch)
treeda0710bb9dec90881ab5e4b084595af3cbc9d1d0 /models-base/src/main/java/org/onap
parentb6649e710c6aad05b6cbb64fa61d6aa0ad82f12a (diff)
Add ErrorResponse to policy framework exceptions
The ErrorResponse object is now contained in Policy Framework exceptions. Issue-ID: POLICY-1095 Change-Id: Ib0ce6cdbbead939afefc4afa3f507eb1a28c4a5c Signed-off-by: liamfallon <liam.fallon@est.tech>
Diffstat (limited to 'models-base/src/main/java/org/onap')
-rw-r--r--models-base/src/main/java/org/onap/policy/models/base/PfModelException.java54
-rw-r--r--models-base/src/main/java/org/onap/policy/models/base/PfModelExceptionInfo.java59
-rw-r--r--models-base/src/main/java/org/onap/policy/models/base/PfModelRuntimeException.java36
3 files changed, 20 insertions, 129 deletions
diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfModelException.java b/models-base/src/main/java/org/onap/policy/models/base/PfModelException.java
index ce44e51f3..46c5bd311 100644
--- a/models-base/src/main/java/org/onap/policy/models/base/PfModelException.java
+++ b/models-base/src/main/java/org/onap/policy/models/base/PfModelException.java
@@ -25,18 +25,20 @@ import javax.ws.rs.core.Response;
import lombok.Getter;
import lombok.ToString;
-import org.apache.commons.lang3.exception.ExceptionUtils;
+import org.onap.policy.models.errors.concepts.ErrorResponse;
+import org.onap.policy.models.errors.concepts.ErrorResponseInfo;
+import org.onap.policy.models.errors.concepts.ErrorResponseUtils;
/**
* This class is a base exception from which all model exceptions are sub classes.
*/
@Getter
@ToString
-public class PfModelException extends Exception implements PfModelExceptionInfo {
+public class PfModelException extends Exception implements ErrorResponseInfo {
private static final long serialVersionUID = -8507246953751956974L;
- // The status code on the exception
- private final Response.Status statusCode;
+ // The error response of the exception
+ private final ErrorResponse errorResponse = new ErrorResponse();
// The object on which the exception was thrown
private final transient Object object;
@@ -60,7 +62,8 @@ public class PfModelException extends Exception implements PfModelExceptionInfo
*/
public PfModelException(final Response.Status statusCode, final String message, final Object object) {
super(message);
- this.statusCode = statusCode;
+ errorResponse.setResponseCode(statusCode);
+ ErrorResponseUtils.getExceptionMessages(errorResponse, this);
this.object = object;
}
@@ -86,45 +89,8 @@ public class PfModelException extends Exception implements PfModelExceptionInfo
public PfModelException(final Response.Status statusCode, final String message, final Exception exception,
final Object object) {
super(message, exception);
- this.statusCode = statusCode;
+ errorResponse.setResponseCode(statusCode);
+ ErrorResponseUtils.getExceptionMessages(errorResponse, this);
this.object = object;
}
-
- /**
- * Get the message from this exception and its causes.
- *
- * @return the cascaded messages from this exception and the exceptions that caused it
- */
- @Override
- public String getCascadedMessage() {
- return buildCascadedMessage(this);
- }
-
- /**
- * Build a cascaded message from an exception and all its nested exceptions.
- *
- * @param throwable the top level exception
- * @return cascaded message string
- */
- public static String buildCascadedMessage(Throwable throwable) {
- final StringBuilder builder = new StringBuilder();
- builder.append(throwable.getMessage());
-
- for (Throwable t = throwable; t != null; t = t.getCause()) {
- builder.append("\ncaused by: ");
- builder.append(t.getMessage());
- }
-
- return builder.toString();
- }
-
- /**
- * Get the stack trace of the exception as a string.
- *
- * @return the stack trace of this message as a string
- */
- @Override
- public String getStackTraceAsString() {
- return ExceptionUtils.getStackTrace(this);
- }
}
diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfModelExceptionInfo.java b/models-base/src/main/java/org/onap/policy/models/base/PfModelExceptionInfo.java
deleted file mode 100644
index 2fe244cec..000000000
--- a/models-base/src/main/java/org/onap/policy/models/base/PfModelExceptionInfo.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
- * ================================================================================
- * 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.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.models.base;
-
-import javax.ws.rs.core.Response;
-
-/**
- * Interface implemented bu Policy framework model exceptions to allow uniform reading of status codes and cascaded
- * messages.
- *
- * @author Liam Fallon (liam.fallon@est.tech)
- */
-public interface PfModelExceptionInfo {
-
- /**
- * Get the status code associated with an exception.
- * @return the status code
- */
- public Response.Status getStatusCode();
-
- /**
- * Get the messages for all the cascaded exceptions in an exception.
- *
- * @return the cascaded message
- */
- public String getCascadedMessage();
-
- /**
- * Get the object associated with an exception.
- *
- * @return the object associated with an exception
- */
- public Object getObject();
-
- /**
- * Get the stack trace of the exception as a string.
- *
- * @return the stack trace of this message as a string
- */
- public String getStackTraceAsString();
-}
diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfModelRuntimeException.java b/models-base/src/main/java/org/onap/policy/models/base/PfModelRuntimeException.java
index 32855c2a4..472412865 100644
--- a/models-base/src/main/java/org/onap/policy/models/base/PfModelRuntimeException.java
+++ b/models-base/src/main/java/org/onap/policy/models/base/PfModelRuntimeException.java
@@ -25,18 +25,20 @@ import javax.ws.rs.core.Response;
import lombok.Getter;
import lombok.ToString;
-import org.apache.commons.lang3.exception.ExceptionUtils;
+import org.onap.policy.models.errors.concepts.ErrorResponse;
+import org.onap.policy.models.errors.concepts.ErrorResponseInfo;
+import org.onap.policy.models.errors.concepts.ErrorResponseUtils;
/**
* This class is a base model run time exception from which all model run time exceptions are sub classes.
*/
@Getter
@ToString
-public class PfModelRuntimeException extends RuntimeException implements PfModelExceptionInfo {
+public class PfModelRuntimeException extends RuntimeException implements ErrorResponseInfo {
private static final long serialVersionUID = -8507246953751956974L;
- // The return code on the exception
- private final Response.Status statusCode;
+ // The error response of the exception
+ private final ErrorResponse errorResponse = new ErrorResponse();
// The object on which the exception was thrown
private final transient Object object;
@@ -61,7 +63,8 @@ public class PfModelRuntimeException extends RuntimeException implements PfModel
public PfModelRuntimeException(final Response.Status statusCode, final String message, final Object object) {
super(message);
this.object = object;
- this.statusCode = statusCode;
+ errorResponse.setResponseCode(statusCode);
+ ErrorResponseUtils.getExceptionMessages(errorResponse, this);
}
/**
@@ -87,26 +90,7 @@ public class PfModelRuntimeException extends RuntimeException implements PfModel
final Object object) {
super(message, exception);
this.object = object;
- this.statusCode = statusCode;
- }
-
- /**
- * Get the message from this exception and its causes.
- *
- * @return the message of this exception and all the exceptions that caused this exception
- */
- @Override
- public String getCascadedMessage() {
- return PfModelException.buildCascadedMessage(this);
- }
-
- /**
- * Get the stack trace of the exception as a string.
- *
- * @return the stack trace of this message as a string
- */
- @Override
- public String getStackTraceAsString() {
- return ExceptionUtils.getStackTrace(this);
+ errorResponse.setResponseCode(statusCode);
+ ErrorResponseUtils.getExceptionMessages(errorResponse, this);
}
}