KickJava   Java API By Example, From Geeks To Geeks.

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


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 package com.sun.enterprise.admin.verifier.tests;
25
26 /**
27  * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
28  *
29  * Copyright 2001-2002 by iPlanet/Sun Microsystems, Inc.,
30  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
31  * All rights reserved.
32  */

33
34 import java.net.*;
35
36 /* Test Case to check the validity of IIOP listener fields
37  * Author : srini@sun.com
38  */

39
40 // 8.0 XML Verifier
41
//import com.sun.enterprise.tools.verifier.Result;
42
import com.sun.enterprise.config.serverbeans.Server;
43 import com.sun.enterprise.config.serverbeans.*;
44 import com.sun.enterprise.config.serverbeans.Resources;
45 import com.sun.enterprise.config.serverbeans.Applications;
46 import com.sun.enterprise.config.ConfigContext;
47 import com.sun.enterprise.config.ConfigContextEvent;
48 import com.sun.enterprise.config.ConfigException;
49 import com.sun.enterprise.config.serverbeans.*;
50
51 import com.sun.enterprise.admin.verifier.*;
52
53 // Logging
54
import java.util.logging.*;
55 import com.sun.logging.*;
56
57 public class IiopListenerTest extends ServerXmlTest implements ServerCheck {
58     
59      // Logging
60
static Logger _logger = LogDomains.getLogger(LogDomains.APPVERIFY_LOGGER);
61     
62     public IiopListenerTest() {
63     }
64
65     // check method called by command line verifier
66
public Result check(ConfigContext context)
67     {
68         Result result;
69         result = super.getInitializedResult();
70         // 8.0 XML Verifier
71
/*try {
72             Server server = (Server)context.getRootConfigBean();
73             IiopService service = server.getIiopService();
74             IiopListener[] listener = service.getIiopListener();
75             
76             // check how many listeners are enabled Bug : 4698687
77             int count=0;
78             for(int i=0;i<listener.length;i++) {
79                 if(listener[i].isEnabled())
80                     count++;
81             }*/

82             /*
83              * Fix comment: The following if check is totally spurious:
84              * 1. The message shows that Only 2 iiop lsnrs can be enabled and
85              * the condition checked is count >= 2. ?????
86              * 2. The exact restrictions (based on which the verifier works
87              * are not known and there is not enough time to test all
88              * that. Date : 08/14/02.
89             */

90             /*
91             if(count >= 2)
92                 result.failed("Only 2 Iiop Listeners can be enabled");
93                 */

94             /*for(int i=0; i < listener.length;i++){
95                 String hostIP = listener[i].getAddress();
96                 String hostPort = listener[i].getPort();
97                 try {
98                     if(!StaticTest.isPortValid(Integer.parseInt(hostPort)))
99                         result.failed("Invalid IIOP Listener Port - " + hostPort);
100                     else
101                         result.passed("valid IIOP Listener Port");
102                 } catch(NumberFormatException e) {
103                     result.failed("Port Number - " + hostPort + " : Invalid");
104                 }
105                 // Bug 4711404
106                 if(hostIP != null && hostIP.equals(""))
107                     result.failed("Host IP cannot be null String");
108                 try{
109                         InetAddress.getByName(hostIP).getHostName();
110                         result.passed("Valid IIOP Listener IP");
111                 }catch(UnknownHostException e){
112                     result.failed("Host name not resolvable - " + hostIP);
113                 }
114             }
115         }
116         catch(Exception ex) {
117             // Logging
118             _logger.log(Level.FINE, "serverxmlverifier.exception", ex);
119             result.failed("Exception : " + ex.getMessage());
120         }*/

121         return result;
122     }
123     
124     // check method called by adminGUI and iasadmin
125
public Result check(ConfigContextEvent ccce) {
126         Result result = new Result();
127         Object JavaDoc value = ccce.getObject();
128         String JavaDoc choice = ccce.getChoice();
129         ConfigContext context = ccce.getConfigContext();
130         String JavaDoc beanName = ccce.getBeanName();
131         if(beanName!=null)
132                 return testSave(ccce.getName(), ccce.getObject());
133         
134         IiopListener listener = (IiopListener)value;
135         
136         // check if IiopListener ID is valid object name Bug : 4698687 : start
137
String JavaDoc id = listener.getId();
138         if(StaticTest.checkObjectName(id, result))
139             result.passed("Valid Object Name");
140         else {
141             result.failed("IIOP Listener ID Invalid ");
142             return result;
143         }
144         // End Bug : 4698687
145

146         String JavaDoc hostIP = listener.getAddress();
147         String JavaDoc hostPort = listener.getPort();
148         
149         if(choice.equals("ADD")) {
150                 try {
151                     // 8.0 XML Verifier
152
//Server server = (Server)context.getRootConfigBean();
153
//IiopService service = server.getIiopService();
154
Config config = StaticTest.getConfig(context);
155                     if(config!=null) {
156                         IiopService service = config.getIiopService();
157                         IiopListener[] listeners = service.getIiopListener();
158                         // check how many listeners are enabled Bug : 4698687
159
int count=0;
160                         for(int i=0;i<listeners.length;i++) {
161                             if(listeners[i].isEnabled())
162                                 count++;
163                         }
164                         /*
165                          * Fix comment: The following if check is totally spurious:
166                          * 1. The message shows that Only 2 iiop lsnrs can be enabled and
167                          * the condition checked is count >= 2. ?????
168                          * 2. The exact restrictions (based on which the verifier works
169                          * are not known and there is not enough time to test all
170                          * that. Date : 08/14/02.
171                         */

172                         /*
173                         if(count >= 2) {
174                             result.failed("Only 2 Iiop Listeners can be enabled");
175                             return result;
176                         }
177                         */

178                     }
179                 } catch(Exception JavaDoc e) {
180                     result.failed("Exception occured " + e.getMessage());
181                 }
182         }
183         
184         try {
185             if(hostPort != null && !hostPort.equals("") ) {
186                 if(!StaticTest.isPortValid(Integer.parseInt(hostPort))) {
187                     result.failed("Invalid IIOP Listener Port - " + hostPort);
188                     // Return the result if port is invalid and do not do any further test.
189
return result;
190                 }
191                 else
192                     result.passed("valid IIOP Listener Port");
193             }
194         } catch(NumberFormatException JavaDoc e) {
195             result.failed("Port Number - " + hostPort + " : Invalid");
196             return result;
197         }
198         try{
199                 InetAddress.getByName(hostIP).getHostName();
200                 result.passed("Valid IIOP Listener IP");
201         }catch(UnknownHostException e){
202             result.failed("Host name not resolvable - " + hostIP);
203             return result;
204         }
205         return result;
206     }
207     
208     public Result testSave(String JavaDoc name, Object JavaDoc value) {
209            Result result = new Result();
210            result.passed("Passed **");
211            if(name.equals(ServerTags.ADDRESS)) {
212                try{
213                     InetAddress.getByName((String JavaDoc)value).getHostName();
214                     result.passed("Valid Http Listener IP Address");
215                }catch(UnknownHostException e){
216                     result.failed("Host name not resolvable - " + (String JavaDoc)value);
217                }
218            }
219            String JavaDoc hostPort = (String JavaDoc) value;
220            if(name.equals(ServerTags.PORT)){
221                 try {
222                    if(hostPort != null && !hostPort.equals("")) {
223                        if(!StaticTest.isPortValid(Integer.parseInt(hostPort))) {
224                             result.failed("Invalid IIOP Listener Port - " + hostPort);
225                        }
226                        else {
227                             result.passed("valid IIOP Listener Port");
228                        }
229                    }
230                 } catch(NumberFormatException JavaDoc e) {
231                     result.failed("Port Number - " + hostPort + " : Invalid");
232                 }
233            }
234            return result;
235     }
236 }
237
Popular Tags