1 23 24 package com.sun.enterprise.tools.verifier.tests.webservices; 25 26 27 import com.sun.enterprise.tools.verifier.*; 28 import com.sun.enterprise.deployment.*; 29 import com.sun.enterprise.deployment.util.ModuleDescriptor; 30 31 import java.lang.ClassLoader ; 32 import com.sun.enterprise.tools.verifier.tests.*; 33 import com.sun.enterprise.util.io.FileUtils; 34 35 import java.lang.reflect.*; 36 37 import java.io.File ; 38 39 44 47 48 54 55 public abstract class WSTest extends VerifierTest implements VerifierCheck, WSCheck { 56 57 67 public Result check(Descriptor descriptor) { 68 return check((WebServiceEndpoint) descriptor); 69 } 70 71 78 public abstract Result check(WebServiceEndpoint descriptor); 79 80 89 protected Class loadSEIClass(WebServiceEndpoint descriptor, Result result) { 90 ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor(); 91 92 try { 93 Context context = getVerifierContext(); 94 ClassLoader jcl = context.getClassLoader(); 95 Class cl = Class.forName(descriptor.getServiceEndpointInterface(), false, getVerifierContext().getClassLoader()); 96 result.passed(smh.getLocalString ( 97 "com.sun.enterprise.tools.verifier.tests.webservices.clpassed", 98 "The [{0}] Class [{1}] exists and was loaded successfully.", 99 new Object [] {"SEI",descriptor.getServiceEndpointInterface()})); 100 return cl; 101 } catch (ClassNotFoundException e) { 102 Verifier.debug(e); 103 result.failed(smh.getLocalString 104 ("com.sun.enterprise.tools.verifier.tests.webservices.WSTest.SEIClassExists", 105 "Error: Service Endpoint Interface class [ {0} ] not found.", 106 new Object [] {descriptor.getServiceEndpointInterface()})); 107 return null; 108 } 109 } 110 111 120 protected Class loadImplBeanClass(WebServiceEndpoint descriptor, Result result) { 121 ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor(); 123 String beanClassName = null; 124 125 if (descriptor.implementedByEjbComponent()) { 126 beanClassName = descriptor.getEjbComponentImpl().getEjbClassName(); 127 } 128 else if (descriptor.implementedByWebComponent()) { 129 WebComponentDescriptor wcd = descriptor.getWebComponentImpl(); 130 if(wcd!=null) 131 beanClassName = wcd.getWebComponentImplementation(); 132 } 133 else { 134 result.addErrorDetails(smh.getLocalString 136 ("com.sun.enterprise.tools.verifier.tests.webservices.Error", 137 "Error: Unexpected error occurred [ {0} ]", 138 new Object [] {"The WebService is neither implemented by an EJB nor a Servlet"})); 139 } 140 if (beanClassName != null) { 141 try { 142 Context context = getVerifierContext(); 143 ClassLoader jcl = context.getClassLoader(); 144 return Class.forName(beanClassName, false, getVerifierContext().getClassLoader()); 145 } 146 catch (ClassNotFoundException e) { 147 Verifier.debug(e); 148 result.failed(smh.getLocalString 149 ("com.sun.enterprise.tools.verifier.tests.webservices.WSTest.BeanClassExists", 150 "Error: Service Endpoint Implementation Bean class [ {0} ] not found.", 151 new Object [] {beanClassName})); 152 return null; 153 } 154 } 155 result.addErrorDetails(smh.getLocalString 157 ("com.sun.enterprise.tools.verifier.tests.webservices.Error", 158 "Error: Unexpected error occurred [ {0} ]", 159 new Object [] {"The Servlet Impl Bean class name could not be resolved"})); 160 161 return null; 162 } 163 164 public boolean isSEIMethod (MethodDescriptor mdesc, EjbDescriptor desc, Class sei, ClassLoader cl) { 165 166 Method[] seiMeths = sei.getMethods(); 167 Method methToBeTested = null; 168 169 try { 170 methToBeTested = mdesc.getMethod(desc); 171 } catch(Exception e) { 172 179 return false; 180 } 181 182 for (int i=0; i < seiMeths.length; i++) { 183 if (WSTest.matchesSignatureAndReturn(seiMeths[i], methToBeTested)) 184 return true; 185 } 186 return false; 187 } 188 189 public static boolean matchesSignatureAndReturn (Method meth1, Method meth2) { 190 191 if (!(meth1.getName()).equals(meth2.getName())) 192 return false; 193 194 201 202 Class ret1 = meth1.getReturnType(); 203 Class ret2 = meth2.getReturnType(); 204 if (ret1 != ret2) 205 return false; 206 207 Class [] param1 = meth1.getParameterTypes(); 208 Class [] param2 = meth2.getParameterTypes(); 209 210 if(param1.length != param2.length) 211 return false; 212 213 for(int i = 0; i < param1.length; i++) 214 if(param1[i] != param2[i]) 215 return false; 216 217 218 Class [] excep1 = meth1.getExceptionTypes(); 221 Class [] excep2 = meth2.getExceptionTypes(); 222 223 for(int i = 0; i < excep2.length; i++) { 224 if(!isMatching(excep2[i], excep1)) 225 return false; 226 } 227 228 return true; 229 } 230 231 private static boolean isMatching(Class cl, Class [] classes) { 232 233 for (int i= 0; i < classes.length; i++) { 234 240 if (classes[i].equals(cl)) 241 return true; 242 } 243 return false; 244 } 245 246 protected String getAbstractArchiveUri(WebServiceEndpoint desc) { 247 String archBase = getVerifierContext().getAbstractArchive(). 248 getArchiveUri(); 249 final ModuleDescriptor moduleDescriptor = desc.getBundleDescriptor(). 250 getModuleDescriptor(); 251 if (moduleDescriptor.isStandalone()) { 252 return archBase; } else { 254 return archBase + File.separator + 255 FileUtils.makeFriendlyFileName(moduleDescriptor.getArchiveUri()); 256 } 257 } 258 259 } 260 | Popular Tags |