Search in sources :

Example 1 with ServiceCode

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

the class ServiceCodeExceptionMapper method main.

public static void main(final String[] args) throws SecurityException, NoSuchFieldException {
    for (final ServiceCode code : ServiceCode.values()) {
        System.out.println("Service Code: " + code.getCode());
        System.out.println("Name:         " + code.name());
        System.out.println("Description:  " + code.getSummary(Locale.ENGLISH));
        System.out.println("Retryable:    " + code.isRetryable());
        System.out.println("Fatal:        " + code.isFatal());
        final Field field = ServiceCode.class.getField(code.name());
        final boolean deprecated = field.isAnnotationPresent(Deprecated.class);
        System.out.println("Deprecated:   " + deprecated);
        final StatusType status = code.getHTTPStatus();
        System.out.println("HTTP Status:  " + status.getStatusCode() + " " + status.getReasonPhrase());
        System.out.println();
    }
}
Also used : Field(java.lang.reflect.Field) ServiceCode(com.emc.storageos.svcs.errorhandling.resources.ServiceCode) StatusType(javax.ws.rs.core.Response.StatusType)

Example 2 with ServiceCode

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

the class ServiceErrorTest method testXMLUnauthorized.

@Test
public void testXMLUnauthorized() throws JAXBException {
    final ServiceCode code = ServiceCode.SECURITY_UNAUTHORIZED_OPERATION;
    final String message = "No credentials were specified";
    final String xml = xml(error(code, message, null));
    // useful for debugging
    // System.out.println(xml);
    assertXmlContains(xml, "code", "4000");
    assertXmlContains(xml, "retryable", "false");
    assertXmlContains(xml, "details", message);
}
Also used : ServiceCode(com.emc.storageos.svcs.errorhandling.resources.ServiceCode) Test(org.junit.Test)

Example 3 with ServiceCode

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

the class Documenter method document.

private static void document(PrintStream out) throws NoSuchFieldException {
    final Map<ServiceCode, List<DocumenterEntry>> codeToEntries = new TreeMap<ServiceCode, List<DocumenterEntry>>();
    for (final ServiceCode value : ServiceCode.values()) {
        codeToEntries.put(value, new ArrayList<DocumenterEntry>());
    }
    for (final DocumenterEntry entry : createEntries()) {
        codeToEntries.get(entry.getCode()).add(entry);
    }
    for (final Entry<ServiceCode, List<DocumenterEntry>> pair : codeToEntries.entrySet()) {
        final ServiceCode code = pair.getKey();
        final List<DocumenterEntry> messages = pair.getValue();
        Collections.sort(messages);
        // no point documenting ServiceCodes that aren't in use
        if (messages.isEmpty()) {
            continue;
        }
        documentServiceCode(out, code, messages);
        documentMessages(out, messages);
        out.println();
    }
}
Also used : ServiceCode(com.emc.storageos.svcs.errorhandling.resources.ServiceCode) ArrayList(java.util.ArrayList) List(java.util.List) TreeMap(java.util.TreeMap)

Example 4 with ServiceCode

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

the class DocumenterTest method serviceCodeToStatus.

@Test
public void serviceCodeToStatus() {
    final Collection<DocumenterEntry> entries = Documenter.createEntries();
    final Map<ServiceCode, Set<StatusType>> serviceToStatus = new HashMap<ServiceCode, Set<StatusType>>();
    for (final DocumenterEntry entry : entries) {
        if (!serviceToStatus.containsKey(entry.getCode())) {
            serviceToStatus.put(entry.getCode(), new HashSet<StatusType>());
        }
        serviceToStatus.get(entry.getCode()).add(entry.getStatus());
    }
    final Map<ServiceCode, Set<StatusType>> failures = new HashMap<ServiceCode, Set<StatusType>>();
    for (final Entry<ServiceCode, Set<StatusType>> entry : serviceToStatus.entrySet()) {
        if (entry.getValue().size() > 1) {
            failures.put(entry.getKey(), entry.getValue());
        }
    }
    assertTrue("Some service codes map to more than one HTTP status code: " + failures, failures.isEmpty());
}
Also used : ServiceCode(com.emc.storageos.svcs.errorhandling.resources.ServiceCode) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) StatusType(javax.ws.rs.core.Response.StatusType) DocumenterEntry(com.emc.storageos.svcs.errorhandling.utils.Documenter.DocumenterEntry) Test(org.junit.Test)

Example 5 with ServiceCode

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

the class ApiDoclet method findErrorCodes.

private static synchronized List<ApiErrorCode> findErrorCodes(ClassDoc[] classes) {
    // Find ServiceCode Class
    ClassDoc serviceCodeClass = null;
    for (ClassDoc classDoc : classes) {
        if (classDoc.qualifiedName().equals(ServiceCode.class.getCanonicalName())) {
            serviceCodeClass = classDoc;
            break;
        }
    }
    if (serviceCodeClass == null) {
        throw new RuntimeException("Unable to find ServiceCode Class");
    }
    // Extract ServiceCode information
    List<ApiErrorCode> errorCodes = Lists.newArrayList();
    for (FieldDoc field : serviceCodeClass.enumConstants()) {
        ApiErrorCode errorCode = new ApiErrorCode(ServiceCode.valueOf(field.name()));
        if (AnnotationUtils.hasAnnotation(field, KnownAnnotations.Deprecated_Annotation)) {
            errorCode.setDeprecated(true);
        }
        errorCodes.add(errorCode);
    }
    Collections.sort(errorCodes, new Comparator<ApiErrorCode>() {

        @Override
        public int compare(ApiErrorCode o1, ApiErrorCode o2) {
            return Integer.valueOf(o1.getCode()).compareTo(o2.getCode());
        }
    });
    return errorCodes;
}
Also used : ServiceCode(com.emc.storageos.svcs.errorhandling.resources.ServiceCode) ApiErrorCode(com.emc.apidocs.model.ApiErrorCode)

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