1 23 24 31 32 package com.sun.enterprise.admin.verifier.tests; 33 34 37 38 import java.net.*; 39 import java.util.StringTokenizer ; 40 41 import com.sun.enterprise.config.serverbeans.Server; 44 import com.sun.enterprise.config.serverbeans.*; 45 import com.sun.enterprise.config.serverbeans.Resources; 46 import com.sun.enterprise.config.serverbeans.Applications; 47 import com.sun.enterprise.config.ConfigContext; 48 import com.sun.enterprise.config.ConfigException; 49 import com.sun.enterprise.config.serverbeans.*; 50 import com.sun.enterprise.config.ConfigContextEvent; 51 import com.sun.enterprise.admin.common.ObjectNames; 52 53 import com.sun.enterprise.admin.verifier.*; 54 55 import java.util.logging.Logger ; 57 import java.util.logging.Level ; 58 import com.sun.logging.LogDomains; 59 60 61 public class HttpListenerTest extends ServerXmlTest implements ServerCheck { 62 63 64 static Logger _logger = LogDomains.getLogger(LogDomains.APPVERIFY_LOGGER); 66 private static final String DELIMITER=","; 67 protected HttpListener thisListener; 69 71 public HttpListenerTest() { 72 } 73 74 public Result check(ConfigContext context) { 76 Result result; 77 result = super.getInitializedResult(); 78 117 return result; 118 } 119 120 public Result check(ConfigContextEvent ccce) { 122 Result result = new Result(); 124 Object value = ccce.getObject(); 126 ConfigContext context = ccce.getConfigContext(); 127 String beanName = ccce.getBeanName(); 129 if(beanName!=null) { 130 String name = ccce.getName(); 131 result = testSave(name, (String )value, context); 133 return result; 134 } 135 HttpListener http = (HttpListener)value; 136 thisListener = http; 138 if(ccce.getChoice().equals(StaticTest.DELETE)) 140 { 141 try { 142 Config config = StaticTest.getConfig(context); 143 if(config != null) { 144 HttpService service = config.getHttpService(); 145 VirtualServer[] vs = service.getVirtualServer(); 149 150 for (int i=0; vs != null && i < vs.length; i++) { 151 String httpListener = vs[i].getHttpListeners(); 152 if (httpListener != null) { 153 StringTokenizer st = new StringTokenizer (httpListener, DELIMITER); 154 StringBuffer newHttpListener = new StringBuffer (""); 155 String token = ""; 156 while (st.hasMoreTokens()) { 157 token = st.nextToken(); 158 if (token.equals(thisListener.getId())) { 159 result.failed("This listener is being referenced by some virtual server. Please remove the reference and try again."); 160 return result; 161 } 162 } 163 } 164 } result.passed("Test passed for referential integrity"); 166 } 167 } catch (Exception e) { 168 result.failed("Exception Caught : " + e.getMessage()); 169 } 170 return result; 171 } 172 String id = http.getId(); 174 if(StaticTest.checkObjectName(id, result)) 175 result.passed("Valid Object Name"); 176 else { 177 result.failed("Http Listener ID Invalid "); 178 return result; 179 } 180 182 try{ 183 if(StaticTest.isPortValid(Integer.parseInt(http.getPort()))) 184 result.passed("passed ***"); 185 else { 186 result.failed("Invalid Port Number"); 187 return result; 188 } 189 String port = http.getPort(); 190 197 if(ccce.getChoice().equals(StaticTest.ADD) && isPortUsed(port, context,result)) { 198 return result; 199 } 200 } 202 catch(NumberFormatException e){ 203 result.failed("Number Format Exception"); 204 return result; 205 } 206 String httpAddress = http.getAddress(); 207 try{ 208 if(httpAddress == null || httpAddress.equals("")) { 210 result.failed("Http Address cannot be Null value"); 211 return result; 212 } 213 if(StaticTest.checkAddress(httpAddress)) 214 InetAddress.getByName(httpAddress).getHostName(); 216 result.passed("Valid Http Listener IP Address"); 217 }catch(UnknownHostException e){ 218 result.failed("Host name not resolvable - " + httpAddress); 219 return result; 220 } 221 String virtualServer = http.getDefaultVirtualServer(); 222 try { 223 Config config = StaticTest.getConfig(context); 227 if( config!=null ) { 228 boolean exists = checkVSExists(virtualServer, config); 229 if(exists) 230 result.passed("Virtual Server found in vs class"); 231 else 232 result.failed("Virtual Server not found in vs class"); 233 } 234 }catch(Exception e){ 235 result.failed("Virtual Server specified not available "); 236 } 237 return result; 238 } 239 240 public Result testSave(String name, String value, ConfigContext context) { 241 Result result = new Result(); 242 result.passed("Passed "); 243 if(name.equals(ServerTags.ADDRESS)){ 244 try{ 245 if(value == null || value.equals("")) { 247 result.failed("Http Address cannot be Null"); 248 return result; 249 } 250 if(StaticTest.checkAddress(value)) 251 InetAddress.getByName(value).getHostName(); 253 result.passed("Valid Http Listener IP Address"); 254 }catch(UnknownHostException e){ 255 result.failed("Host name not resolvable - " + value); 256 } 257 } 258 if(name.equals(ServerTags.PORT)){ 259 try{ 260 if(StaticTest.isPortValid(Integer.parseInt(value))) 261 result.passed("passed ***"); 262 else 263 result.failed("Invalid Port Number"); 264 278 } 280 catch(NumberFormatException e){ 281 result.failed("Number Format Exception"); 282 } 283 } 284 return result; 285 } 286 287 296 private boolean checkVSExists(String vsID, Config config) { 297 VirtualServer vs = config.getHttpService().getVirtualServerById(vsID); 298 if(vs != null) 299 return true; 300 return false; 301 } 302 303 public boolean isPortUsed(String port, ConfigContext context, Result result) 306 { 307 result.passed("..."); 308 boolean flag = false; 309 try { 310 Config config = StaticTest.getConfig(context); 314 if(config!=null) { 315 HttpListener[] httpListener = config.getHttpService().getHttpListener(); 316 for(int i=0;i<httpListener.length;i++) { 317 if(!thisListener.getId().equals(httpListener[i].getId())) 318 { 319 if(port.equals(httpListener[i].getPort()) 320 && thisListener.getAddress().equals(httpListener[i].getAddress())) 321 { 322 flag=true; 323 result.failed("Port Already In Use by : " + httpListener[i].getId()); 324 break; 325 } 326 } 327 } 328 } 329 } catch(Exception e) { 330 result.failed("Exception Caught : " + e.getMessage()); 332 } 333 return flag; 334 } 335 336 } 337 | Popular Tags |