Search in sources :

Example 11 with ServiceCode

use of com.emc.storageos.svcs.errorhandling.resources.ServiceCode in project coprhd-controller by CoprHD.

the class ExceptionMessagesProxy method invoke.

@Override
public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
    final Class<?> type = type(method);
    final String detailBase = detailBase(method);
    final String detailKey = method.getName();
    final ServiceCode serviceCode = serviceCode(method);
    final Throwable cause = cause(args);
    if (ServiceError.class.isAssignableFrom(type)) {
        return contructServiceError(serviceCode, detailBase, detailKey, convertThrowableMessages(args));
    }
    Exception exception = contructException(type, serviceCode, cause, detailBase, detailKey, convertThrowableMessages(args));
    StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
    // removing the following 3 stack trace elements from the trackstrace:
    // 0: Thread#getStackTrace
    // 1: ExceptionMessagesProxy#invoke
    // 2: com.sun.proxy.$ProxyXX#<methodName>
    exception.setStackTrace(Arrays.copyOfRange(stackTrace, 3, stackTrace.length));
    return exception;
}
Also used : DeclareServiceCode(com.emc.storageos.svcs.errorhandling.annotations.DeclareServiceCode) ServiceCode(com.emc.storageos.svcs.errorhandling.resources.ServiceCode) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 12 with ServiceCode

use of com.emc.storageos.svcs.errorhandling.resources.ServiceCode in project coprhd-controller by CoprHD.

the class ExceptionMessagesProxy method serviceCode.

/**
 * Get the specified {@link ServiceCode} from the {@link DeclareServiceCode} annotation
 *
 * @param method
 * @return
 */
private ServiceCode serviceCode(final Method method) {
    final DeclareServiceCode declaredServiceCode = method.getAnnotation(DeclareServiceCode.class);
    if (declaredServiceCode == null) {
        throw new IllegalStateException("A service code must be provided via @DeclareServiceCode");
    }
    final ServiceCode serviceCode = declaredServiceCode.value();
    return serviceCode;
}
Also used : DeclareServiceCode(com.emc.storageos.svcs.errorhandling.annotations.DeclareServiceCode) ServiceCode(com.emc.storageos.svcs.errorhandling.resources.ServiceCode) DeclareServiceCode(com.emc.storageos.svcs.errorhandling.annotations.DeclareServiceCode)

Aggregations

ServiceCode (com.emc.storageos.svcs.errorhandling.resources.ServiceCode)12 Test (org.junit.Test)5 StatusType (javax.ws.rs.core.Response.StatusType)3 DeclareServiceCode (com.emc.storageos.svcs.errorhandling.annotations.DeclareServiceCode)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 TreeSet (java.util.TreeSet)2 ApiErrorCode (com.emc.apidocs.model.ApiErrorCode)1 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)1 DocumenterEntry (com.emc.storageos.svcs.errorhandling.utils.Documenter.DocumenterEntry)1 Field (java.lang.reflect.Field)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ResourceBundle (java.util.ResourceBundle)1 TreeMap (java.util.TreeMap)1