001: package com.sun.portal.sra.admin.mbeans;
002:
003: import java.io.BufferedReader;
004: import java.io.File;
005: import java.io.IOException;
006: import java.io.InputStreamReader;
007: import java.util.*;
008: import java.util.logging.Level;
009: import java.util.logging.Logger;
010: import java.net.URL;
011: import java.net.MalformedURLException;
012:
013: import com.sun.portal.admin.common.context.PSConfigContext;
014: import com.sun.portal.admin.common.PSMBeanException;
015: import com.sun.portal.fabric.util.FileUtil;
016: import com.sun.portal.fabric.tasks.MonitoringConfigurationHelper;
017: import com.sun.portal.log.common.PortalLogger;
018: import com.sun.portal.log.common.PortalLogManager;
019: import com.sun.portal.sra.admin.context.NLPPropertyContext;
020: import com.sun.portal.sra.admin.context.SRAFileContextImpl;
021: import com.sun.portal.sra.admin.context.SRAPropertyContext;
022: import com.sun.portal.sra.admin.util.OSDefaults;
023: import com.sun.portal.sra.admin.util.SystemDefaults;
024: import com.sun.portal.fabric.util.ExecuteUtil;
025:
026: /**
027: * @version 1.0
028: * @created 04-Mar-2005 9:58:14 PM
029: * @author Sandeep Soni
030: */
031: public class NetletProxy extends SraServerImpl implements SraServer {
032: private static final String _mainClass = "com.sun.portal.netlet.proxy.NetletProxy";
033:
034: private String _classPath = new String();
035:
036: private String _instanceName = new String();
037:
038: private String _jvmProperties = new String();
039:
040: private Properties _platformConfProperties = new Properties();
041:
042: private HashMap _systemProperties = new HashMap();
043:
044: private static OSDefaults _osDefaults;
045:
046: private static String FS;
047:
048: public static final String COMPONENT_NAME = "gateway";//ldap attribute is stored in the same component type
049:
050: public static final String ATTRIBUTE_NLP_LISTS = "sunPortalGatewayNLPHostsAndIPs";
051:
052: private static String loggerName = "debug.com.sun.portal.admin.mbeans";
053:
054: private ExecuteUtil execUtil = new ExecuteUtil();
055:
056: static {
057: _osDefaults = SystemDefaults.getSystemDefaults();
058: FS = _osDefaults.getValue("fs");
059: }
060:
061: private static Logger logger = PortalLogger
062: .getLogger(NetletProxy.class);
063:
064: /**
065: * @param instanceName
066: */
067: protected NetletProxy(String instanceName, PSConfigContext cc) {
068: this .cc = cc;
069: _instanceName = instanceName;
070: populateForNamedInstance();
071: }
072:
073: protected NetletProxy(SRAPropertyContext pc, PSConfigContext cc) {
074: super (pc, cc);
075: }
076:
077: protected NetletProxy(PSConfigContext cc) {
078: this .cc = cc;
079: }
080:
081: private static boolean is_Windows() {
082: return System.getProperty("os.name").indexOf("indows") != -1;
083: }
084:
085: /**
086: * @param configFileProperties
087: * @return
088: */
089: public SraServer createInstance(Properties configFileProperties)
090: throws PSMBeanException {
091:
092: pc = new NLPPropertyContext(configFileProperties);
093: fc = new SRAFileContextImpl(pc, cc);
094: _instanceName = pc.getInstanceName();
095:
096: Boolean reCopy = (fc.existsGWInstance(pc.getInstanceName())
097: .booleanValue()
098: || fc.existsNLPInstance(pc.getInstanceName())
099: .booleanValue() || fc.existsRWPInstance(
100: pc.getInstanceName()).booleanValue()) ? Boolean.FALSE
101: : Boolean.TRUE;
102: if (fc.existsNLPInstance(pc.getInstanceName()).booleanValue()) {
103: throw new PSMBeanException(
104: "psadmin.error.sra.create.instanceExists");
105: }
106: if (CheckPort(pc.getHost(), pc.getPort(), 50) == Boolean.TRUE) {
107: String token[] = { pc.getPort() };
108: throw new PSMBeanException(
109: "psadmin.error.sra.create.portAlreadyInUse", token);
110: }
111:
112: copyFile(fc.getTemplatePlatformConfigurationFile(), fc
113: .getInstancePlatformConfigurationFile(), reCopy);
114: replaceTokens(fc.getInstancePlatformConfigurationFile());
115:
116: if (!pc.doCreateNewIdentitySDKInstance().booleanValue()) {
117: String[][] appendNameValues = new String[][] {
118: { "netletproxy.port", pc.getPort() },
119: { "gateway.bindipaddress", pc.getIP() },
120: { "gateway.sockretries", "3" } };
121: try {
122: addOrReplaceNameValues(fc
123: .getInstancePlatformConfigurationFile(),
124: appendNameValues);
125: } catch (IOException e) {
126: throw new PSMBeanException(
127: "psadmin.error.sra.create.platformConfMissing");
128: }
129: } else {
130: createIdentitySDKInstance();
131: native2Ascii();
132: String[][] appendNameValues = new String[][] {
133: { "netletproxy.port", pc.getPort() },
134: { "gateway.bindipaddress", pc.getIP() },
135: { "gateway.sockretries", "3" },
136: { "portal.server.instance", pc.getInstanceName() } };
137: try {
138: addOrReplaceNameValues(fc
139: .getInstancePlatformConfigurationFile(),
140: appendNameValues);
141: } catch (IOException e) {
142: throw new PSMBeanException(
143: "psadmin.error.sra.create.platformConfMissing");
144: }
145: }
146:
147: if (pc.doCreateSelfSignedCertificate().booleanValue()) {
148: FileUtil.makeDir(fc.getInstanceCertificatesDirectory());
149: if (createSelfSignedCertificate().booleanValue()) {
150: createLoggingUserAuthenticationEntry();
151: }
152: }
153: createInstanceSignature();
154: //addServerInstanceInfoToProfile(COMPONENT_NAME, ATTRIBUTE_NLP_LISTS);
155: setAttribute(pc.getPortalHost(), pc.getInstanceName(),
156: ATTRIBUTE_NLP_LISTS, pc.getHost(), pc.getIP());
157: pc.write(fc.getInstanceNLPConfigurationPropertiesFile(), fc
158: .getInstanceNLPConfigurationPropertiesFile());
159: String MonitoringFileName = cc.getPSConfigDir()
160: + File.separator + pc.getInstanceName()
161: + File.separator + "nlproxy" + File.separator
162: + "monitoring.properties";
163: File MonitoringFile = new File(MonitoringFileName);
164: if (!MonitoringFile.exists()) {
165: copyFile(cc.getPSBaseDir() + File.separator + "template"
166: + File.separator + "sra" + File.separator
167: + "monitoring.properties", MonitoringFileName,
168: Boolean.FALSE);
169: FileUtil.replaceTokenInFile(MonitoringFile,
170: "%INSTANCE_CONFIG_DIR%", cc.getPSConfigDir() + FS
171: + pc.getInstanceName() + FS + "nlproxy");
172: MonitoringConfigurationHelper.configurePropertyFile(
173: MonitoringFileName, pc.getHost(), cc);
174: }
175: populateForNamedInstance();
176: if (is_Windows())
177: createWindowsService();
178: if (pc.doStartAfterInstall().booleanValue())
179: start();
180: return this ;
181: }
182:
183: public boolean deleteInstance() throws PSMBeanException {
184: boolean status = true;
185: stop();
186: PortalLogManager.deleteSRALoggersList(fc
187: .getInstancePlatformConfigurationFile(), "nlproxy");
188: removeInstanceSignature();
189: //deleteServerInstanceInfoFromProfile(COMPONENT_NAME, ATTRIBUTE_NLP_LISTS);
190: deleteAttribute(pc.getPortalHost(), pc.getInstanceName(),
191: ATTRIBUTE_NLP_LISTS, pc.getHost(), pc.getIP());
192: if (is_Windows())
193: deleteWindowsService();
194: return status;
195: }
196:
197: /*
198: * (non-Javadoc)
199: *
200: * @see java.lang.Object#equals(java.lang.Object)
201: */
202: public boolean equals(Object obj) {
203: boolean ret = false;
204: if (obj instanceof Gateway) {
205: Gateway g = (Gateway) obj;
206: if (g.getInstanceName().equals(_instanceName))
207: ret = true;
208: }
209: return ret;
210: }
211:
212: public String getclassPath() {
213: return _classPath;
214: }
215:
216: // create windows service
217: private void createWindowsService() throws PSMBeanException {
218: StringBuffer sb = new StringBuffer();
219:
220: String classPath = getclassPath();
221: if (getclassPath() == null
222: || classPath.trim().equalsIgnoreCase("")) {
223: setClassPath(); // sets the default classPath for Gateway component
224: classPath = getclassPath();
225: }
226: setJVMProperties();
227:
228: String command = cc.getPSBaseDir() + File.separator + "lib"
229: + File.separator + "srasvc.exe";
230: String extraLibs = fc.getExtraLibs(amc.getJDKPath());
231: String libraryPath = fc
232: .getCreateSelfSignedCertificateLibraryPath()
233: + File.pathSeparator + extraLibs;
234: libraryPath += File.pathSeparator
235: + replaceBackSlash(System
236: .getProperty("java.library.path"));
237: String[] envp = new String[7];
238:
239: String DEFINES = " -Dnetletd.profilename="
240: + pc.getInstanceName();
241: sb.append(DEFINES);
242: sb.append(" -classpath ");
243: sb.append(classPath);
244: sb.append(" ");
245: sb.append(_jvmProperties);
246: sb.append(" ");
247: sb.append(_mainClass.trim());
248: // DebugContext.message("Command = " + sb.toString());
249: Object[] params2 = { sb.toString() };
250: logger.log(Level.INFO, "PSSR_CSPS_ADM_MBEANS022", params2);
251:
252: envp[0] = "servicename=SRA.Netlet." + pc.getInstanceName();
253: envp[1] = "serviceshowname=Portal SRA Netlet "
254: + pc.getInstanceName() + " instance";
255: envp[2] = "servicedesname=Sun Java System Portal SRA's Netlet "
256: + pc.getInstanceName() + " instance";
257: envp[3] = "javahome="
258: + _platformConfProperties
259: .getProperty("gateway.jdk.dir");
260: envp[4] = "jvmoptions=" + sb.toString();
261: envp[5] = "workingdirectory=" + cc.getPSConfigDir()
262: + File.separator + pc.getInstanceName()
263: + File.separator + "gateway";
264: envp[6] = "prefixpath=" + libraryPath;
265:
266: try {
267: String args[] = { "install" };
268: execUtil.exec(command, args, envp);
269: } catch (Exception e) {
270: throw new PSMBeanException(e.toString());
271: }
272: }
273:
274: // delete windows service
275: private void deleteWindowsService() throws PSMBeanException {
276:
277: String command = cc.getPSBaseDir() + File.separator + "lib"
278: + File.separator + "srasvc.exe";
279: try {
280: String args[] = { "uninstall", "servicename",
281: "SRA.Netlet." + pc.getInstanceName() };
282: execUtil.exec(command, args);
283: } catch (Exception e) {
284: throw new PSMBeanException(e.toString());
285: }
286: }
287:
288: /*
289: * (non-Javadoc)
290: *
291: * @see com.sun.portal.sra.mbeans.SraServer#getInstanceName()
292: */
293: public String getInstanceName() {
294: return new String(_instanceName);
295: }
296:
297: public String getjvmProperties() {
298: return _jvmProperties;
299: }
300:
301: public String getmainClass() {
302: return _mainClass;
303: }
304:
305: /*
306: * (non-Javadoc)
307: *
308: * @see com.sun.portal.sra.mbeans.SraServerComponent#getPlatformConfProperties()
309: */
310: public Properties getPlatformConfProperties() {
311: return (Properties) _platformConfProperties.clone();
312: }
313:
314: public HashMap getSystemProperties() {
315: return _systemProperties;
316: }
317:
318: /*
319: * (non-Javadoc)
320: *
321: * @see com.sun.portal.sra.mbeans.SraServerComponent#populateForNamedInstance(java.lang.String)
322: */
323: private void populateForNamedInstance() {
324: try {
325: String instancePropertiesFile = cc.getPSConfigDir()
326: + SRAFileContextImpl.fs + "NLPConfig-"
327: + _instanceName + ".properties";
328: pc = new NLPPropertyContext(load(instancePropertiesFile));
329: fc = new SRAFileContextImpl(pc, cc);
330: _platformConfProperties = load(fc
331: .getInstancePlatformConfigurationFile());
332: _jvmProperties = _platformConfProperties
333: .getProperty("netletproxy.jvm.flags");
334: _classPath = _platformConfProperties
335: .getProperty("netletproxy.jvm.classpath");
336: try {
337: amc = fc.getAMPropertyContext();
338: } catch (Exception e) {
339: e.printStackTrace();
340: // DebugContext.error("Error in getting AMConfig.properties");
341: logger.severe("PSSR_CSPS_ADM_MBEANS020");
342: }
343: } catch (IOException ioe) {
344: // DebugContext.message("Error in populating the netletproxy
345: // instance!");
346: logger.info("PSSR_CSPS_ADM_MBEANS021");
347: }
348: setClassPath();
349: setJVMProperties();
350: }
351:
352: /**
353: *
354: */
355: private void setClassPath() {
356: _classPath = _platformConfProperties
357: .getProperty("netletproxy.jvm.classpath");
358: String IDSAME_CONFIG_DIR = cc.getISConfigDir();
359: String IS_HOME = cc.getISBaseDir();
360:
361: String IS_CLASSPATH = IDSAME_CONFIG_DIR + File.pathSeparator;
362: IS_CLASSPATH = IS_CLASSPATH + IS_HOME + fs + "lib"
363: + File.pathSeparator;
364: IS_CLASSPATH = IS_CLASSPATH + IS_HOME + fs + "locale"
365: + File.pathSeparator;
366: IS_CLASSPATH = IS_CLASSPATH + IS_HOME + fs + "lib" + fs
367: + "am_sdk.jar" + File.pathSeparator;
368: IS_CLASSPATH = IS_CLASSPATH + IS_HOME + fs + "lib" + fs
369: + "am_services.jar" + File.pathSeparator;
370: IS_CLASSPATH = IS_CLASSPATH + IS_HOME + fs + "lib" + fs
371: + "am_logging.jar" + File.pathSeparator;
372: IS_CLASSPATH = IS_CLASSPATH + IS_HOME + fs + "lib" + fs
373: + "servlet.jar" + File.pathSeparator;
374: IS_CLASSPATH = IS_CLASSPATH + IS_HOME + fs + "lib" + fs
375: + "xmlsec.jar" + File.pathSeparator;
376:
377: String JCE_CLASSPATH = IS_HOME + fs + "lib" + fs
378: + "jce1_2_1.jar" + File.pathSeparator;
379: JCE_CLASSPATH = JCE_CLASSPATH + IS_HOME + fs + "lib" + fs
380: + "local_policy.jar" + File.pathSeparator;
381: JCE_CLASSPATH = JCE_CLASSPATH + IS_HOME + fs + "lib" + fs
382: + "US_export_policy.jar" + File.pathSeparator;
383: JCE_CLASSPATH = JCE_CLASSPATH + IS_HOME + fs + "lib" + fs
384: + "sunjce_provider.jar" + File.pathSeparator;
385:
386: String PS_HOME = cc.getPSBaseDir();
387: String LOGGING_CLASSPATH = PS_HOME + fs + "lib" + fs
388: + "pslogcommon.jar" + File.pathSeparator;
389:
390: String JDMK_LIB_DIR = fc.getJdmkLibLocation();
391: String MONITORING_JAR = PS_HOME + fs + "lib" + fs
392: + "monitoring.jar" + File.pathSeparator;
393: MONITORING_JAR = MONITORING_JAR + JDMK_LIB_DIR + fs + "jmx.jar"
394: + File.pathSeparator;
395: MONITORING_JAR = MONITORING_JAR + PS_HOME + fs + "lib" + fs
396: + "javax77.jar" + File.pathSeparator;
397: MONITORING_JAR = MONITORING_JAR + JDMK_LIB_DIR + fs
398: + "jdmkrt.jar" + File.pathSeparator;
399: MONITORING_JAR = MONITORING_JAR + JDMK_LIB_DIR + fs
400: + "jmxremote.jar" + File.pathSeparator;
401: MONITORING_JAR = MONITORING_JAR + JDMK_LIB_DIR + fs
402: + "jmxremote_optional.jar" + File.pathSeparator;
403: MONITORING_JAR = MONITORING_JAR + JDMK_LIB_DIR + fs
404: + "sunsasl.jar" + File.pathSeparator;
405: MONITORING_JAR = MONITORING_JAR + JDMK_LIB_DIR + fs
406: + "sasl.jar" + File.pathSeparator;
407:
408: String NLP_CLASSPATH = PS_HOME + fs + "lib"
409: + File.pathSeparator;
410: NLP_CLASSPATH = NLP_CLASSPATH + PS_HOME + fs + "locale"
411: + File.pathSeparator;
412: NLP_CLASSPATH = NLP_CLASSPATH + PS_HOME + fs + "lib" + fs
413: + "netletproxy.jar" + File.pathSeparator;
414: NLP_CLASSPATH = NLP_CLASSPATH + PS_HOME + fs + "lib" + fs
415: + "ps_util.jar" + File.pathSeparator;
416: NLP_CLASSPATH = NLP_CLASSPATH + PS_HOME + fs + "lib" + fs
417: + "ldapjdk.jar" + File.pathSeparator;
418: NLP_CLASSPATH = NLP_CLASSPATH + PS_HOME + fs + "lib" + fs
419: + "gateway.jar" + File.pathSeparator;
420: NLP_CLASSPATH = NLP_CLASSPATH + PS_HOME + fs + "lib" + fs
421: + "certadmin.jar" + File.pathSeparator;
422: NLP_CLASSPATH = NLP_CLASSPATH + PS_HOME + fs + "lib" + fs
423: + "ssl.jar" + File.pathSeparator;
424: NLP_CLASSPATH = NLP_CLASSPATH + PS_HOME + fs + "lib" + fs
425: + "x509v1.jar" + File.pathSeparator;
426: NLP_CLASSPATH = NLP_CLASSPATH + PS_HOME + fs + "lib" + fs
427: + "js.jar" + File.pathSeparator;
428:
429: String JSS_JAR = fc.getJSSJARDir() + fs + "jss4.jar"
430: + File.pathSeparator + fc.getJSSJARFile()
431: + File.pathSeparator;
432: NLP_CLASSPATH = IS_CLASSPATH + JCE_CLASSPATH + JSS_JAR
433: + LOGGING_CLASSPATH + MONITORING_JAR + NLP_CLASSPATH;
434: if (_classPath != null)
435: _classPath += File.pathSeparator + NLP_CLASSPATH;
436: else
437: _classPath = NLP_CLASSPATH;
438: }
439:
440: private void setJVMProperties() {
441: _jvmProperties = _platformConfProperties
442: .getProperty("netletproxy.jvm.flags");
443: if (_jvmProperties == null
444: || _jvmProperties.trim().equalsIgnoreCase("")) {
445: _jvmProperties = "-ms64m ";
446: _jvmProperties += "-mx128m ";
447: }
448: String IS_HOME = cc.getISBaseDir();
449:
450: String DEFINES1 = "-Dsun.net.inetaddr.ttl=0 -Djava.protocol.handler.pkgs=com.iplanet.services.comm";
451: Properties instancePlatformConfigProperties;
452: try {
453: instancePlatformConfigProperties = load(fc
454: .getInstancePlatformConfigurationFile());
455: } catch (IOException ioe) {
456: return;
457: }
458: String gatewayNotificationUrl = instancePlatformConfigProperties
459: .getProperty("gateway.notification.url");
460: String amNotificationUrl = instancePlatformConfigProperties
461: .getProperty("gateway.protocol")
462: + "://"
463: + instancePlatformConfigProperties
464: .getProperty("gateway.host")
465: + ":"
466: + instancePlatformConfigProperties
467: .getProperty("netletproxy.port")
468: + FS
469: + gatewayNotificationUrl;
470:
471: List notificationUrlList = getNotificationURL(
472: gatewayNotificationUrl, amNotificationUrl,
473: instancePlatformConfigProperties);
474: if (notificationUrlList != null) {
475: gatewayNotificationUrl = (String) notificationUrlList
476: .get(0);
477: amNotificationUrl = (String) notificationUrlList.get(1);
478: }
479:
480: String DIRECTORY_CERT_DB = instancePlatformConfigProperties
481: .getProperty("gateway.certdir");
482: String FILE_CERT_DB_PASSWORD = DIRECTORY_CERT_DB + fs
483: + ".jsspass";
484: String FILE_CERT_NICKNAME = DIRECTORY_CERT_DB + fs
485: + ".nickname";
486:
487: String DEFINES2 = "-Dcom.iplanet.am.notification.url="
488: + amNotificationUrl + " -Dgateway.notification.url="
489: + gatewayNotificationUrl;
490: String DEFINES3 = "-Dgateway.keybase=" + DIRECTORY_CERT_DB
491: + " -Dgateway.pass=" + FILE_CERT_DB_PASSWORD
492: + " -Dgateway.nickname=" + FILE_CERT_NICKNAME;
493: /*String DEFINES4 = "-Djava.util.logging.manager=com.sun.identity.log.LogManager -Djava.util.logging.config.file=" + IS_HOME + fs + "lib" + fs
494: + "LogConfig.properties" + " -Dcom.sun.portal.log.config.file=" + fc.getInstancePlatformConfigurationFile();*/
495:
496: // Identity Log Manager was being used instead of Portal Log Manager and hence the logs were not going into the portal logs
497: String DEFINES4 = " -Dcom.sun.portal.log.config.file="
498: + fc.getInstancePlatformConfigurationFile();
499: /*DEFINES4 = DEFINES4 + " -Dcom.sun.portal.monitoring.MonitoringContext.configuration.directory=" + cc.getPSConfigDir() + fs
500: + pc.getInstanceName() + fs + "nlp";*/
501: String DEFINES5 = " -Dgateway.profilename="
502: + pc.getInstanceName() + " -Dconf.suffix="
503: + pc.getInstanceName();
504:
505: String IS_CONFIG_NAME = instancePlatformConfigProperties
506: .getProperty("portal.server.instance");
507: if (IS_CONFIG_NAME != null
508: && !IS_CONFIG_NAME.trim().equalsIgnoreCase("")) {
509: DEFINES5 = DEFINES5 + " -Dserver.name=" + IS_CONFIG_NAME;
510: }
511:
512: StringBuffer sb = new StringBuffer();
513: sb.append(DEFINES1);
514: sb.append(" ");
515: sb.append(DEFINES2);
516: sb.append(" ");
517: sb.append(DEFINES3);
518: sb.append(" ");
519: sb.append(DEFINES4);
520: sb.append(" ");
521: sb.append(DEFINES5);
522: sb.append(" ");
523: sb.append("-DSRAP_CONFIG_DIR=" + cc.getPSConfigDir());
524: if (_jvmProperties != null) {
525: _jvmProperties += " ";
526: _jvmProperties += sb.toString();
527: } else
528: _jvmProperties = sb.toString();
529: }
530:
531: private String getExecCommand() {
532: StringBuffer sb = new StringBuffer();
533:
534: String classPath = getclassPath();
535: if (getclassPath() == null
536: || classPath.trim().equalsIgnoreCase("")) {
537: setClassPath(); // sets the default classPath for NetletProxy
538: // component
539: classPath = getclassPath();
540: }
541: setJVMProperties();
542:
543: String command = _platformConfProperties
544: .getProperty("gateway.jdk.dir")
545: + FORWARD_SLASH + "bin" + FORWARD_SLASH + "java";
546: String DEFINES = " -Dnetletd.profilename="
547: + pc.getInstanceName();
548: sb.append(command);
549: sb.append(DEFINES);
550: sb.append(" -classpath ");
551: sb.append(classPath);
552: sb.append(" ");
553: sb.append(_jvmProperties);
554: sb.append(" ");
555: sb.append(_mainClass.trim());
556: // DebugContext.message("Command = " + sb.toString());
557: Object[] params2 = { sb.toString() };
558: logger.log(Level.INFO, "PSSR_CSPS_ADM_MBEANS022", params2);
559:
560: return sb.toString();
561: }
562:
563: public boolean start() throws PSMBeanException {
564: boolean retCode = true;
565: if (_instanceName.length() > 0) {
566: String command = getExecCommand();
567: String extraLibs = fc.getExtraLibs(amc.getJDKPath());
568: String libraryPath = fc
569: .getCreateSelfSignedCertificateLibraryPath()
570: + File.pathSeparator + extraLibs;
571: libraryPath += File.pathSeparator
572: + replaceBackSlash(System
573: .getProperty("java.library.path"));
574: String[] envp = new String[2];
575: envp[0] = "LD_LIBRARY_PATH=" + libraryPath;
576: envp[1] = "SHLIB_PATH=" + libraryPath;
577: // Execute the command here.
578: String instance = pc.getInstanceName();
579: String pid = getInstancePID(instance);
580: if (!pid.trim().equalsIgnoreCase("")) {
581: // DebugContext.error("Info: Netlet Proxy instance already
582: // running!");
583: logger.severe("PSSR_CSPS_ADM_MBEANS023");
584: String token[] = { instance };
585: throw new PSMBeanException(
586: "psadmin.error.sra.start.instanceAlreadyRunning",
587: token);
588: } else if (CheckPort(pc.getHost(), pc.getPort(), 50) == Boolean.TRUE) {
589: String token[] = { "nlproxy", pc.getPort() };
590: throw new PSMBeanException(
591: "psadmin.error.sra.start.portAlreadyInUse",
592: token);
593: } else {
594: if (!is_Windows())
595: command = command.trim() + " &";
596: else {
597: command = "net";
598: try {
599: String args[] = { "start",
600: "SRA.Netlet." + pc.getInstanceName() };
601: execUtil.exec(command, args, envp);
602: } catch (Exception e) {
603: logger.severe("PSSR_CSPS_ADM_MBEANS028");
604: String token[] = { instance, "nlproxy" };
605: throw new PSMBeanException(
606: "psadmin.error.sra.start.instance",
607: token);
608: }
609: }
610: Object[] params2 = { "export " + envp[0] + ";"
611: + command };
612: logger.log(Level.INFO, "PSSR_CSPS_ADM_MBEANS022",
613: params2);
614:
615: // DebugContext.message(command);
616: logger.info("PSSR_CSPS_ADM_MBEANS024");
617: if (!is_Windows()) {
618: try {
619: Runtime.getRuntime().exec(command, envp);
620: Thread.sleep(10000L);
621: } catch (Exception e) {
622: logger.severe("PSSR_CSPS_ADM_MBEANS028");
623: String token[] = { instance, "nlproxy" };
624: throw new PSMBeanException(
625: "psadmin.error.sra.start.instance",
626: token);
627: }
628: }
629: if (CheckPort(pc.getHost(), pc.getPort(), 50) == Boolean.TRUE) {
630: pid = getInstancePID(pc.getInstanceName());
631: if (pid.trim().equalsIgnoreCase("")) {
632: String token[] = { "nlproxy", pc.getPort() };
633: throw new PSMBeanException(
634: "psadmin.error.sra.start.portAlreadyInUse",
635: token);
636: }
637: // DebugContext.message("Netlet Proxy started
638: // successfully .");
639: logger.info("PSSR_CSPS_ADM_MBEANS025");
640: } else {
641: // DebugContext.message("Netlet Proxy failed to start
642: // due to some internal errors .");
643: logger.info("PSSR_CSPS_ADM_MBEANS026");
644: pid = getInstancePID(pc.getInstanceName());
645: if (!pid.trim().equalsIgnoreCase("")) {
646: String token[] = { "netlet proxy", pid };
647: throw new PSMBeanException(
648: "psadmin.error.sra.start.instanceRunningButNotListening",
649: token);
650: }
651: return false;
652: }
653: }
654: }
655: return retCode;
656: }
657:
658: public boolean stop() throws PSMBeanException {
659: boolean retCode = true;
660: if (_instanceName.length() > 0) {
661: // Execute the command here.to stop the instance
662: String pid = getInstancePID(pc.getInstanceName());
663: if (!pid.equalsIgnoreCase("")) {
664: String command = _osDefaults.getValue("kill") + " -9 "
665: + pid;
666: try {
667: int exitValue = 0;
668: if (!is_Windows()) {
669: exitValue = exec(command);
670: } else {
671: command = "net";
672: String args[] = { "stop",
673: "SRA.Netlet." + pc.getInstanceName() };
674: exitValue = execUtil.exec(command, args);
675: }
676: if (exitValue != 0) {
677: // DebugContext.error("Failed on stop instance <" +
678: // exitValue + ">");
679: Object[] params9 = { exitValue + "", ">" };
680: logger.log(Level.SEVERE,
681: "PSSR_CSPS_ADM_MBEANS029", params9);
682: return false;
683: } else {
684: // DebugContext.message("Stopped the instance.");
685: logger.info("PSSR_CSPS_ADM_MBEANS030");
686: }
687: } catch (Exception e) {
688: e.printStackTrace();
689: // DebugContext.error("Confiugration Error: Failed to stop
690: // the instance " + pc.getInstanceName());
691: Object[] params11 = { pc.getInstanceName() };
692: logger.log(Level.SEVERE, "PSSR_CSPS_ADM_MBEANS031",
693: params11);
694: return false;
695: }
696: }
697:
698: }
699: return retCode;
700: }
701:
702: public String toString() {
703: super .toString();
704: StringBuffer sb = new StringBuffer();
705: sb.append(" Java VM Properties : " + _jvmProperties + "\n");
706: sb.append(" System Properties : " + _systemProperties + "\n");
707: sb.append(" Classpath : " + _classPath + "\n");
708: return sb.toString();
709: }
710:
711: /*
712: * (non-Javadoc)
713: *
714: * @see com.sun.portal.sra.mbeans.SraServer#getServiceIdentifier()
715: */
716: public int getServiceIdentifier() {
717: return SraServer.INSTANCE_TYPE_NETLET_PROXY;
718: }
719:
720: /*
721: * (non-Javadoc)
722: *
723: * @see com.sun.portal.sra.mbeans.SraServer#isGateway()
724: */
725: public boolean isGateway() {
726: return false;
727: }
728:
729: /*
730: * (non-Javadoc)
731: *
732: * @see com.sun.portal.sra.mbeans.SraServer#isRewriterProxy()
733: */
734: public boolean isRewriterProxy() {
735: return false;
736: }
737:
738: /*
739: * (non-Javadoc)
740: *
741: * @see com.sun.portal.sra.mbeans.SraServer#isNetletProxy()
742: */
743: public boolean isNetletProxy() {
744: return true;
745: }
746:
747: public String getInstancePID(String instance) {
748: String result = "";
749: String pscommand = _osDefaults.getValue("pid");
750: // DebugContext.message(pscommand);
751: logger.info("PSSR_CSPS_ADM_MBEANS032");
752: Process ps_process = null;
753: try {
754: if (!is_Windows()) {
755: ps_process = Runtime.getRuntime().exec(pscommand);
756:
757: BufferedReader br = new BufferedReader(
758: new InputStreamReader(ps_process
759: .getInputStream()));
760: String s = "";
761: while ((s = br.readLine()) != null) {
762: // -Dgateway.profilename= (for gateway)
763: // -Drwproxyd.profilename= (for rwp)
764: if (s.indexOf("-Dnetletd.profilename=" + instance
765: + " ") != -1) {
766: result = s;
767: // DebugContext.message("Line : " + s);
768: Object[] params13 = { s };
769: logger.log(Level.INFO,
770: "PSSR_CSPS_ADM_MBEANS033", params13);
771: break;
772: }
773: }
774: } else {
775: ps_process = Runtime.getRuntime().exec("net START");
776:
777: BufferedReader br = new BufferedReader(
778: new InputStreamReader(ps_process
779: .getInputStream()));
780: String s = "";
781: while ((s = br.readLine()) != null) {
782: if (s
783: .indexOf("Portal SRA Netlet " + instance
784: + " ") != -1) {
785: result = "100";
786: // DebugContext.message("Line : " + s);
787: Object[] params16 = { s };
788: logger.log(Level.INFO,
789: "PSSR_CSPS_ADM_MBEANS016", params16);
790: break;
791: }
792: }
793: }
794: } catch (IOException e) {
795: e.printStackTrace();
796: return result;
797: }
798: StringTokenizer st = new StringTokenizer(result);
799: try {
800: result = st.nextToken();
801: // DebugContext.message("Process Id : " + result);
802: Object[] params14 = { result };
803: logger.log(Level.INFO, "PSSR_CSPS_ADM_MBEANS034", params14);
804: } catch (NoSuchElementException nsee) {
805: // DebugContext.message("No NLP instance is running!!!");
806: logger.info("PSSR_CSPS_ADM_MBEANS035");
807: }
808: return result;
809: }
810:
811: public Boolean removeInstanceSignature() {
812: Boolean result = Boolean.TRUE;
813: try {
814: FileUtil.deleteDir(fc
815: .getInstanceNLPConfigurationPropertiesFile());
816: if (!fc.existsRWPInstance(pc.getInstanceName())
817: .booleanValue()
818: && !fc.existsGWInstance(pc.getInstanceName())
819: .booleanValue()) {
820: FileUtil.deleteDir(fc
821: .getInstanceCertificatesDirectory());
822: FileUtil.deleteDir(fc
823: .getInstancePlatformConfigurationFile());
824: FileUtil.deleteDir(cc.getPSConfigDir() + FS
825: + pc.getInstanceName());
826: removeIdentitySDKInstance();
827: } else {
828: String[][] appendNameValues = new String[][] { {
829: "netletproxy.port", "" } };
830: addOrReplaceNameValues(fc
831: .getInstancePlatformConfigurationFile(),
832: appendNameValues);
833: FileUtil.deleteDir(cc.getPSConfigDir() + FS
834: + pc.getInstanceName() + FS + "nlproxy");
835: }
836: } catch (Exception e) {
837: e.printStackTrace();
838: result = Boolean.FALSE;
839: }
840: return result;
841: }
842:
843: public Boolean createLoggingUserAuthenticationEntry() {
844: return super .createLoggingUserAuthenticationEntry();
845: }
846:
847: public boolean isStarted(String hostname, int portNumber) {
848: String pid = getInstancePID(this ._instanceName);
849: return ((pid != null && !pid.equalsIgnoreCase("")) && super
850: .isStarted(hostname, portNumber));
851: }
852:
853: public boolean isStopped(String hostname, int portNumber) {
854: return super.isStopped(hostname, portNumber);
855: }
856: }
|