Servlet Interface test.
Servlets must implement the javax.servlet.Servlet interface
either directly or indirectly through GenericServlet or HttpServlet
Result result = getInitializedResult();
ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
if (!descriptor.getServletDescriptors().isEmpty()) {
boolean oneFailed = false;
boolean notPassOrFail = true;
// get the servlets in this .war
Set servlets = descriptor.getServletDescriptors();
Iterator itr = servlets.iterator();
result = loadWarFile(descriptor);
// test the servlets in this .war
while (itr.hasNext()) {
WebComponentDescriptor servlet = (WebComponentDescriptor)itr.next();
String servletClassName = servlet.getWebComponentImplementation();
Class c = loadClass(result, servletClassName);
// if the class could not be loaded we dont want to fail
// , it will be caught by the ServletClass test anyway
if (c == null) {
continue;
}
if (isJAXRPCEndpoint(servlet)) {
result.addGoodDetails(smh.getLocalString
("tests.componentNameConstructor",
"For [ {0} ]",
new Object[] {compName.toString()}));
result.addGoodDetails(smh.getLocalString
(getClass().getName() + ".notApplicable1",
"Not Applicable since, Servlet [ {0} ] is a JAXRPC Endpoint.",
new Object[] {servletClassName}));
notPassOrFail = false;
}
else if (isImplementorOf(c, "javax.servlet.Servlet")) {
result.addGoodDetails(smh.getLocalString
("tests.componentNameConstructor",
"For [ {0} ]",
new Object[] {compName.toString()}));
result.addGoodDetails(smh.getLocalString
(getClass().getName() + ".passed",
"Servlet class [ {0} ] directly or indirectly implements javax.servlet.Servlet",
new Object[] {servletClassName}));
notPassOrFail = false;
} else {
oneFailed = true;
result.addErrorDetails(smh.getLocalString
("tests.componentNameConstructor",
"For [ {0} ]",
new Object[] {compName.toString()}));
result.addErrorDetails(smh.getLocalString
(getClass().getName() + ".failed",
"Error: Servlet class [ {0} ] does not directly or indirectly implement javax.servlet.Servlet",
new Object[] {servletClassName}));
notPassOrFail = false;
}
}
// this means classloader returned null for all servlets
if (notPassOrFail) {
result.addWarningDetails(smh.getLocalString
("tests.componentNameConstructor",
"For [ {0} ]", new Object[] {compName.toString()}));
result.warning(smh.getLocalString
(getClass().getName() + ".warning",
"Some servlet classes could not be loaded."));
}
else if (oneFailed) {
result.setStatus(Result.FAILED);
} else {
result.setStatus(Result.PASSED);
}
} else {
result.addNaDetails(smh.getLocalString
("tests.componentNameConstructor",
"For [ {0} ]",
new Object[] {compName.toString()}));
result.notApplicable(smh.getLocalString
(getClass().getName() + ".notApplicable",
"There are no servlet components within the web archive [ {0} ]",
new Object[] {descriptor.getName()}));
}
return result;