1.1 --- a/j2ee.sun.ws7/src/org/netbeans/modules/j2ee/sun/ws7/dm/WS70SunDeploymentManager.java Mon Aug 30 15:00:31 2010 +0530
1.2 +++ b/j2ee.sun.ws7/src/org/netbeans/modules/j2ee/sun/ws7/dm/WS70SunDeploymentManager.java Mon Aug 30 17:40:30 2010 +0530
1.3 @@ -185,38 +185,7 @@
1.4
1.5 // Get the instance location from wsenv file
1.6 public String getInstanceLocation(){
1.7 - String instanceLocation = new String();
1.8 - if(serverLocation!=null && serverLocation.length()!=0) {
1.9 - String wsenv = serverLocation + File.separator + "lib" + File.separator + "wsenv";
1.10 - boolean isWindows = false;
1.11 - File wsenvFile = new File(wsenv);
1.12 - if(!wsenvFile.exists()) {
1.13 - wsenv = serverLocation + File.separator + "lib" + File.separator + "wsenv.bat";
1.14 - isWindows = true;
1.15 - }
1.16 - instanceLocation = getInstanceRoot(wsenv, isWindows);
1.17 - }
1.18 - return instanceLocation;
1.19 - }
1.20 -
1.21 - public String getInstanceRoot(String wsenv, boolean isWindows){
1.22 - try{
1.23 - BufferedReader br = new BufferedReader(new FileReader(wsenv));
1.24 - String line = null;
1.25 - do {
1.26 - line = br.readLine();
1.27 - if(line.contains("WS_INSTANCEROOT=")) {
1.28 - if(isWindows) {
1.29 - return line.split("=")[1];
1.30 - } else {
1.31 - return line.substring(line.indexOf("=")+2, line.indexOf(";")-1);
1.32 - }
1.33 - }
1.34 - } while(line!=null);
1.35 - }catch(Exception e) {
1.36 - e.printStackTrace();
1.37 - }
1.38 - return "";
1.39 + return org.netbeans.modules.j2ee.sun.ws7.util.Util.getInstanceLocation(serverLocation);
1.40 }
1.41
1.42 public boolean isLocalServer(){
1.43 @@ -781,16 +750,7 @@
1.44
1.45
1.46 public boolean isRunning(){
1.47 - try {
1.48 - java.net.InetSocketAddress isa = new java.net.InetSocketAddress(java.net.InetAddress.getByName(host), port);
1.49 - java.net.Socket socket = new java.net.Socket();
1.50 - socket.connect(isa);
1.51 - socket.close();
1.52 - return true;
1.53 - } catch (IOException e) {
1.54 - return false;
1.55 - }
1.56 -
1.57 + return org.netbeans.modules.j2ee.sun.ws7.util.Util.isRunning(host, port);
1.58 }
1.59
1.60 public boolean isRunning(String configName){
2.1 --- a/j2ee.sun.ws7/src/org/netbeans/modules/j2ee/sun/ws7/j2ee/WS70J2eePlatformImpl.java Mon Aug 30 15:00:31 2010 +0530
2.2 +++ b/j2ee.sun.ws7/src/org/netbeans/modules/j2ee/sun/ws7/j2ee/WS70J2eePlatformImpl.java Mon Aug 30 17:40:30 2010 +0530
2.3 @@ -92,6 +92,7 @@
2.4 private static final String ACTIVATION = "activation.jar"; //NOI18N
2.5 private static final String JSF_IMPL = "jsf-impl.jar"; //NOI18N
2.6 private static final String JSF_API = "jsf-api.jar"; //NOI18N
2.7 + private static final String WEBSERV_RT_JAR = "webserv-rt.jar"; //NOI18N
2.8
2.9 private List libraries = new ArrayList();
2.10 private List classPathEntries = new ArrayList();
2.11 @@ -151,6 +152,7 @@
2.12 l.add(fileToUrl(new File(root, libJar(ACTIVATION))));
2.13 l.add(fileToUrl(new File(root, libJar(JSF_IMPL))));
2.14 l.add(fileToUrl(new File(root, libJar(JSF_API))));
2.15 + l.add(fileToUrl(new File(root, libJar(WEBSERV_RT_JAR))));
2.16 } else {
2.17 // In case of JES installation, parse the serverxml file to get the classpath jars
2.18 // Check these jars against listed jars (listJars()) before adding them to the library
2.19 @@ -188,7 +190,7 @@
2.20
2.21 // for JES installation
2.22 private String[] listJars() {
2.23 - String[] jars = { "jaxws-api.jar", "jaxws-rt.jar", "jaxws-tools.jar", "jsr181-api.jar", "jsr250-api.jar", "jaxb-api.jar", "jaxb-impl.jar", "jaxb-xjc.jar", "sjsxp.jar", "jsr173_api.jar", "saaj-api.jar", "saaj-impl.jar", "xmldsig.jar", "xmlsec.jar", "xws-security.jar", "xws-security_jaxrpc.jar", "wss-provider-update.jar", "security-plugin.jar", "FastInfoset.jar", "relaxngDatatype.jar", "resolver.jar", WS70_JAR, JSTL_JAR, MAIL_JAR, JAXRPC_API_JAR, JAXRPC_IMPL_JAR, JAXRPC_SPI_JAR, ACTIVATION, JSF_IMPL, JSF_API };
2.24 + String[] jars = { "jaxws-api.jar", "jaxws-rt.jar", "jaxws-tools.jar", "jsr181-api.jar", "jsr250-api.jar", "jaxb-api.jar", "jaxb-impl.jar", "jaxb-xjc.jar", "sjsxp.jar", "jsr173_api.jar", "saaj-api.jar", "saaj-impl.jar", "xmldsig.jar", "xmlsec.jar", "xws-security.jar", "xws-security_jaxrpc.jar", "wss-provider-update.jar", "security-plugin.jar", "FastInfoset.jar", "relaxngDatatype.jar", "resolver.jar", WS70_JAR, JSTL_JAR, MAIL_JAR, JAXRPC_API_JAR, JAXRPC_IMPL_JAR, JAXRPC_SPI_JAR, ACTIVATION, JSF_IMPL, JSF_API, WEBSERV_RT_JAR };
2.25
2.26 return jars;
2.27 }
2.28 @@ -300,7 +302,8 @@
2.29 new File(root, libJar(MAIL_JAR)),
2.30 new File(root, libJar(ACTIVATION)),
2.31 new File(root, libJar(JSF_IMPL)),
2.32 - new File(root, libJar(JSF_API))
2.33 + new File(root, libJar(JSF_API)),
2.34 + new File(root, libJar(WEBSERV_RT_JAR))
2.35 };
2.36 } else {
2.37 return (File[])classPathEntries.toArray();
3.1 --- a/j2ee.sun.ws7/src/org/netbeans/modules/j2ee/sun/ws7/ui/Bundle.properties Mon Aug 30 15:00:31 2010 +0530
3.2 +++ b/j2ee.sun.ws7/src/org/netbeans/modules/j2ee/sun/ws7/ui/Bundle.properties Mon Aug 30 17:40:30 2010 +0530
3.3 @@ -104,6 +104,7 @@
3.4 MSG_ENTER_HOSTNAME=Please enter Administration Host Name
3.5 MSG_ENTER_VALID_PORT=Please enter valid Administration Port Number
3.6 MSG_ENTER_USERNAME=Please enter User Name for the Oracle iPlanet Web Server 7.0 Administrator
3.7 +MSG_ADMIN_CONNECT_ERROR=<html>Unable to connect with the administration server. Please check if the server is up <br> and running and that the host and port provided are correct. </html>
3.8
3.9 MSG_Server_Instance_Added=Server instance "{0}" was added successfully.
3.10
4.1 --- a/j2ee.sun.ws7/src/org/netbeans/modules/j2ee/sun/ws7/ui/WS70AddServerChoiceVisualPanel.java Mon Aug 30 15:00:31 2010 +0530
4.2 +++ b/j2ee.sun.ws7/src/org/netbeans/modules/j2ee/sun/ws7/ui/WS70AddServerChoiceVisualPanel.java Mon Aug 30 17:40:30 2010 +0530
4.3 @@ -54,23 +54,28 @@
4.4 import java.util.ArrayList;
4.5 import java.util.List;
4.6 import java.util.Iterator;
4.7 +import java.lang.reflect.*;
4.8
4.9 import org.openide.util.NbBundle;
4.10 import org.openide.WizardDescriptor;
4.11 +import org.netbeans.modules.j2ee.sun.ws7.WS7LibsClassLoader;
4.12 +
4.13 /**
4.14 *
4.15 * @author Administrator
4.16 */
4.17 public class WS70AddServerChoiceVisualPanel extends javax.swing.JPanel {
4.18 private static final String LOCALHOST="localhost";//NOI18N
4.19 - private static final String SSL_PORT="8989";//NOI18N
4.20 - private static final String NON_SSL_PORT="8800";//NOI18N
4.21 + private static final String DEFAULT_SSL_PORT = "8989";
4.22 + private static final String DEFAULT_NON_SSL_PORT = "8800";
4.23 private String installDirName;
4.24 private String hostName=LOCALHOST;
4.25 - private String portNumber = SSL_PORT;
4.26 + private String portNumber= DEFAULT_SSL_PORT;
4.27 private String userName;
4.28 private String password;
4.29 private final List listeners = new ArrayList();
4.30 + private List<String> ssl_ports = new ArrayList<String>();
4.31 + private List<String> non_ssl_ports = new ArrayList<String>();
4.32
4.33 /**
4.34 * Creates new form WS70AddServerChoiceVisualPanel
4.35 @@ -92,7 +97,6 @@
4.36 public String getAdminPort(){
4.37 return jAdminPortTxt.getText().trim();
4.38 }
4.39 -
4.40
4.41 public String getServerLocation(){
4.42 return jLocationTxt.getText().trim();
4.43 @@ -103,8 +107,96 @@
4.44 public boolean isAdminOnSSL(){
4.45 return jCBSSLPort.isSelected();
4.46 }
4.47 +
4.48 + public void updatePortField() {
4.49 + String location = jLocationTxt.getText().trim();
4.50 + // To take care of JES installation also, get the instance location from wsenv file
4.51 + String instanceLocation = org.netbeans.modules.j2ee.sun.ws7.util.Util.getInstanceLocation(location);
4.52 + parseServerXml(instanceLocation);
4.53 + }
4.54 +
4.55 + // Use the java Reflexion to access the admin generated schema2beans classes especially Server class (which are part of webserv-rt.jar)
4.56 + // and then parse the server.xml to get the http-listeners
4.57 + public void parseServerXml(String location) {
4.58 + File serverXml = new File(location+File.separator+"admin-server"+File.separator+"config"+File.separator+"server.xml");
4.59 + try {
4.60 + WS7LibsClassLoader wscl = new WS7LibsClassLoader();
4.61 + wscl.addURL(new File(location + File.separator + "lib" + File.separator + "webserv-rt.jar"));
4.62 + Class serverCls = wscl.loadClass("com.sun.webserver.config.serverbeans.Server");
4.63 +
4.64 + // Call create graph method (on serverXml file) and getHttpListener method from the server class
4.65 + Method cgMth = serverCls.getMethod("createGraph", new Class[] {serverXml.getClass()});
4.66 + Method hlMth = serverCls.getMethod("getHttpListener", null);
4.67 +
4.68 + // Load HttpListenerType class and get the required methods
4.69 + Class hlCls = wscl.loadClass("com.sun.webserver.config.serverbeans.HttpListenerType");
4.70 + Method getPortMth = hlCls.getMethod("getPort", null);
4.71 + Method getSslMth = hlCls.getMethod("getSsl", null);
4.72 + Method isHLEnabledMth = hlCls.getMethod("isEnabled", null);
4.73 +
4.74 + // Load SslType class as getSsl method returns a SslType class, which will be used to invoke the getEnabled method
4.75 + Class sslTypeCls = wscl.loadClass("com.sun.webserver.config.serverbeans.SslType");
4.76 + Method isSSLEnabledMth = sslTypeCls.getMethod("getEnabled", new Class[] {Integer.TYPE});
4.77 +
4.78 + // Make sure that no previous ports exist
4.79 + ssl_ports.clear();
4.80 + non_ssl_ports.clear();
4.81 +
4.82 + Object createGraph = cgMth.invoke(serverCls, new Object[]{serverXml});
4.83 + Object[] httpListeners = (Object[]) hlMth.invoke(createGraph, null);
4.84 +
4.85 + // Iterate through all the http-listeners to separte ssl and non-ssl ports
4.86 + for(Object hl : httpListeners) {
4.87 + Object isHLEnabled = isHLEnabledMth.invoke(hl, null);
4.88 + if (!((Boolean)isHLEnabled))
4.89 + continue;
4.90 +
4.91 + Object port = getPortMth.invoke(hl, null);
4.92 + Object ssl = getSslMth.invoke(hl, null);
4.93 + Object isSSLEnabled = isSSLEnabledMth.invoke(ssl, new Object[] {new Integer(0)});
4.94 + if ((Boolean)isSSLEnabled) {
4.95 + ssl_ports.add(port.toString());
4.96 + } else {
4.97 + non_ssl_ports.add(port.toString());
4.98 + }
4.99 + }
4.100 +
4.101 + // Set the initial display based on the http-listener ports detected
4.102 + if (ssl_ports.size() > 0 || non_ssl_ports.size() > 0)
4.103 + setInitialDisplay();
4.104 + else
4.105 + setDefaultDisplay();
4.106 +
4.107 + } catch(Exception e) {
4.108 + System.out.println("Warning: HttpListener's port detection is failed, so setting the defaults");
4.109 + setDefaultDisplay();
4.110 + e.printStackTrace();
4.111 + }
4.112 +
4.113 + }
4.114 +
4.115 + // If only 1 port type is detected then SSL checkbox is disabled, while appropriately checked
4.116 + // If only 1 SSL, 1 non SSL, or 1 of both ssl and non SSL ports are detected then port field is disabled
4.117 + // If both port types (SSL and non SSL) are detected then SSL checkbox is enabled
4.118 + // If more than 1 port of the selected type (SSL or non SSL) is found then port field is enabled for that type
4.119 + private void setInitialDisplay() {
4.120 + List<String> ports = (ssl_ports.size() != 0) ? ssl_ports : non_ssl_ports;
4.121 + jAdminPortTxt.setText(ports.get(0));
4.122 + jAdminPortTxt.setEditable((ports.size() > 1));
4.123 + jCBSSLPort.setSelected((ssl_ports.size() != 0));
4.124 + jCBSSLPort.setEnabled((ssl_ports.size() > 0 && non_ssl_ports.size() > 0));
4.125 + }
4.126 +
4.127 + // In case of any failures just use this as a default display
4.128 + private void setDefaultDisplay() {
4.129 + jAdminPortTxt.setText(DEFAULT_SSL_PORT);
4.130 + jAdminPortTxt.setEditable(false);
4.131 + jCBSSLPort.setEnabled(false);
4.132 + jCBSSLPort.setSelected(true);
4.133 + }
4.134 +
4.135 public boolean isValid(WizardDescriptor wizard){
4.136 - if(!validateDirctory()){
4.137 + if (!validateDirectory()){
4.138 jLocationTxt.setFocusable(true);
4.139 wizard.putProperty(WS70ServerUIWizardIterator.PROP_ERROR_MESSAGE
4.140 , NbBundle.getBundle(WS70AddServerChoiceVisualPanel.class).getString("MSG_INVALID_SERVER_DIRECTORY"));
4.141 @@ -128,6 +220,13 @@
4.142 , NbBundle.getBundle(WS70AddServerChoiceVisualPanel.class).getString("MSG_ENTER_USERNAME"));
4.143 return false;
4.144 }
4.145 + // Remote host validation needs to be done only after validating admin host and admin port
4.146 + // Just show a warning message and proceed further even if validation fails
4.147 + if (!validateRemoteHost()) {
4.148 + wizard.putProperty(WS70ServerUIWizardIterator.PROP_ERROR_MESSAGE
4.149 + , NbBundle.getBundle(WS70AddServerChoiceVisualPanel.class).getString("MSG_ADMIN_CONNECT_ERROR"));
4.150 + return true;
4.151 + }
4.152 wizard.putProperty(WS70ServerUIWizardIterator.PROP_ERROR_MESSAGE, null);
4.153 return true;
4.154 }
4.155 @@ -150,6 +249,10 @@
4.156 if(port<=0 || port>65535){
4.157 return false;
4.158 }
4.159 +
4.160 + if (!jCBRemote.isSelected())
4.161 + return (jCBSSLPort.isSelected()) ? ssl_ports.contains(portNumber)
4.162 + : non_ssl_ports.contains(portNumber);
4.163 return true;
4.164 }
4.165 private boolean validateUserName(){
4.166 @@ -158,7 +261,15 @@
4.167 }
4.168 return true;
4.169 }
4.170 - private boolean validateDirctory() {
4.171 + private boolean validateRemoteHost() {
4.172 + if (jCBRemote.isSelected()) {
4.173 + String host = jAdminHostTxt.getText().trim();
4.174 + String port = jAdminPortTxt.getText().trim();
4.175 + return org.netbeans.modules.j2ee.sun.ws7.util.Util.isRunning(host, Integer.parseInt(port));
4.176 + }
4.177 + return true;
4.178 + }
4.179 + private boolean validateDirectory() {
4.180 if(installDirName==null){
4.181 return false;
4.182 }
4.183 @@ -281,6 +392,7 @@
4.184
4.185 jAdminHostTxt.setEditable(false);
4.186 jAdminHostTxt.setText(LOCALHOST);
4.187 +
4.188 jAdminHostTxt.addCaretListener(new javax.swing.event.CaretListener() {
4.189 public void caretUpdate(javax.swing.event.CaretEvent evt) {
4.190 jAdminHostTxtCaretUpdate(evt);
4.191 @@ -291,7 +403,9 @@
4.192 jAdminPortLbl.setLabelFor(jAdminPortTxt);
4.193 jAdminPortLbl.setText(bundle.getString("LBL_AddServerVisualPanelPort")); // NOI18N
4.194
4.195 - jAdminPortTxt.setText("8989");
4.196 + jAdminPortTxt.setEditable(false);
4.197 + jAdminPortTxt.setText(DEFAULT_SSL_PORT);
4.198 +
4.199 jAdminPortTxt.addCaretListener(new javax.swing.event.CaretListener() {
4.200 public void caretUpdate(javax.swing.event.CaretEvent evt) {
4.201 jAdminPortTxtCaretUpdate(evt);
4.202 @@ -341,6 +455,7 @@
4.203
4.204 jCBSSLPort.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ws7/ui/Bundle").getString("A11Y_SSL_Mnem").charAt(0));
4.205 jCBSSLPort.setSelected(true);
4.206 + jCBSSLPort.setEnabled(false);
4.207 jCBSSLPort.setText(bundle.getString("LBL_AddServerVisualPanelSSLPort")); // NOI18N
4.208 jCBSSLPort.setToolTipText(bundle.getString("Tooltip_AddServerVisualPanelSSLPort")); // NOI18N
4.209 jCBSSLPort.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
4.210 @@ -464,23 +579,32 @@
4.211 }// </editor-fold>//GEN-END:initComponents
4.212
4.213 private void jCBSSLPortItemStateChanged (java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jCBSSLPortItemStateChanged
4.214 - if (jCBSSLPort.isSelected()){
4.215 - if (jAdminPortTxt.getText().equals(NON_SSL_PORT))
4.216 - jAdminPortTxt.setText(SSL_PORT);
4.217 - }else {
4.218 - if (jAdminPortTxt.getText().equals (SSL_PORT))
4.219 - jAdminPortTxt.setText(NON_SSL_PORT);
4.220 + if (jCBRemote.isSelected()) {
4.221 + if (jCBSSLPort.isSelected())
4.222 + jAdminPortTxt.setText(DEFAULT_SSL_PORT);
4.223 + else
4.224 + jAdminPortTxt.setText(DEFAULT_NON_SSL_PORT);
4.225 + } else {
4.226 + List<String> ports = (jCBSSLPort.isSelected()) ? ssl_ports : non_ssl_ports;
4.227 + jAdminPortTxt.setEditable((ports.size() > 1));
4.228 + jAdminPortTxt.setText(ports.get(0));
4.229 }
4.230 }//GEN-LAST:event_jCBSSLPortItemStateChanged
4.231
4.232 private void jCBRemoteStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jCBRemoteStateChanged
4.233 - if(!jCBRemote.isSelected()){
4.234 + if (!jCBRemote.isSelected()) {
4.235 jAdminHostTxt.setText(LOCALHOST);
4.236 - jAdminHostTxt.setEditable(false);
4.237 - }else{
4.238 - if(!jAdminHostTxt.isEditable()){
4.239 - jAdminHostTxt.setEditable(true);
4.240 - }
4.241 + jAdminHostTxt.setEditable(false);
4.242 + if (validateDirectory())
4.243 + setInitialDisplay();
4.244 + else
4.245 + setDefaultDisplay();
4.246 + } else {
4.247 + jAdminHostTxt.setEditable(true);
4.248 + jAdminPortTxt.setText(DEFAULT_SSL_PORT);
4.249 + jAdminPortTxt.setEditable(true);
4.250 + jCBSSLPort.setEnabled(true);
4.251 + jCBSSLPort.setSelected(true);
4.252 }
4.253 }//GEN-LAST:event_jCBRemoteStateChanged
4.254
4.255 @@ -494,6 +618,13 @@
4.256 return;
4.257 }
4.258 installDirName = dirName;
4.259 +
4.260 + // If a valid webserver installation is detected then call the updatePortField method to parse the server.xml file
4.261 + // and then to update the admin port value, else fall back to the default display
4.262 + if (validateDirectory())
4.263 + updatePortField();
4.264 + else
4.265 + setDefaultDisplay();
4.266 fireChange();
4.267 }//GEN-LAST:event_jLocationTxtFocusLost
4.268
4.269 @@ -573,6 +704,13 @@
4.270 }
4.271 }
4.272 }
4.273 +
4.274 + // If a valid webserver installation is detected then call the updatePortField method to parse the server.xml file
4.275 + // and then to update the admin port value, else fall back to the default display
4.276 + if (validateDirectory())
4.277 + updatePortField();
4.278 + else
4.279 + setDefaultDisplay();
4.280 }//GEN-LAST:event_jBrowseBtnActionPerformed
4.281
4.282
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
5.2 +++ b/j2ee.sun.ws7/src/org/netbeans/modules/j2ee/sun/ws7/util/Util.java Mon Aug 30 17:40:30 2010 +0530
5.3 @@ -0,0 +1,102 @@
5.4 +/*
5.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
5.6 + *
5.7 + * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
5.8 + *
5.9 + * The contents of this file are subject to the terms of either the GNU
5.10 + * General Public License Version 2 only ("GPL") or the Common
5.11 + * Development and Distribution License("CDDL") (collectively, the
5.12 + * "License"). You may not use this file except in compliance with the
5.13 + * License. You can obtain a copy of the License at
5.14 + * http://www.netbeans.org/cddl-gplv2.html
5.15 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
5.16 + * specific language governing permissions and limitations under the
5.17 + * License. When distributing the software, include this License Header
5.18 + * Notice in each file and include the License file at
5.19 + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
5.20 + * particular file as subject to the "Classpath" exception as provided
5.21 + * by Sun in the GPL Version 2 section of the License file that
5.22 + * accompanied this code. If applicable, add the following below the
5.23 + * License Header, with the fields enclosed by brackets [] replaced by
5.24 + * your own identifying information:
5.25 + * "Portions Copyrighted [year] [name of copyright owner]"
5.26 + *
5.27 + * Contributor(s):
5.28 + *
5.29 + * The Original Software is NetBeans. The Initial Developer of the Original
5.30 + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
5.31 + * Microsystems, Inc. All Rights Reserved.
5.32 + *
5.33 + * If you wish your version of this file to be governed by only the CDDL
5.34 + * or only the GPL Version 2, indicate your decision by adding
5.35 + * "[Contributor] elects to include this software in this distribution
5.36 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
5.37 + * single choice of license, a recipient has the option to distribute
5.38 + * your version of this file under either the CDDL, the GPL Version 2 or
5.39 + * to extend the choice of license to its licensees as provided above.
5.40 + * However, if you add GPL Version 2 code and therefore, elected the GPL
5.41 + * Version 2 license, then the option applies only if the new code is
5.42 + * made subject to such option by the copyright holder.
5.43 + */
5.44 +
5.45 +package org.netbeans.modules.j2ee.sun.ws7.util;
5.46 +
5.47 +import java.io.File;
5.48 +import java.io.BufferedReader;
5.49 +import java.io.FileReader;
5.50 +import java.io.IOException;
5.51 +
5.52 +public class Util {
5.53 + // Get the instance location from wsenv file
5.54 + public static String getInstanceLocation(String serverLocation) {
5.55 + String instanceLocation = "";
5.56 +
5.57 + if(serverLocation!=null && serverLocation.trim().length()!=0) {
5.58 + String wsenvPath = serverLocation + File.separator + "lib" + File.separator + "wsenv";
5.59 +
5.60 + boolean isWindows = (File.separatorChar == '\\');
5.61 + if (isWindows)
5.62 + wsenvPath += ".bat";
5.63 +
5.64 + if(new File(wsenvPath).exists())
5.65 + instanceLocation = getInstanceRoot(wsenvPath, isWindows);
5.66 + }
5.67 +
5.68 + return instanceLocation;
5.69 + }
5.70 +
5.71 + public static String getInstanceRoot(String wsenvPath, boolean isWindows) {
5.72 + try {
5.73 + BufferedReader br = new BufferedReader(new FileReader(wsenvPath));
5.74 + String line = null;
5.75 + do {
5.76 + line = br.readLine();
5.77 + if (line.contains("WS_INSTANCEROOT=")) {
5.78 + if (isWindows) {
5.79 + return line.split("=")[1];
5.80 + } else {
5.81 + return line.substring(line.indexOf("=")+2, line.indexOf(";")-1);
5.82 + }
5.83 + }
5.84 + } while(line != null);
5.85 + } catch(Exception e) {
5.86 + e.printStackTrace();
5.87 + }
5.88 + return "";
5.89 + }
5.90 +
5.91 + public static boolean isRunning(String host, int port){
5.92 + try {
5.93 + java.net.InetSocketAddress isa = new java.net.InetSocketAddress(java.net.InetAddress.getByName(host), port);
5.94 + java.net.Socket socket = new java.net.Socket();
5.95 + socket.connect(isa);
5.96 + socket.close();
5.97 + return true;
5.98 + } catch (IOException e) {
5.99 + return false;
5.100 + }
5.101 +
5.102 + }
5.103 +
5.104 +}
5.105 +