KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > verifier > tests > VirtualServerTest


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /**
25  * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
26  *
27  * Copyright 2001-2002 by iPlanet/Sun Microsystems, Inc.,
28  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
29  * All rights reserved.
30  */

31
32 package com.sun.enterprise.admin.verifier.tests;
33
34 /* Test case to check the validity of Virtual Server fields
35  * Author : srini@sun.com
36  */

37
38 import java.io.File JavaDoc;
39 import java.util.StringTokenizer JavaDoc;
40 import java.util.Vector JavaDoc;
41
42 // 8.0 XML Verifier
43
//import com.sun.enterprise.tools.verifier.Result;
44
import com.sun.enterprise.config.serverbeans.Server;
45 import com.sun.enterprise.config.serverbeans.*;
46 import com.sun.enterprise.config.serverbeans.Resources;
47 import com.sun.enterprise.config.serverbeans.Applications;
48 import com.sun.enterprise.config.ConfigContext;
49 import com.sun.enterprise.config.ConfigException;
50 import com.sun.enterprise.config.serverbeans.*;
51 import com.sun.enterprise.config.ConfigContextEvent;
52
53 import com.sun.enterprise.admin.verifier.*;
54 // Logging
55
import java.util.logging.Logger JavaDoc;
56 import java.util.logging.Level JavaDoc;
57 import com.sun.logging.LogDomains;
58
59
60
61 public class VirtualServerTest extends ServerXmlTest implements ServerCheck {
62     // Logging
63
static Logger JavaDoc _logger = LogDomains.getLogger(LogDomains.APPVERIFY_LOGGER);
64     
65     public VirtualServerTest() {
66     }
67  
68     // check method invoked by the command line verifier
69
public Result check(ConfigContext context) {
70             Result result;
71             result = super.getInitializedResult();
72             // 8.0 XML Verifier
73
/*try {
74                 Server server = (Server)context.getRootConfigBean();
75                 VirtualServerClass[] virtual = server.getHttpService().getVirtualServerClass();
76                 for(int i=0;i<virtual.length;i++) {
77                     VirtualServer[] vserver = virtual[i].getVirtualServer();
78                     for(int j=0;j<vserver.length;j++){
79                         // check the id Bug: 4711203
80                         int id;
81                         try {
82                             id = Integer.parseInt(vserver[j].getId().substring(0,1));
83                             if(id <= 9 )
84                                 result.failed("Virtual Server ID cannot start with a number");
85                         } catch(Exception e) {
86                         }
87                         // check Mime
88                         String str = vserver[j].getMime();
89                         if(str != null) {
90                             if(!isMimeAvailable(str,context))
91                                 result.failed("Mime type " + vserver[j].getMime() + " not available for virtual server " + virtual[i].getId());
92                         }
93                         // check ACL
94                         str = vserver[j].getAcls();
95                         if(str!=null) {
96                             // Bug 4711404
97                             if(str.equals(""))
98                                 result.failed("ACL cannot be null String for virtual server " + vserver[i].getId());
99                             Vector acls = tokens(str);
100                             for(int k=0;k<acls.size();k++) {
101                                 if(! isAclAvailable((String)acls.get(k), context))
102                                     // Bug 4711404
103                                     result.failed("Acl not available for virtual server " + vserver[i].getId());
104                             }
105                         }
106                         // check Httplisteners
107                         str = vserver[j].getHttpListeners();
108                         if(str!=null) {
109                             // Bug 4711404
110                             if(str.equals(""))
111                                 result.failed("Http Listeners cannot be null string for virtual server " + vserver[i].getId());
112                             Vector https = tokens(str);
113                             for(int k=0;k<https.size();k++) {
114                                 if(! isHttpListenerAvailable((String)https.get(i), context))
115                                         // Bug 4711404
116                                         result.failed("Http Listener not available for virtual server " + vserver[i].getId());
117                             }
118                         }
119                         // check config file
120                         String fileName = vserver[j].getConfigFile();
121                         if(!(fileName==null || fileName.equals("obj.conf"))) {
122                             File f = new File(fileName);
123                             if(!f.exists())
124                                 result.failed("Config File " + fileName + " does not exists for virtual server " + virtual[i].getId());
125                         }
126                     }
127                 }
128             } catch(Exception ex) {
129                 //<addition author="irfan@sun.com" [bug/rfe]-id="" >
130                 /*ex.printStackTrace();
131                 result.failed("Exception : " + ex.getMessage());*/

132                 /*_logger.log(Level.FINE, "serverxmlverifier.exception", ex);
133                 result.failed("Exception : " + ex.getMessage());
134                 //</addition>
135             }*/

136             return result;
137     }
138     
139     // check method called from the admin GUI and iasadmin
140
public Result check(ConfigContextEvent ccce) {
141         Result result = new Result();
142         Object JavaDoc value = ccce.getObject();
143         ConfigContext context = ccce.getConfigContext();
144         String JavaDoc beanName = ccce.getBeanName();
145         result.passed("Passed ***");
146
147         //BUG 4739891 BEGIN
148
String JavaDoc choice = ccce.getChoice();
149         if (choice.equals(StaticTest.DELETE)) {
150             /* No need to verify this element if it is being DELETEd from
151                the Config.
152              */

153             return result;
154         }
155         //BUG 4739891 END
156

157         if(beanName != null) {
158                     String JavaDoc name = ccce.getName();
159                     result = testSave(name, (String JavaDoc)value, context);
160                     return result;
161         }
162         VirtualServer virtual = (VirtualServer)value;
163         
164         // check if virtual server id is valid object name Bug : 4698687 : start
165
String JavaDoc id = virtual.getId();
166         if(StaticTest.checkObjectName(id, result))
167             result.passed("Valid Object Name");
168         else {
169             result.failed("Virtual Server ID Invalid ");
170             return result;
171         }
172         // End Bug : 4698687
173

174         boolean isNumber = false;
175         // check the id
176
for(int i=0; i<10;i++) {
177             if(virtual.getId().startsWith(String.valueOf(i)))
178                     isNumber = true;
179         }
180         if(isNumber)
181               result.failed("ID cannot start with a number");
182         // check the mime type
183
/*
184         if(!isMimeAvailable(virtual.getMime(),context))
185             result.failed("Mime id not available");
186 */

187         return result;
188     }
189     
190     public Result testSave(String JavaDoc name, String JavaDoc value, ConfigContext context) {
191         Result result = new Result();
192         result.passed("passed ****");
193         // check the config file
194
/*
195         if(name.equals(ServerTags.CONFIG_FILE)) {
196             if(value != null) {
197                 File f = new File(value);
198                 if(!f.exists())
199                     result.failed("Config File Does not exist");
200             }
201         }
202 */

203         // check the log file
204
if(name.equals(ServerTags.LOG_FILE)) {
205             if(value != null) {
206                 File JavaDoc f = new File JavaDoc(value);
207                 if(!f.exists())
208                     result.failed("Log File does not exist");
209             }
210         }
211 /*
212         // check the acls
213         if(name.equals(ServerTags.ACLS)){
214             if(value!=null) {
215                     Vector acls = tokens(value);
216                     for(int i=0;i<acls.size();i++) {
217                         if(! isAclAvailable((String)acls.get(i), context)) {
218                             result.failed("Acl not available");
219                             return result;
220                         }
221                     }
222             }
223         }
224 */

225         //check the httplisteners
226
if(name.equals(ServerTags.HTTP_LISTENERS)) {
227             if(value!=null) {
228                     Vector JavaDoc https = tokens(value);
229                     for(int i=0;i<https.size();i++) {
230                         if(! isHttpListenerAvailable((String JavaDoc)https.get(i), context)) {
231                                 result.failed("Http Listener not available");
232                                 return result;
233                         }
234                     }
235             }
236         }
237         return result;
238     }
239     
240     public boolean isMimeAvailable(String JavaDoc value, ConfigContext context) {
241 /*
242         try {
243              //Server server = (Server)context.getRootConfigBean();
244              Config config = StaticTest.getConfig(context);
245              if(config!=null) {
246                  Mime[] avlMime = config.getHttpService().getMime();
247                  for(int i=0;i<avlMime.length;i++){
248                      if(value.equals(avlMime[i].getId()))
249                             return true;
250                  }
251              }
252         }catch(Exception ex) {
253             //<addition author="irfan@sun.com" [bug/rfe]-id="" >
254             _logger.log(Level.FINE, "serverxmlverifier.exception", ex);
255             //</addition>
256         }
257 */

258         return false;
259     }
260     
261     public boolean isAclAvailable(String JavaDoc value, ConfigContext context) {
262 /*
263         try {
264             //Server server = (Server)context.getRootConfigBean();
265             Config config = StaticTest.getConfig(context);
266             if(config!=null) {
267                 Acl[] avlAcl = config.getHttpService().getAcl();
268                 for(int i=0;i<avlAcl.length;i++) {
269                     if(value.equals(avlAcl[i].getId()))
270                         return true;
271                 }
272             }
273         }catch(Exception ex) {
274             //<addition author="irfan@sun.com" [bug/rfe]-id="logging" >
275             _logger.log(Level.FINE, "serverxmlverifier.exception", ex);
276             //</addition>
277         }
278 */

279         return false;
280     }
281     
282     public boolean isHttpListenerAvailable(String JavaDoc value, ConfigContext context) {
283         try {
284             //Server server = (Server)context.getRootConfigBean();
285
Config config = StaticTest.getConfig(context);
286             if(config!=null) {
287                 HttpListener[] http = config.getHttpService().getHttpListener();
288                 for(int i=0;i<http.length;i++) {
289                     if(value.equals(http[i].getId()))
290                         return true;
291                 }
292             }
293         }catch(Exception JavaDoc ex) {
294             //<addition author="irfan@sun.com" [bug/rfe]-id="logging" >
295
/*e.printStackTrace();*/
296             _logger.log(Level.FINE, "serverxmlverifier.exception", ex);
297             //</addition>
298
}
299         return false;
300     }
301     
302     public Vector JavaDoc tokens(String JavaDoc value) {
303         StringTokenizer JavaDoc token = new StringTokenizer JavaDoc(value,",");
304         Vector JavaDoc test = new Vector JavaDoc();
305          while(token.hasMoreTokens())
306                     test.add(token.nextToken());
307         return test;
308     }
309 }
310
Popular Tags