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();
}
}
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);
}
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();
}
}
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());
}
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;
}
Aggregations