1 23 package com.sun.enterprise.tools.verifier.tests.webservices; 24 25 import com.sun.enterprise.deployment.WebServiceEndpoint; 26 import com.sun.enterprise.tools.verifier.Result; 27 import com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor; 28 import org.w3c.dom.Document ; 29 import org.w3c.dom.Element ; 30 import org.w3c.dom.Node ; 31 34 35 66 67 public class WSSchemaLocation extends WSTest implements WSCheck { 68 String myValue = null; 69 String [] reqSchemaLocation = 70 {"http://java.sun.com/xml/ns/j2ee http://www.ibm.com/webservices/xsd/j2ee_web_services_1_1.xsd", 71 "http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/javaee_web_services_1_2.xsd"}; 72 int i; 73 77 public Result check (WebServiceEndpoint descriptor) { 78 79 Result result = getInitializedResult(); 80 ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor(); 81 String [] reqSchemaLocationSub1 = 82 {"http://java.sun.com/xml/ns/j2ee", "http://java.sun.com/xml/ns/javaee"}; 83 String [] reqSchemaLocationSub2 = 84 {"http://www.ibm.com/webservices/xsd/j2ee_web_services_1_1.xsd", 85 "http://java.sun.com/xml/ns/javaee/javaee_web_services_1_2.xsd"}; 86 boolean rslt = false; 87 String schemaVersion = getVerifierContext().getSchemaVersion(); 88 Document wsdoc=getVerifierContext().getWebServiceDocument(); 89 if (wsdoc == null && schemaVersion.compareTo("1.1") > 0) { 91 addGoodDetails(result, compName); 92 result.passed(smh.getLocalString(getClass().getName() + ".passed1", 93 "Webservices deployment descriptor is not defined for this archive")); 94 return result; 95 } 96 97 try { 98 if (wsdoc.getDocumentElement().hasAttributes()) { 99 getNode(wsdoc); 100 if ( myValue != null) { 101 for(i=0; i<reqSchemaLocation.length; i++) { 102 rslt = verifySchema(myValue, reqSchemaLocation[i], 103 reqSchemaLocationSub1[i], reqSchemaLocationSub2[i]); 104 if(rslt) break; 105 } 106 } 107 } 108 if (rslt) { 109 result.addGoodDetails(smh.getLocalString ("tests.componentNameConstructor", 110 "For [ {0} ]", new Object [] {compName.toString()})); 111 result.passed(smh.getLocalString (getClass().getName() + ".passed", 112 "The schemaLocation in the webservices.xml file for [{0}] matches the schema file requirement", 113 new Object [] {compName.toString()})); 114 } 115 else { 116 result.addErrorDetails(smh.getLocalString ("tests.componentNameConstructor", 117 "For [ {0} ]", new Object [] {compName.toString()})); 118 result.failed(smh.getLocalString (getClass().getName() + ".failed", 119 "The schemaLocation in the webservices.xml file for [{0}] does not match the schema file requirement", 120 new Object [] {compName.toString()})); 121 } 122 }catch (Exception e) { 123 result.failed(smh.getLocalString 125 (getClass().getName() + ".failed", 126 "The schemaLocation in the webservices.xml file for [{0}] does not match the schema file requirement", 127 new Object [] {compName.toString()})); 128 result.addErrorDetails(smh.getLocalString 129 ("com.sun.enterprise.tools.verifier.tests.webservices.Error", 130 "Error: Unexpected error occurred [ {0} ]", 131 new Object [] {e.getMessage()})); 132 } 133 return result; 134 } 135 136 private boolean verifySchema(String nodeval, String reqSchemaLocation, 137 String reqSchemaLocationSub1, String reqSchemaLocationSub2){ 138 try { 139 int off1 = reqSchemaLocation.indexOf("http", reqSchemaLocationSub1.length()); 140 int off2 = nodeval.indexOf("http",reqSchemaLocationSub1.length()); 141 if ( checkSubString(nodeval, 0,0,reqSchemaLocationSub1.length()) 143 && checkSubString(nodeval, off1,off2,reqSchemaLocationSub2.length()) ) { 144 ; } 146 else { 147 return false; 149 } 150 151 if ( reqSchemaLocation.length() > nodeval.length()) 153 return false; 154 155 175 176 for ( int i = reqSchemaLocationSub1.length(); i < off2; i++) { 177 if ( !(Character.isWhitespace(nodeval.charAt(i))) ) { 178 return false; 179 } 180 } 181 182 }catch (Exception e) { 183 e.toString(); 184 e.printStackTrace(); 185 } 186 return true; 187 } 188 private boolean checkSubString(String str , int off1, int off2, int len) { 189 if (reqSchemaLocation[i].regionMatches(off1, str, off2, len)) { 190 return true; 191 } 192 return false; 193 } 194 195 public void getNode(Node node) { 196 197 String name = node.getNodeName(); 198 int myType = node.getNodeType(); 199 if ( ( myType == 1 ) & (name.equals("webservices") )) { 201 Element e = (Element )node; 202 myValue = e.getAttribute("xsi:schemaLocation"); 203 return; 204 } 205 if (node.hasChildNodes()) { 206 Node firstChild = node.getFirstChild(); 207 getNode(firstChild); 208 } 209 Node nextNode = node.getNextSibling(); 210 if (nextNode != null) getNode(nextNode); 211 return ; 212 } 213 } 214 215 | Popular Tags |