0001: package com.sun.portal.sra.admin.mbeans;
0002:
0003: import java.io.BufferedReader;
0004: import java.io.File;
0005: import java.io.IOException;
0006: import java.io.InputStreamReader;
0007: import java.util.*;
0008: import java.util.logging.Level;
0009: import java.util.logging.Logger;
0010: import java.net.URL;
0011: import java.net.MalformedURLException;
0012:
0013: import com.sun.portal.admin.common.context.PSConfigContext;
0014: import com.sun.portal.admin.common.PSMBeanException;
0015: import com.sun.portal.fabric.util.FileUtil;
0016: import com.sun.portal.fabric.util.ExecuteUtil;
0017: import com.sun.portal.fabric.tasks.MonitoringConfigurationHelper;
0018: import com.sun.portal.log.common.PortalLogger;
0019: import com.sun.portal.log.common.PortalLogManager;
0020: import com.sun.portal.sra.admin.context.GWPropertyContext;
0021: import com.sun.portal.sra.admin.context.SRAFileContextImpl;
0022: import com.sun.portal.sra.admin.context.SRAPropertyContext;
0023: import com.sun.portal.sra.admin.util.OSDefaults;
0024: import com.sun.portal.sra.admin.util.SystemDefaults;
0025:
0026: /**
0027: * @version 1.0
0028: * @created 04-Mar-2005 9:58:13 PM
0029: * @author Sandeep Soni
0030: */
0031: public class Gateway extends SraServerImpl implements SraServer {
0032: private static final String _mainClass = "com.sun.portal.netlet.eproxy.EProxy";
0033:
0034: private String _classPath = new String();
0035:
0036: private String _instanceName = new String();
0037:
0038: private String _jvmProperties = new String();
0039:
0040: private Properties _platformConfProperties = new Properties();
0041:
0042: private HashMap _systemProperties = new HashMap();
0043:
0044: private static OSDefaults _osDefaults;
0045:
0046: private static String FS;
0047:
0048: public static final String COMPONENT_NAME = "gateway";
0049:
0050: public static final String ATTRIBUTE_GATEWAY_LISTS = "sunPortalGatewayGatewayHostsAndIPs";
0051:
0052: public static final String ATTRIBUTE_GATEWAY_HTTPS_PORT = "sunPortalGatewayEProxyHTTPSPort";
0053:
0054: public static final String ATTRIBUTE_GATEWAY_HTTP_PORT = "sunPortalGatewayEProxyHTTPPort";
0055:
0056: public static final String ATTRIBUTE_GATEWAY_ENABLE_HTTPS = "sunPortalGatewayEProxyEnableHTTPS";
0057:
0058: public static final String ATTRIBUTE_GATEWAY_ENABLE_HTTP = "sunPortalGatewayEProxyEnableHTTP";
0059:
0060: private static String loggerName = "debug.com.sun.portal.admin.mbeans";
0061:
0062: private ExecuteUtil execUtil = new ExecuteUtil();
0063:
0064: static {
0065: _osDefaults = SystemDefaults.getSystemDefaults();
0066: FS = _osDefaults.getValue("fs");
0067: }
0068: private static Logger logger = PortalLogger
0069: .getLogger(Gateway.class);
0070:
0071: protected Gateway(String instanceName, PSConfigContext cc) {
0072: this .cc = cc;
0073: _instanceName = instanceName;
0074: populateForNamedInstance();
0075: }
0076:
0077: protected Gateway(SRAPropertyContext pc, PSConfigContext cc) {
0078: super (pc, cc);
0079: }
0080:
0081: protected Gateway(PSConfigContext cc) {
0082: this .cc = cc;
0083: }
0084:
0085: private static boolean is_Windows() {
0086: return System.getProperty("os.name").indexOf("indows") != -1;
0087: }
0088:
0089: /**
0090: * @param configFileProperties
0091: * @return
0092: */
0093: public SraServer createInstance(Properties configFileProperties)
0094: throws PSMBeanException {
0095:
0096: pc = new GWPropertyContext(configFileProperties);
0097: fc = new SRAFileContextImpl(pc, cc);
0098: _instanceName = pc.getInstanceName();
0099: Boolean reCopy = (fc.existsGWInstance(pc.getInstanceName())
0100: .booleanValue()
0101: || fc.existsNLPInstance(pc.getInstanceName())
0102: .booleanValue() || fc.existsRWPInstance(
0103: pc.getInstanceName()).booleanValue()) ? Boolean.FALSE
0104: : Boolean.TRUE;
0105:
0106: if (fc.existsGWInstance(pc.getInstanceName()).booleanValue()) {
0107: // DebugContext.message("Gateway instance is already configured !");
0108: logger.info("PSSR_CSPS_ADM_MBEANS000");
0109: throw new PSMBeanException(
0110: "psadmin.error.sra.create.instanceExists");
0111: }
0112: if (CheckPort(pc.getHost(), pc.getPort(), 50) == Boolean.TRUE) {
0113: String token[] = { pc.getPort() };
0114: throw new PSMBeanException(
0115: "psadmin.error.sra.create.portAlreadyInUse", token);
0116: }
0117: copyFile(fc.getTemplatePlatformConfigurationFile(), fc
0118: .getInstancePlatformConfigurationFile(), reCopy);
0119: replaceTokens(fc.getInstancePlatformConfigurationFile());
0120: if (!pc.doCreateNewIdentitySDKInstance().booleanValue()) {
0121: String[][] appendNameValues = new String[][] {
0122: { "gateway.bindipaddress", pc.getIP() },
0123: { "gateway.sockretries", "3" } };
0124: try {
0125: addOrReplaceNameValues(fc
0126: .getInstancePlatformConfigurationFile(),
0127: appendNameValues);
0128: } catch (IOException e) {
0129: throw new PSMBeanException(
0130: "psadmin.error.sra.create.platformConfMissing");
0131: }
0132: } else {
0133: createIdentitySDKInstance();
0134: String[][] appendNameValues = new String[][] {
0135: { "gateway.bindipaddress", pc.getIP() },
0136: { "gateway.sockretries", "3" },
0137: { "portal.server.instance", pc.getInstanceName() } };
0138: try {
0139: addOrReplaceNameValues(fc
0140: .getInstancePlatformConfigurationFile(),
0141: appendNameValues);
0142: } catch (IOException e) {
0143: throw new PSMBeanException(
0144: "psadmin.error.sra.create.platformConfMissing");
0145: }
0146: }
0147: if (pc.doCreateSelfSignedCertificate().booleanValue()) {
0148: FileUtil.makeDir(fc.getInstanceCertificatesDirectory());
0149: if (createSelfSignedCertificate().booleanValue()) {
0150: createLoggingUserAuthenticationEntry();
0151: }
0152: }
0153: createInstanceSignature();
0154: //addServerInstanceInfoToProfile(COMPONENT_NAME, ATTRIBUTE_GATEWAY_LISTS);
0155: setAttribute(pc.getPortalHost(), pc.getInstanceName(),
0156: ATTRIBUTE_GATEWAY_LISTS, pc.getHost(), pc.getIP());
0157: pc.write(fc.getInstanceGWConfigurationPropertiesFile(), fc
0158: .getInstanceGWConfigurationPropertiesFile());
0159: String MonitoringFileName = cc.getPSConfigDir()
0160: + File.separator + pc.getInstanceName()
0161: + File.separator + "gateway" + File.separator
0162: + "monitoring.properties";
0163: File MonitoringFile = new File(MonitoringFileName);
0164: if (!MonitoringFile.exists()) {
0165: copyFile(cc.getPSBaseDir() + File.separator + "template"
0166: + File.separator + "sra" + File.separator
0167: + "monitoring.properties", MonitoringFileName,
0168: Boolean.FALSE);
0169: FileUtil.replaceTokenInFile(MonitoringFile,
0170: "%INSTANCE_CONFIG_DIR%", cc.getPSConfigDir() + FS
0171: + pc.getInstanceName() + FS + "gateway");
0172: MonitoringConfigurationHelper.configurePropertyFile(
0173: MonitoringFileName, pc.getHost(), cc);
0174: }
0175: populateForNamedInstance();
0176: if (is_Windows())
0177: createWindowsService();
0178: if (pc.doStartAfterInstall().booleanValue())
0179: start();
0180: return this ;
0181: }
0182:
0183: public boolean deleteInstance() throws PSMBeanException {
0184: boolean status = true;
0185: boolean deletePlatformConf = false;
0186: stop();
0187: FileUtil.deleteDir(cc.getPSConfigDir() + FS
0188: + pc.getInstanceName() + FS + "gateway");
0189: if (!fc.existsRWPInstance(pc.getInstanceName()).booleanValue()
0190: && !fc.existsNLPInstance(pc.getInstanceName())
0191: .booleanValue()) {
0192: deletePlatformConf = true;
0193: FileUtil.deleteDir(cc.getPSConfigDir() + FS
0194: + pc.getInstanceName());
0195: if (pc.doCreateNewIdentitySDKInstance().booleanValue()) {
0196: removeIdentitySDKInstance();
0197: }
0198: }
0199: PortalLogManager.deleteSRALoggersList(fc
0200: .getInstancePlatformConfigurationFile(), "gateway");
0201: removeInstanceSignature(deletePlatformConf);
0202: //deleteServerInstanceInfoFromProfile(COMPONENT_NAME, ATTRIBUTE_GATEWAY_LISTS);
0203: deleteAttribute(pc.getPortalHost(), pc.getInstanceName(),
0204: ATTRIBUTE_GATEWAY_LISTS, pc.getHost(), pc.getIP());
0205: if (is_Windows())
0206: deleteWindowsService();
0207: return status;
0208: }
0209:
0210: /*
0211: * (non-Javadoc)
0212: *
0213: * @see java.lang.Object#equals(java.lang.Object)
0214: */
0215: public boolean equals(Object obj) {
0216: boolean ret = false;
0217: if (obj instanceof Gateway) {
0218: Gateway g = (Gateway) obj;
0219: if (g.getInstanceName().equals(_instanceName))
0220: ret = true;
0221: }
0222: return ret;
0223: }
0224:
0225: public String getclassPath() {
0226: return new String(_classPath);
0227: }
0228:
0229: // create windows service
0230: private void createWindowsService() throws PSMBeanException {
0231: StringBuffer sb = new StringBuffer();
0232:
0233: String classPath = getclassPath();
0234: if (getclassPath() == null
0235: || classPath.trim().equalsIgnoreCase("")) {
0236: setClassPath(); // sets the default classPath for Gateway component
0237: classPath = getclassPath();
0238: }
0239: setJVMProperties();
0240:
0241: String command = cc.getPSBaseDir() + File.separator + "lib"
0242: + File.separator + "srasvc.exe";
0243: String DEFINES = " -Dgateway.profilename="
0244: + pc.getInstanceName();
0245: String extraLibs = fc.getExtraLibs(amc.getJDKPath());
0246: String libraryPath = cc.getPSBaseDir() + File.separator + "lib"
0247: + File.pathSeparator
0248: + fc.getCreateSelfSignedCertificateLibraryPath()
0249: + File.pathSeparator + extraLibs;
0250: libraryPath += File.pathSeparator
0251: + replaceBackSlash(System
0252: .getProperty("java.library.path"));
0253: String[] envp = new String[7];
0254:
0255: sb.append(DEFINES);
0256: sb.append(" ");
0257: sb.append("-classpath ");
0258: sb.append(classPath);
0259: sb.append(" ");
0260: sb.append(_jvmProperties);
0261: sb.append(" ");
0262: String HTTP_PROXY_SET = _platformConfProperties
0263: .getProperty("http.proxySet");
0264: String HTTP_PROXY_HOST = _platformConfProperties
0265: .getProperty("http.proxyHost");
0266: String HTTP_PROXY_PORT = _platformConfProperties
0267: .getProperty("http.proxyPort");
0268:
0269: Boolean useProxy = Boolean.FALSE;
0270: if (HTTP_PROXY_SET != null
0271: && !HTTP_PROXY_SET.trim().equalsIgnoreCase("")
0272: && HTTP_PROXY_SET.equalsIgnoreCase("true")) {
0273: useProxy = Boolean.TRUE;
0274: if (HTTP_PROXY_HOST != null
0275: && !HTTP_PROXY_HOST.trim().equalsIgnoreCase(""))
0276: useProxy = Boolean.FALSE;
0277: if (HTTP_PROXY_PORT != null
0278: && !HTTP_PROXY_PORT.trim().equalsIgnoreCase(""))
0279: useProxy = Boolean.FALSE;
0280: }
0281: String PROXY_DEFINES = "";
0282: if (useProxy == Boolean.FALSE) {
0283: // Verify if Portal Server is up
0284: if (CheckPortalInstance() == Boolean.FALSE) {
0285: // DebugContext.error("Portal Server Gateway cannot get started.
0286: // Portal Server has to start first.");
0287: logger.severe("PSSR_CSPS_ADM_MBEANS001");
0288: }
0289:
0290: } else
0291: PROXY_DEFINES = " -Dhttp.proxySet=" + HTTP_PROXY_SET
0292: + " -Dhttp.proxyHost=" + HTTP_PROXY_HOST
0293: + " -Dhttp.proxyPort=" + HTTP_PROXY_PORT;
0294:
0295: sb.append((PROXY_DEFINES + " " + _mainClass).trim());
0296: // DebugContext.message("Command = " + sb.toString());
0297: Object[] params2 = { sb.toString() };
0298: logger.log(Level.INFO, "PSSR_CSPS_ADM_MBEANS002", params2);
0299:
0300: envp[0] = "servicename=SRA.Gateway." + pc.getInstanceName();
0301: envp[1] = "serviceshowname=Portal SRA Gateway "
0302: + pc.getInstanceName() + " instance";
0303: envp[2] = "servicedesname=Sun Java System Portal SRA's Gateway "
0304: + pc.getInstanceName() + " instance";
0305: envp[3] = "javahome="
0306: + _platformConfProperties
0307: .getProperty("gateway.jdk.dir");
0308: envp[4] = "jvmoptions=" + sb.toString();
0309: envp[5] = "workingdirectory=" + cc.getPSConfigDir()
0310: + File.separator + pc.getInstanceName()
0311: + File.separator + "gateway";
0312: envp[6] = "prefixpath=" + libraryPath;
0313:
0314: try {
0315: String args[] = { "install" };
0316: execUtil.exec(command, args, envp);
0317: } catch (Exception e) {
0318: throw new PSMBeanException(e.toString());
0319: }
0320: }
0321:
0322: // delete windows service
0323: private void deleteWindowsService() throws PSMBeanException {
0324:
0325: String command = cc.getPSBaseDir() + File.separator + "lib"
0326: + File.separator + "srasvc.exe";
0327: try {
0328: String args[] = { "uninstall", "servicename",
0329: "SRA.Gateway." + pc.getInstanceName() };
0330: execUtil.exec(command, args);
0331: } catch (Exception e) {
0332: throw new PSMBeanException(e.toString());
0333: }
0334: }
0335:
0336: /**
0337: * @return
0338: */
0339: private String getExecCommand() {
0340: StringBuffer sb = new StringBuffer();
0341:
0342: String classPath = getclassPath();
0343: if (getclassPath() == null
0344: || classPath.trim().equalsIgnoreCase("")) {
0345: setClassPath(); // sets the default classPath for Gateway component
0346: classPath = getclassPath();
0347: }
0348: setJVMProperties();
0349:
0350: String command = _platformConfProperties
0351: .getProperty("gateway.jdk.dir")
0352: + FORWARD_SLASH + "bin" + FORWARD_SLASH + "java";
0353: String DEFINES = " -Dgateway.profilename="
0354: + pc.getInstanceName();
0355: sb.append(command);
0356: sb.append(DEFINES);
0357: sb.append(" ");
0358: sb.append("-classpath ");
0359: sb.append(classPath);
0360: sb.append(" ");
0361: sb.append(_jvmProperties);
0362: sb.append(" ");
0363: String HTTP_PROXY_SET = _platformConfProperties
0364: .getProperty("http.proxySet");
0365: String HTTP_PROXY_HOST = _platformConfProperties
0366: .getProperty("http.proxyHost");
0367: String HTTP_PROXY_PORT = _platformConfProperties
0368: .getProperty("http.proxyPort");
0369:
0370: Boolean useProxy = Boolean.FALSE;
0371: if (HTTP_PROXY_SET != null
0372: && !HTTP_PROXY_SET.trim().equalsIgnoreCase("")
0373: && HTTP_PROXY_SET.equalsIgnoreCase("true")) {
0374: useProxy = Boolean.TRUE;
0375: if (HTTP_PROXY_HOST != null
0376: && !HTTP_PROXY_HOST.trim().equalsIgnoreCase(""))
0377: useProxy = Boolean.FALSE;
0378: if (HTTP_PROXY_PORT != null
0379: && !HTTP_PROXY_PORT.trim().equalsIgnoreCase(""))
0380: useProxy = Boolean.FALSE;
0381: }
0382: String PROXY_DEFINES = "";
0383: if (useProxy == Boolean.FALSE) {
0384: // Verify if Portal Server is up
0385: if (CheckPortalInstance() == Boolean.FALSE) {
0386: // DebugContext.error("Portal Server Gateway cannot get started.
0387: // Portal Server has to start first.");
0388: logger.severe("PSSR_CSPS_ADM_MBEANS001");
0389: }
0390:
0391: } else
0392: PROXY_DEFINES = " -Dhttp.proxySet=" + HTTP_PROXY_SET
0393: + " -Dhttp.proxyHost=" + HTTP_PROXY_HOST
0394: + " -Dhttp.proxyPort=" + HTTP_PROXY_PORT;
0395:
0396: sb.append((PROXY_DEFINES + " " + _mainClass).trim());
0397: // DebugContext.message("Command = " + sb.toString());
0398: Object[] params2 = { sb.toString() };
0399: logger.log(Level.INFO, "PSSR_CSPS_ADM_MBEANS002", params2);
0400:
0401: return sb.toString();
0402: }
0403:
0404: /*
0405: * (non-Javadoc)
0406: *
0407: * @see com.sun.portal.sra.mbeans.SraServer#getInstanceName()
0408: */
0409: public String getInstanceName() {
0410: return new String(_instanceName);
0411: }
0412:
0413: public String getjvmProperties() {
0414: return new String(_jvmProperties);
0415: }
0416:
0417: public String getmainClass() {
0418: return new String(_mainClass);
0419: }
0420:
0421: /*
0422: * @see com.sun.portal.sra.mbeans.SraServerComponent#getPlatformConfProperties()
0423: */
0424: public Properties getPlatformConfProperties() {
0425: return (Properties) _platformConfProperties.clone();
0426: }
0427:
0428: public HashMap getSystemProperties() {
0429: return (HashMap) _systemProperties.clone();
0430: }
0431:
0432: /*
0433: * @see com.sun.portal.sra.mbeans.SraServerComponent#populateForNamedInstance(java.lang.String)
0434: */
0435: private void populateForNamedInstance() {
0436: try {
0437: String instancePropertiesFile = cc.getPSConfigDir()
0438: + SRAFileContextImpl.fs + "GWConfig-"
0439: + _instanceName + ".properties";
0440: pc = new GWPropertyContext(load(instancePropertiesFile));
0441: fc = new SRAFileContextImpl(pc, cc);
0442: _platformConfProperties = load(fc
0443: .getInstancePlatformConfigurationFile());
0444: _jvmProperties = _platformConfProperties
0445: .getProperty("gateway.jvm.flags");
0446: _classPath = _platformConfProperties
0447: .getProperty("gateway.jvm.classpath");
0448: try {
0449: amc = fc.getAMPropertyContext();
0450: } catch (Exception e) {
0451: // DebugContext.error("Error in getting AMConfig.properties");
0452: logger.severe("PSSR_CSPS_ADM_MBEANS003");
0453: }
0454: } catch (IOException ioe) {
0455: // DebugContext.message("Error in populating the gateway
0456: // instance!");
0457: logger.info("PSSR_CSPS_ADM_MBEANS004");
0458: }
0459: setJVMProperties();
0460: setSystemProperties();
0461: setClassPath();
0462: }
0463:
0464: /**
0465: *
0466: */
0467: private void setClassPath() {
0468: _classPath = _platformConfProperties
0469: .getProperty("gateway.jvm.classpath");
0470: String IDSAME_CONFIG_DIR = cc.getISConfigDir();
0471: String IS_HOME = cc.getISBaseDir();
0472:
0473: String IS_CLASSPATH = IDSAME_CONFIG_DIR + File.pathSeparator;
0474: IS_CLASSPATH = IS_CLASSPATH + IS_HOME + fs + "lib"
0475: + File.pathSeparator;
0476: IS_CLASSPATH = IS_CLASSPATH + IS_HOME + fs + "locale"
0477: + File.pathSeparator;
0478: IS_CLASSPATH = IS_CLASSPATH + IS_HOME + fs + "lib" + fs
0479: + "am_sdk.jar" + File.pathSeparator;
0480: IS_CLASSPATH = IS_CLASSPATH + IS_HOME + fs + "lib" + fs
0481: + "am_services.jar" + File.pathSeparator;
0482: IS_CLASSPATH = IS_CLASSPATH + IS_HOME + fs + "lib" + fs
0483: + "am_logging.jar" + File.pathSeparator;
0484: IS_CLASSPATH = IS_CLASSPATH + IS_HOME + fs + "lib" + fs
0485: + "servlet.jar" + File.pathSeparator;
0486:
0487: String JCE_CLASSPATH = IS_HOME + fs + "lib" + fs
0488: + "jce1_2_1.jar" + File.pathSeparator;
0489: JCE_CLASSPATH = JCE_CLASSPATH + IS_HOME + fs + "lib" + fs
0490: + "local_policy.jar" + File.pathSeparator;
0491: JCE_CLASSPATH = JCE_CLASSPATH + IS_HOME + fs + "lib" + fs
0492: + "US_export_policy.jar" + File.pathSeparator;
0493: JCE_CLASSPATH = JCE_CLASSPATH + IS_HOME + fs + "lib" + fs
0494: + "sunjce_provider.jar" + File.pathSeparator;
0495:
0496: String PS_HOME = cc.getPSBaseDir();
0497: String GW_CLASSPATH = PS_HOME + fs + "lib" + File.pathSeparator;
0498: GW_CLASSPATH = GW_CLASSPATH + PS_HOME + fs + "locale"
0499: + File.pathSeparator;
0500: GW_CLASSPATH = GW_CLASSPATH + PS_HOME + fs + "lib" + fs
0501: + "gateway.jar" + File.pathSeparator;
0502: GW_CLASSPATH = GW_CLASSPATH + PS_HOME + fs + "lib" + fs
0503: + "ps_util.jar" + File.pathSeparator;
0504: GW_CLASSPATH = GW_CLASSPATH + PS_HOME + fs + "lib" + fs
0505: + "rwportal.jar" + File.pathSeparator;
0506: GW_CLASSPATH = GW_CLASSPATH + PS_HOME + fs + "lib" + fs
0507: + "certadmin.jar" + File.pathSeparator;
0508: GW_CLASSPATH = GW_CLASSPATH + PS_HOME + fs + "lib" + fs
0509: + "js.jar" + File.pathSeparator;
0510:
0511: String RW_JAR = PS_HOME + fs + "lib" + fs + "rewriter.jar"
0512: + File.pathSeparator;
0513:
0514: String JDMK_LIB_DIR = fc.getJdmkLibLocation();
0515: String MONITORING_JAR = PS_HOME + fs + "lib" + fs
0516: + "monitoring.jar" + File.pathSeparator;
0517: MONITORING_JAR = MONITORING_JAR + JDMK_LIB_DIR + fs + "jmx.jar"
0518: + File.pathSeparator;
0519: MONITORING_JAR = MONITORING_JAR + PS_HOME + fs + "lib" + fs
0520: + "javax77.jar" + File.pathSeparator;
0521: MONITORING_JAR = MONITORING_JAR + JDMK_LIB_DIR + fs
0522: + "jdmkrt.jar" + File.pathSeparator;
0523: MONITORING_JAR = MONITORING_JAR + JDMK_LIB_DIR + fs
0524: + "jmxremote.jar" + File.pathSeparator;
0525: MONITORING_JAR = MONITORING_JAR + JDMK_LIB_DIR + fs
0526: + "jmxremote_optional.jar" + File.pathSeparator;
0527: MONITORING_JAR = MONITORING_JAR + JDMK_LIB_DIR + fs
0528: + "sunsasl.jar" + File.pathSeparator;
0529: MONITORING_JAR = MONITORING_JAR + JDMK_LIB_DIR + fs
0530: + "sasl.jar" + File.pathSeparator;
0531:
0532: String LOGGING_CLASSPATH = PS_HOME + fs + "lib" + fs
0533: + "pslogcommon.jar" + File.pathSeparator;
0534: String JSS_JAR = fc.getJSSJARDir() + fs + "jss4.jar"
0535: + File.pathSeparator + fc.getJSSJARFile()
0536: + File.pathSeparator;
0537: GW_CLASSPATH = IS_CLASSPATH + JCE_CLASSPATH + JSS_JAR + RW_JAR
0538: + LOGGING_CLASSPATH + MONITORING_JAR + GW_CLASSPATH;
0539: if (_classPath != null)
0540: _classPath += File.pathSeparator + GW_CLASSPATH;
0541: else
0542: _classPath = GW_CLASSPATH;
0543: }
0544:
0545: /**
0546: *
0547: */
0548: private void setJVMProperties() {
0549: _jvmProperties = _platformConfProperties
0550: .getProperty("gateway.jvm.flags");
0551: if (_jvmProperties == null
0552: || _jvmProperties.trim().equalsIgnoreCase("")) {
0553: _jvmProperties = "-ms64m ";
0554: _jvmProperties += "-mx128m ";
0555: }
0556: String IS_HOME = cc.getISBaseDir();
0557:
0558: String DEFINES1 = "-Dsun.net.inetaddr.ttl=0 -Djava.protocol.handler.pkgs=com.iplanet.services.comm";
0559: Properties instancePlatformConfigProperties;
0560: try {
0561: instancePlatformConfigProperties = load(fc
0562: .getInstancePlatformConfigurationFile());
0563: } catch (IOException ioe) {
0564: // DebugContext.error("Error reading instance properties file!!");
0565: logger.severe("PSSR_CSPS_ADM_MBEANS005");
0566: return;
0567: }
0568: String gatewayNotificationUrl = instancePlatformConfigProperties
0569: .getProperty("gateway.notification.url");
0570: String amNotificationUrl = instancePlatformConfigProperties
0571: .getProperty("gateway.protocol")
0572: + "://"
0573: + instancePlatformConfigProperties
0574: .getProperty("gateway.host")
0575: + ":"
0576: + instancePlatformConfigProperties
0577: .getProperty("gateway.port")
0578: + FS
0579: + gatewayNotificationUrl;
0580:
0581: List notificationUrlList = getNotificationURL(
0582: gatewayNotificationUrl, amNotificationUrl,
0583: instancePlatformConfigProperties);
0584: if (notificationUrlList != null) {
0585: gatewayNotificationUrl = (String) notificationUrlList
0586: .get(0);
0587: amNotificationUrl = (String) notificationUrlList.get(1);
0588: }
0589:
0590: String DIRECTORY_CERT_DB = instancePlatformConfigProperties
0591: .getProperty("gateway.certdir");
0592: String FILE_CERT_DB_PASSWORD = DIRECTORY_CERT_DB + fs
0593: + ".jsspass";
0594: String FILE_CERT_NICKNAME = DIRECTORY_CERT_DB + fs
0595: + ".nickname";
0596:
0597: String DEFINES2 = "-Dcom.iplanet.am.notification.url="
0598: + amNotificationUrl + " -Dgateway.notification.url="
0599: + gatewayNotificationUrl;
0600: String DEFINES3 = "-Dgateway.keybase=" + DIRECTORY_CERT_DB
0601: + " -Dgateway.pass=" + FILE_CERT_DB_PASSWORD
0602: + " -Dgateway.nickname=" + FILE_CERT_NICKNAME;
0603: String DEFINES4 = "-DLOG_COMPATMODE=Off -Djava.util.logging.config.file="
0604: + IS_HOME
0605: + fs
0606: + "lib"
0607: + fs
0608: + "LogConfig.properties"
0609: + " -Dcom.sun.portal.log.config.file="
0610: + fc.getInstancePlatformConfigurationFile();
0611: /*DEFINES4 = DEFINES4 + " -Dcom.sun.portal.monitoring.MonitoringContext.configuration.directory=" + cc.getPSConfigDir() + fs
0612: + pc.getInstanceName() + fs + "gateway";*/
0613: String DEFINES5 = "-Dconf.suffix=" + pc.getInstanceName();
0614:
0615: String IS_CONFIG_NAME = instancePlatformConfigProperties
0616: .getProperty("portal.server.instance");
0617: if (IS_CONFIG_NAME != null
0618: && !IS_CONFIG_NAME.trim().equalsIgnoreCase("")) {
0619: DEFINES5 = DEFINES5 + " -Dserver.name=" + IS_CONFIG_NAME;
0620: }
0621:
0622: StringBuffer sb = new StringBuffer();
0623: sb.append(DEFINES1);
0624: sb.append(" ");
0625: sb.append(DEFINES2);
0626: sb.append(" ");
0627: sb.append(DEFINES3);
0628: sb.append(" ");
0629: sb.append(DEFINES4);
0630: sb.append(" ");
0631: sb.append(DEFINES5);
0632: sb.append(" ");
0633: sb.append("-DSRAP_CONFIG_DIR=" + cc.getPSConfigDir());
0634:
0635: if (_jvmProperties != null) {
0636: _jvmProperties += " ";
0637: _jvmProperties += sb.toString();
0638: } else
0639: _jvmProperties = sb.toString();
0640: // set _jvmProperties to a valid String of jvm properties
0641:
0642: }
0643:
0644: /**
0645: *
0646: */
0647: private void setSystemProperties() {
0648: // set _systemProperties to a valid hashmap containg the system
0649: // properties
0650: }
0651:
0652: public boolean start() throws PSMBeanException {
0653: boolean retCode = true;
0654: if (_instanceName.length() > 0) {
0655: String command = getExecCommand();
0656: String extraLibs = fc.getExtraLibs(amc.getJDKPath());
0657: String libraryPath = fc
0658: .getCreateSelfSignedCertificateLibraryPath()
0659: + File.pathSeparator + extraLibs;
0660: libraryPath += File.pathSeparator
0661: + replaceBackSlash(System
0662: .getProperty("java.library.path"));
0663: String[] envp = new String[2];
0664: envp[0] = "LD_LIBRARY_PATH=" + libraryPath;
0665: envp[1] = "SHLIB_PATH=" + libraryPath;
0666: boolean isHttps = isHttpsEnabled();
0667: boolean isHttp = isHttpEnabled();
0668: String httpPort = getHttpPort();
0669: String httpsPort = getHttpsPort();
0670: String instance = pc.getInstanceName();
0671: String pid = getInstancePID(instance);
0672: if (!pid.trim().equalsIgnoreCase("")) {
0673: logger.severe("PSSR_CSPS_ADM_MBEANS006");
0674: String token[] = { instance };
0675: throw new PSMBeanException(
0676: "psadmin.error.sra.start.instanceAlreadyRunning",
0677: token);
0678: } else if (isHttps
0679: && CheckPort(pc.getHost(), httpsPort, 50) == Boolean.TRUE) {
0680: String token[] = { "gateway", httpsPort };
0681: throw new PSMBeanException(
0682: "psadmin.error.sra.start.portAlreadyInUse",
0683: token);
0684: } else if (!isHttps
0685: && isHttp
0686: && CheckPort(pc.getHost(), httpPort, 50) == Boolean.TRUE) {
0687: String token[] = { "gateway", httpPort };
0688: throw new PSMBeanException(
0689: "psadmin.error.sra.start.portAlreadyInUse",
0690: token);
0691: } else {
0692: if (!is_Windows())
0693: command = command.trim() + " &";
0694: else {
0695: command = "net";
0696: String[] args = {
0697: "start",
0698: "\"SRA.Gateway." + pc.getInstanceName()
0699: + "\"" };
0700: try {
0701: execUtil.exec(command, args);
0702: Thread.sleep(10000L);
0703: } catch (Exception e) {
0704: logger.severe("PSSR_CSPS_ADM_MBEANS011");
0705: String token[] = { instance, "gateway" };
0706: throw new PSMBeanException(
0707: "psadmin.error.sra.start.instance",
0708: token);
0709: }
0710: }
0711: Object[] params2 = { "export " + envp[0] + ";"
0712: + command };
0713: logger.log(Level.INFO, "PSSR_CSPS_ADM_MBEANS002",
0714: params2);
0715: // DebugContext.message(command);
0716: logger.info("PSSR_CSPS_ADM_MBEANS007");
0717:
0718: try {
0719: if (!is_Windows()) {
0720: Runtime.getRuntime().exec(command, envp);
0721: Thread.sleep(10000L);
0722: }
0723: } catch (Exception e) {
0724: logger.severe("PSSR_CSPS_ADM_MBEANS011");
0725: String token[] = { instance, "gateway" };
0726: throw new PSMBeanException(
0727: "psadmin.error.sra.start.instance", token);
0728: }
0729:
0730: // createFile(instance, getInstancePID(instance));
0731: // checking whether the process is up and running...
0732: /*if (CheckPort(pc.getHost(), pc.getPort(), 50) == Boolean.TRUE) {
0733: pid = getInstancePID(pc.getInstanceName());
0734: if (pid.trim().equalsIgnoreCase("")) {
0735: String token[] = {"gateway", pc.getPort()};
0736: throw new PSMBeanException("psadmin.error.sra.start.portAlreadyInUse",token);
0737: }
0738: // DebugContext.message("Gateway started successfully
0739: // .");
0740: logger.info("PSSR_CSPS_ADM_MBEANS008");
0741: } */
0742: if (isHttps
0743: && CheckPort(pc.getHost(), httpsPort, 50) == Boolean.TRUE) {
0744: pid = getInstancePID(pc.getInstanceName());
0745: if (pid.trim().equalsIgnoreCase("")) {
0746: String token[] = { "gateway", httpsPort };
0747: throw new PSMBeanException(
0748: "psadmin.error.sra.start.portAlreadyInUse",
0749: token);
0750: }
0751: } else if (!isHttps
0752: && isHttp
0753: && CheckPort(pc.getHost(), httpPort, 50) == Boolean.TRUE) {
0754: pid = getInstancePID(pc.getInstanceName());
0755: if (pid.trim().equalsIgnoreCase("")) {
0756: String token[] = { "gateway", httpPort };
0757: throw new PSMBeanException(
0758: "psadmin.error.sra.start.portAlreadyInUse",
0759: token);
0760: }
0761: } else {
0762: // DebugContext.message("Gateway failed to start due to
0763: // some internal errors .");
0764: logger.info("PSSR_CSPS_ADM_MBEANS009");
0765: pid = getInstancePID(pc.getInstanceName());
0766: if (!pid.trim().equalsIgnoreCase("")) {
0767: String token[] = { "gateway", pid };
0768: throw new PSMBeanException(
0769: "psadmin.error.sra.start.instanceRunningButNotListening",
0770: token);
0771: }
0772: return false;
0773: }
0774: }
0775: }
0776: return retCode;
0777: }
0778:
0779: public boolean stop() throws PSMBeanException {
0780: boolean retCode = true;
0781: if (_instanceName.length() > 0) {
0782: // Execute the command here.to stop the instance
0783: String pid = getInstancePID(pc.getInstanceName());
0784: if (!pid.equalsIgnoreCase("")) {
0785: String command = _osDefaults.getValue("kill") + " -9 "
0786: + pid;
0787: try {
0788: int exitValue = 0;
0789: if (is_Windows()) {
0790: command = "net";
0791: String args[] = {
0792: "stop",
0793: "\"SRA.Gateway." + pc.getInstanceName()
0794: + "\"" };
0795: exitValue = execUtil.exec(command, args);
0796: }
0797: exitValue = exec(command);
0798: if (exitValue != 0) {
0799: // DebugContext.error("Failed on stop instance <" +
0800: // exitValue + ">");
0801: Object[] params12 = { exitValue + "", ">" };
0802: logger.log(Level.SEVERE,
0803: "PSSR_CSPS_ADM_MBEANS012", params12);
0804: return false;
0805: } else {
0806: // DebugContext.message("Stopped the instance.");
0807: logger.info("PSSR_CSPS_ADM_MBEANS013");
0808: }
0809: } catch (Exception e) {
0810: e.printStackTrace();
0811: // DebugContext.error("Confiugration Error: Failed to stop
0812: // the instance " + pc.getInstanceName());
0813: Object[] params14 = { pc.getInstanceName() };
0814: logger.log(Level.SEVERE, "PSSR_CSPS_ADM_MBEANS014",
0815: params14);
0816: return false;
0817: }
0818: }
0819:
0820: }
0821: return retCode;
0822: }
0823:
0824: public String toString() {
0825: super .toString();
0826: StringBuffer sb = new StringBuffer();
0827: sb.append(" Java VM Properties : " + _jvmProperties + "\n");
0828: sb.append(" System Properties : " + _systemProperties + "\n");
0829: sb.append(" Classpath : " + _classPath + "\n");
0830: return sb.toString();
0831: }
0832:
0833: /*
0834: * (non-Javadoc)
0835: *
0836: * @see com.sun.portal.sra.mbeans.SraServer#getServiceIdentifier()
0837: */
0838: public int getServiceIdentifier() {
0839: return SraServer.INSTANCE_TYPE_GATEWAY;
0840: }
0841:
0842: /*
0843: * (non-Javadoc)
0844: *
0845: * @see com.sun.portal.sra.mbeans.SraServer#isGateway()
0846: */
0847: public boolean isGateway() {
0848: return true;
0849: }
0850:
0851: /*
0852: * (non-Javadoc)
0853: *
0854: * @see com.sun.portal.sra.mbeans.SraServer#isRewriterProxy()
0855: */
0856: public boolean isRewriterProxy() {
0857: return false;
0858: }
0859:
0860: /*
0861: * (non-Javadoc)
0862: *
0863: * @see com.sun.portal.sra.mbeans.SraServer#isNetletProxy()
0864: */
0865: public boolean isNetletProxy() {
0866: return false;
0867: }
0868:
0869: public String getInstancePID(String instance) {
0870: String result = "";
0871: String pscommand = _osDefaults.getValue("pid");
0872: // DebugContext.message(pscommand);
0873: logger.info("PSSR_CSPS_ADM_MBEANS015");
0874: Process ps_process = null;
0875: try {
0876: if (!is_Windows()) {
0877: ps_process = Runtime.getRuntime().exec(pscommand);
0878:
0879: BufferedReader br = new BufferedReader(
0880: new InputStreamReader(ps_process
0881: .getInputStream()));
0882: String s = "";
0883: while ((s = br.readLine()) != null) {
0884: // -Dnetletd.profilename= (for nlp)
0885: // -Drwproxyd.profilename= (for rwp)
0886: if (s.indexOf("-Dgateway.profilename=" + instance
0887: + " ") != -1) {
0888: result = s;
0889: // DebugContext.message("Line : " + s);
0890: Object[] params16 = { s };
0891: logger.log(Level.INFO,
0892: "PSSR_CSPS_ADM_MBEANS016", params16);
0893: break;
0894: }
0895: }
0896: } else {
0897: ps_process = Runtime.getRuntime().exec("net START");
0898:
0899: BufferedReader br = new BufferedReader(
0900: new InputStreamReader(ps_process
0901: .getInputStream()));
0902: String s = "";
0903: while ((s = br.readLine()) != null) {
0904: if (s.indexOf("Portal SRA Gateway " + instance
0905: + " ") != -1) {
0906: result = "100";
0907: // DebugContext.message("Line : " + s);
0908: Object[] params16 = { s };
0909: logger.log(Level.INFO,
0910: "PSSR_CSPS_ADM_MBEANS016", params16);
0911: break;
0912: }
0913: }
0914: }
0915: } catch (IOException e) {
0916: e.printStackTrace();
0917: return result;
0918: }
0919: StringTokenizer st = new StringTokenizer(result);
0920: try {
0921: result = st.nextToken();
0922: // DebugContext.message("Process Id : " + result);
0923: Object[] params17 = { result };
0924: logger.log(Level.INFO, "PSSR_CSPS_ADM_MBEANS017", params17);
0925: } catch (NoSuchElementException nsee) {
0926: // DebugContext.message("No gateway instance is running!!!");
0927: logger.info("PSSR_CSPS_ADM_MBEANS018");
0928: }
0929: return result;
0930: }
0931:
0932: /*
0933: * This method has to do different actions for different sra servers (e.g.
0934: * gateway, NLP, RWP) This can better moved to their implementations.
0935: */
0936: public Boolean removeInstanceSignature(boolean deletePlatformConf) {
0937:
0938: Boolean result = Boolean.TRUE;
0939: try {
0940: FileUtil.deleteDir(fc
0941: .getInstanceGWConfigurationPropertiesFile());
0942: if (deletePlatformConf) {
0943: FileUtil.deleteDir(fc
0944: .getInstanceCertificatesDirectory());
0945: FileUtil.deleteDir(fc
0946: .getInstancePlatformConfigurationFile());
0947: }
0948: } catch (Exception e) {
0949: e.printStackTrace();
0950: result = Boolean.FALSE;
0951: }
0952: return result;
0953: }
0954:
0955: public Boolean createLoggingUserAuthenticationEntry() {
0956: return super .createLoggingUserAuthenticationEntry();
0957: }
0958:
0959: public boolean isStarted(String hostname, int portNumber) {
0960: String pid = getInstancePID(this ._instanceName);
0961: return ((pid != null && !pid.equalsIgnoreCase("")) && super
0962: .isStarted(hostname, portNumber));
0963: }
0964:
0965: public boolean isStopped(String hostname, int portNumber) {
0966: return super .isStopped(hostname, portNumber);
0967: }
0968:
0969: public String getHttpPort() {
0970: List tmpList = getAttribute(pc.getPortalHost(), pc
0971: .getInstanceName(), ATTRIBUTE_GATEWAY_HTTP_PORT);
0972: if (tmpList != null && tmpList.size() != 0) {
0973: return (String) tmpList.get(0);
0974: }
0975: return pc.getPort();
0976: }
0977:
0978: public String getHttpsPort() {
0979: List tmpList = getAttribute(pc.getPortalHost(), pc
0980: .getInstanceName(), ATTRIBUTE_GATEWAY_HTTPS_PORT);
0981: if (tmpList != null && tmpList.size() != 0) {
0982: return (String) tmpList.get(0);
0983: }
0984: return pc.getPort();
0985: }
0986:
0987: public boolean isHttpEnabled() {
0988: List tmpList = getAttribute(pc.getPortalHost(), pc
0989: .getInstanceName(), ATTRIBUTE_GATEWAY_ENABLE_HTTP);
0990: if (tmpList != null && tmpList.size() != 0) {
0991: return new Boolean(((String) tmpList.get(0)))
0992: .booleanValue();
0993: }
0994: return false;
0995: }
0996:
0997: public boolean isHttpsEnabled() {
0998: List tmpList = getAttribute(pc.getPortalHost(), pc
0999: .getInstanceName(), ATTRIBUTE_GATEWAY_ENABLE_HTTPS);
1000: if (tmpList != null && tmpList.size() != 0) {
1001: return new Boolean(((String) tmpList.get(0)))
1002: .booleanValue();
1003: }
1004: return false;
1005: }
1006:
1007: }
|