FileDocCategorySizeDatePackage
ServletInterface.javaAPI DocGlassfish v2 API7102Fri May 04 22:34:10 BST 2007com.sun.enterprise.tools.verifier.tests.web

ServletInterface

public class ServletInterface extends com.sun.enterprise.tools.verifier.tests.web.WebTest implements WebCheck
Servlet Interface test. Servlets must implement the javax.servlet.Servlet interface either directly or indirectly through GenericServlet or HttpServlet

Fields Summary
final String
servletClassPath
Constructors Summary
Methods Summary
public Resultcheck(WebBundleDescriptor descriptor)
Servlet Interface test. Servlets must implement the javax.servlet.Servlet interface either directly or indirectly through GenericServlet or HttpServlet

param
descriptor the Web deployment descriptor
return
Result the results for this assertion

      
                                            
        

	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;
    
private booleanisJAXRPCEndpoint(WebComponentDescriptor servlet)

  
     String servletClassName = servlet.getWebComponentImplementation();

     if (servletClassName.equals(smh.getLocalString("JAXRPCServlet","com.sun.xml.rpc.server.http.JAXRPCServlet"))) {
        // This is a standard JAXRPC servlet
        return true;
     }

     WebBundleDescriptor descriptor = servlet.getWebBundleDescriptor();
     if (descriptor.hasWebServices()) {
        WebServicesDescriptor wsdesc = descriptor.getWebServices();
        if (wsdesc.hasEndpointsImplementedBy(servlet)) {
           return true;
        }
     }
    return false;