1 23 package com.sun.enterprise.tools.verifier.tests.web; 24 25 import java.util.*; 26 import java.lang.reflect.Modifier ; 27 import com.sun.enterprise.deployment.*; 28 import com.sun.enterprise.deployment.deploy.shared.FileArchive; 29 import com.sun.enterprise.tools.verifier.*; 30 31 38 public class ServletClassDeclared extends WebTest implements WebCheck { 39 40 final String servletClassPath = "WEB-INF/classes"; 41 42 49 public Result check(WebBundleDescriptor descriptor) { 50 51 Result result = getInitializedResult(); 52 if(getVerifierContext().getJavaEEVersion().compareTo(SpecVersionMapper.JavaEEVersion_5) >=0){ 54 result.setStatus(Result.NOT_APPLICABLE); 55 return result; 56 } 57 59 boolean oneWarning = false; 60 boolean foundOne=false; 61 62 result = loadWarFile(descriptor); 64 65 FileArchive arch = null; 67 Enumeration entries= null; 68 Object entry; 70 71 try { 72 String uri = getAbstractArchiveUri(descriptor); 74 try { 75 arch = new FileArchive(); 76 arch.open(uri); 77 entries = arch.entries(); 78 }catch (Exception e) { throw e; } 79 } catch(Exception e) { 85 e.printStackTrace(); 86 result.failed(smh.getLocalString 87 (getClass().getName() + ".exception", 88 "IOException while loading the war file [ {0} ]", 89 new Object [] {descriptor.getName()})); 90 91 return result; 92 } 93 while (entries.hasMoreElements()) { 94 entry = entries.nextElement(); 95 String name = (String )entry; 97 if (name.startsWith(servletClassPath)) { 102 if (name.endsWith(".class")) { 103 String classEntryName = name.substring(0, name.length()-".class".length()); 104 classEntryName = classEntryName.substring(servletClassPath.length()+1, classEntryName.length()); 105 String className = classEntryName.replace('/','.'); 106 Class servletClass = loadClass(result, className); 107 if (!Modifier.isAbstract(servletClass.getModifiers()) && 108 isImplementorOf(servletClass, "javax.servlet.Servlet")) { 109 foundOne=true; 110 Set servlets = descriptor.getServletDescriptors(); 112 boolean foundDD = false; 113 for (Iterator itr = servlets.iterator();itr.hasNext();) { 114 WebComponentDescriptor servlet = (WebComponentDescriptor)itr.next(); 115 String servletClassName = servlet.getWebComponentImplementation(); 116 if (servletClassName.equals(className)) { 117 foundDD=true; 118 break; 119 } 120 } 121 if (foundDD) { 122 result.addGoodDetails(smh.getLocalString 123 (getClass().getName() + ".passed", 124 "Servlet class [ {0} ] found in war file is defined in the Deployement Descriptors", 125 new Object [] {className})); 126 } else { 127 oneWarning=true; 128 result.addWarningDetails(smh.getLocalString 129 (getClass().getName() + ".warning", 130 "Servlet class [ {0} ] found in war file is not defined in the Deployement Descriptors", 131 new Object [] {className})); 132 } 133 } 134 } 135 } 136 } 137 if (!foundOne) { 138 result.notApplicable(smh.getLocalString 139 (getClass().getName() + ".notApplicable", 140 "There are no servlet implementation within the web archive [ {0} ]", 141 new Object [] {descriptor.getName()})); 142 } else { 143 if (oneWarning) { 144 result.setStatus(Result.WARNING); 145 } else { 146 result.setStatus(Result.PASSED); 147 } 148 } 149 return result; 150 } 151 } 152 | Popular Tags |