1 23 package com.sun.enterprise.tools.verifier.tests.web; 24 25 import com.sun.enterprise.tools.verifier.tests.web.WebTest; 26 import java.util.*; 27 import java.io.*; 28 import com.sun.enterprise.deployment.*; 29 import com.sun.enterprise.tools.verifier.*; 30 import com.sun.enterprise.tools.verifier.tests.*; 31 import com.sun.enterprise.util.FileClassLoader; 32 33 34 37 public class ErrorCode extends WebTest implements WebCheck { 38 39 40 47 public static boolean isValidErrorCode(Integer errorCodeTypeInteger) { 48 int errorCodeType = errorCodeTypeInteger.intValue(); 49 if ((errorCodeType == ErrorCodeTypes.CONTINUE) || 50 (errorCodeType == ErrorCodeTypes.SWITCHING_PROTOCOLS) || 51 (errorCodeType == ErrorCodeTypes.OK) || 52 (errorCodeType == ErrorCodeTypes.CREATED) || 53 (errorCodeType == ErrorCodeTypes.ACCEPTED) || 54 (errorCodeType == ErrorCodeTypes.NON_AUTHORITATIVE_INFORMATION) || 55 (errorCodeType == ErrorCodeTypes.NO_CONTENT) || 56 (errorCodeType == ErrorCodeTypes.RESET_CONTENT) || 57 (errorCodeType == ErrorCodeTypes.PARTIAL_CONTENT) || 58 (errorCodeType == ErrorCodeTypes.MULTIPLE_CHOICES) || 59 (errorCodeType == ErrorCodeTypes.MOVED_PERMANENTLY) || 60 (errorCodeType == ErrorCodeTypes.FOUND) || 61 (errorCodeType == ErrorCodeTypes.SEE_OTHER) || 62 (errorCodeType == ErrorCodeTypes.NOT_MODIFIED) || 63 (errorCodeType == ErrorCodeTypes.USE_PROXY) || 64 (errorCodeType == ErrorCodeTypes.UNUSED) || 65 (errorCodeType == ErrorCodeTypes.TEMPORARY_REDIRECT) || 66 (errorCodeType == ErrorCodeTypes.BAD_REQUEST) || 67 (errorCodeType == ErrorCodeTypes.UNAUTHORIZED) || 68 (errorCodeType == ErrorCodeTypes.PAYMENT_REQUIRED) || 69 (errorCodeType == ErrorCodeTypes.FORBIDDEN) || 70 (errorCodeType == ErrorCodeTypes.NOT_FOUND) || 71 (errorCodeType == ErrorCodeTypes.METHOD_NOT_ALLOWED) || 72 (errorCodeType == ErrorCodeTypes.NOT_ACCEPTABLE) || 73 (errorCodeType == ErrorCodeTypes.PROXY_AUTHENTICATION_REQUIRED) || 74 (errorCodeType == ErrorCodeTypes.REQUEST_TIMEOUT) || 75 (errorCodeType == ErrorCodeTypes.CONFLICT) || 76 (errorCodeType == ErrorCodeTypes.GONE) || 77 (errorCodeType == ErrorCodeTypes.LENGTH_REQUIRED) || 78 (errorCodeType == ErrorCodeTypes.PRECONDITION_FAILED) || 79 (errorCodeType == ErrorCodeTypes.REQUEST_ENTITY_TOO_LARGE) || 80 (errorCodeType == ErrorCodeTypes.REQUEST_URI_TOO_LONG) || 81 (errorCodeType == ErrorCodeTypes.UNSUPPORTED_MEDIA_TYPE) || 82 (errorCodeType == ErrorCodeTypes.REQUESTED_RANGE_NOT_SATISFIABLE) || 83 (errorCodeType == ErrorCodeTypes.EXPECTATION_FAILED) || 84 (errorCodeType == ErrorCodeTypes.INTERNAL_SERVER_ERROR) || 85 (errorCodeType == ErrorCodeTypes.NOT_IMPLEMENTED) || 86 (errorCodeType == ErrorCodeTypes.BAD_GATEWAY) || 87 (errorCodeType == ErrorCodeTypes.SERVICE_UNAVAILABLE) || 88 (errorCodeType == ErrorCodeTypes.GATEWAY_TIMEOUT) || 89 (errorCodeType == ErrorCodeTypes.HTTP_VERSION_NOT_SUPPORTED)) { 90 return true; 91 } else { 92 return false; 93 } 94 95 } 96 97 104 public Result check(WebBundleDescriptor descriptor) { 105 106 Result result = getInitializedResult(); 107 ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor(); 108 109 if (descriptor.getErrorPageDescriptors().hasMoreElements()) { 110 boolean oneFailed = false; 111 boolean foundIt = false; 112 int oneErrorCode = 0; 113 int oneNA = 0; 114 for (Enumeration e = descriptor.getErrorPageDescriptors() ; e.hasMoreElements() ;) { 116 foundIt = false; 117 oneErrorCode++; 118 ErrorPageDescriptorImpl errorpage = (ErrorPageDescriptorImpl) e.nextElement(); 119 String exceptionType = errorpage.getExceptionType(); 120 if (!((exceptionType != null) && (exceptionType.length() > 0))) { 121 Integer errorCode = new Integer ( errorpage.getErrorCode() ); 122 if (isValidErrorCode(errorCode)) { 123 foundIt = true; 124 } else { 125 foundIt = false; 126 } 127 128 if (foundIt) { 129 result.addGoodDetails(smh.getLocalString 130 ("tests.componentNameConstructor", 131 "For [ {0} ]", 132 new Object [] {compName.toString()})); 133 result.addGoodDetails(smh.getLocalString 134 (getClass().getName() + ".passed", 135 "Error code [ {0} ] contains valid HTTP error code within web application [ {1} ]", 136 new Object [] {errorCode.toString(), descriptor.getName()})); 137 } else { 138 if (!oneFailed) { 139 oneFailed = true; 140 } 141 result.addErrorDetails(smh.getLocalString 142 ("tests.componentNameConstructor", 143 "For [ {0} ]", 144 new Object [] {compName.toString()})); 145 result.addErrorDetails(smh.getLocalString 146 (getClass().getName() + ".failed", 147 "Error: error-code [ {0} ] does not contain valid HTTP error code within web application [ {1} ]", 148 new Object [] {errorCode.toString(), descriptor.getName()})); 149 } 150 } else { 151 result.addNaDetails(smh.getLocalString 154 ("tests.componentNameConstructor", 155 "For [ {0} ]", 156 new Object [] {compName.toString()})); 157 result.addNaDetails(smh.getLocalString 158 (getClass().getName() + ".notApplicable1", 159 "Not Applicable: Error-code is [ {0} ], using [ {1} ] instead within web application [ {2} ]", 160 new Object [] {new Integer (errorpage.getErrorCode()), exceptionType, descriptor.getName()})); 161 oneNA++; 162 } 163 } 164 if (oneFailed) { 165 result.setStatus(Result.FAILED); 166 } else if (oneNA == oneErrorCode) { 167 result.setStatus(Result.NOT_APPLICABLE); 168 } else { 169 result.setStatus(Result.PASSED); 170 } 171 } else { 172 result.addNaDetails(smh.getLocalString 173 ("tests.componentNameConstructor", 174 "For [ {0} ]", 175 new Object [] {compName.toString()})); 176 result.notApplicable(smh.getLocalString 177 (getClass().getName() + ".notApplicable", 178 "There are no error-code elements within the web archive [ {0} ]", 179 new Object [] {descriptor.getName()})); 180 } 181 182 return result; 183 } 184 } 185 | Popular Tags |