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 javax.servlet.*; 29 import javax.servlet.http.*; 30 import com.sun.enterprise.deployment.*; 31 import com.sun.enterprise.tools.verifier.*; 32 import com.sun.enterprise.tools.verifier.tests.*; 33 34 39 public class ServletInterface extends WebTest implements WebCheck { 40 41 final String servletClassPath = "WEB-INF/classes"; 42 43 52 public Result check(WebBundleDescriptor descriptor) { 53 54 Result result = getInitializedResult(); 55 ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor(); 56 57 if (!descriptor.getServletDescriptors().isEmpty()) { 58 boolean oneFailed = false; 59 boolean notPassOrFail = true; 60 Set servlets = descriptor.getServletDescriptors(); 62 Iterator itr = servlets.iterator(); 63 64 result = loadWarFile(descriptor); 65 66 68 while (itr.hasNext()) { 69 WebComponentDescriptor servlet = (WebComponentDescriptor)itr.next(); 70 String servletClassName = servlet.getWebComponentImplementation(); 71 Class c = loadClass(result, servletClassName); 72 73 if (c == null) { 76 continue; 77 } 78 if (isJAXRPCEndpoint(servlet)) { 79 result.addGoodDetails(smh.getLocalString 80 ("tests.componentNameConstructor", 81 "For [ {0} ]", 82 new Object [] {compName.toString()})); 83 result.addGoodDetails(smh.getLocalString 84 (getClass().getName() + ".notApplicable1", 85 "Not Applicable since, Servlet [ {0} ] is a JAXRPC Endpoint.", 86 new Object [] {servletClassName})); 87 notPassOrFail = false; 88 } 89 else if (isImplementorOf(c, "javax.servlet.Servlet")) { 90 result.addGoodDetails(smh.getLocalString 91 ("tests.componentNameConstructor", 92 "For [ {0} ]", 93 new Object [] {compName.toString()})); 94 result.addGoodDetails(smh.getLocalString 95 (getClass().getName() + ".passed", 96 "Servlet class [ {0} ] directly or indirectly implements javax.servlet.Servlet", 97 new Object [] {servletClassName})); 98 notPassOrFail = false; 99 } else { 100 oneFailed = true; 101 result.addErrorDetails(smh.getLocalString 102 ("tests.componentNameConstructor", 103 "For [ {0} ]", 104 new Object [] {compName.toString()})); 105 result.addErrorDetails(smh.getLocalString 106 (getClass().getName() + ".failed", 107 "Error: Servlet class [ {0} ] does not directly or indirectly implement javax.servlet.Servlet", 108 new Object [] {servletClassName})); 109 notPassOrFail = false; 110 } 111 } 112 if (notPassOrFail) { 114 result.addWarningDetails(smh.getLocalString 115 ("tests.componentNameConstructor", 116 "For [ {0} ]", new Object [] {compName.toString()})); 117 result.warning(smh.getLocalString 118 (getClass().getName() + ".warning", 119 "Some servlet classes could not be loaded.")); 120 } 121 else if (oneFailed) { 122 result.setStatus(Result.FAILED); 123 } else { 124 result.setStatus(Result.PASSED); 125 } 126 } else { 127 result.addNaDetails(smh.getLocalString 128 ("tests.componentNameConstructor", 129 "For [ {0} ]", 130 new Object [] {compName.toString()})); 131 result.notApplicable(smh.getLocalString 132 (getClass().getName() + ".notApplicable", 133 "There are no servlet components within the web archive [ {0} ]", 134 new Object [] {descriptor.getName()})); 135 } 136 return result; 137 } 138 139 private boolean isJAXRPCEndpoint(WebComponentDescriptor servlet) { 140 141 String servletClassName = servlet.getWebComponentImplementation(); 142 143 if (servletClassName.equals(smh.getLocalString("JAXRPCServlet","com.sun.xml.rpc.server.http.JAXRPCServlet"))) { 144 return true; 146 } 147 148 WebBundleDescriptor descriptor = servlet.getWebBundleDescriptor(); 149 if (descriptor.hasWebServices()) { 150 WebServicesDescriptor wsdesc = descriptor.getWebServices(); 151 if (wsdesc.hasEndpointsImplementedBy(servlet)) { 152 return true; 153 } 154 } 155 return false; 156 } 157 158 } 159 | Popular Tags |