Source Code Cross Referenced for BEAWL8Impl.java in  » Portal » Open-Portal » com » sun » portal » fabric » tasks » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Portal » Open Portal » com.sun.portal.fabric.tasks 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /**
0002:         * $Id: BEAWL8Impl.java,v 1.53 2006/11/21 11:38:18 pr150268 Exp $
0003:         * Copyright 2004 Sun Microsystems, Inc. All
0004:         * rights reserved. Use of this product is subject
0005:         * to license terms. Federal Acquisitions:
0006:         * Commercial Software -- Government Users
0007:         * Subject to Standard License Terms and
0008:         * Conditions.
0009:         *
0010:         * Sun, Sun Microsystems, the Sun logo, and Sun ONE
0011:         * are trademarks or registered trademarks of Sun Microsystems,
0012:         * Inc. in the United States and other countries.
0013:         */package com.sun.portal.fabric.tasks;
0014:
0015:        import java.io.File;
0016:        import java.util.Map;
0017:        import java.util.Properties;
0018:        import java.util.logging.Level;
0019:        import java.util.logging.Logger;
0020:        import java.util.logging.LogRecord;
0021:        import java.util.StringTokenizer;
0022:
0023:        import com.sun.portal.admin.common.context.PSConfigContext;
0024:        import com.sun.portal.fabric.util.FileUtil;
0025:
0026:        import com.sun.portal.log.common.PortalLogger;
0027:
0028:        import com.sun.portal.admin.common.PSConfigConstants;
0029:        import com.sun.portal.util.ResourceLoader;
0030:        import java.io.IOException;
0031:        import java.io.FileWriter;
0032:        import java.util.StringTokenizer;
0033:
0034:        import org.jdom.Element;
0035:
0036:        import com.sun.portal.fabric.util.os.OSTasks;
0037:        import com.sun.portal.fabric.util.os.OSTasksFactory;
0038:
0039:        public class BEAWL8Impl extends WebContainerBase implements 
0040:                PSConfigConstants {
0041:
0042:            private String wcHomeDir = null;
0043:            private String wcTargetInstance = null;
0044:            private String wcInstanceDir = null;
0045:            private String wcAdminUser = null;
0046:            private String wcAdminPassword = null;
0047:            private String wcAdminProtocol = null;
0048:            private String wcAdminHost = null;
0049:            private String wcAdminPort = null;
0050:            private String wcTargetConfigdir = null;
0051:            private String wcDomain = null;
0052:            private String wcJDKDir = null;
0053:            private String wcManagedServerStr = null;
0054:            private String amconfigScript = null;
0055:            private boolean wcManagedServer;
0056:
0057:            private File wcConfigfile;
0058:            private String psBaseDir;
0059:            private static String AM_CLASSPATH = "";
0060:            private String amConfigDir = "";
0061:            private String psClassPath;
0062:            private static Logger logger = PortalLogger
0063:                    .getLogger(BEAWL8Impl.class);
0064:
0065:            /**
0066:             * Constructor
0067:             *
0068:             * @param wcAttributes WebContainer Information as a Map
0069:             */
0070:            public BEAWL8Impl(Map wcAttributes) {
0071:
0072:                super (wcAttributes);
0073:                logger.log(Level.FINEST, wcAttributes.toString());
0074:
0075:                wcHomeDir = (String) wcAttributes
0076:                        .get(WEB_CONTAINER_INSTALL_DIR);
0077:                wcInstanceDir = (String) wcAttributes
0078:                        .get(WEB_CONTAINER_INSTANCE_DIR);
0079:                wcTargetInstance = (String) wcAttributes
0080:                        .get(WEB_CONTAINER_INSTANCE);
0081:                wcJDKDir = (String) wcAttributes.get(WEB_CONTAINER_JDK_DIR);
0082:                // This one should be in webcontainer.properties.
0083:                wcAdminUser = (String) wcAttributes
0084:                        .get(WEB_CONTAINER_ADMIN_UID);
0085:                wcAdminPassword = (String) wcAttributes
0086:                        .get(WEB_CONTAINER_ADMIN_PASSWORD);
0087:                wcAdminProtocol = (String) wcAttributes
0088:                        .get(WEB_CONTAINER_ADMIN_SCHEME);
0089:                wcAdminHost = (String) wcAttributes
0090:                        .get(WEB_CONTAINER_ADMIN_HOST);
0091:                wcAdminPort = (String) wcAttributes
0092:                        .get(WEB_CONTAINER_ADMIN_PORT);
0093:                wcManagedServerStr = (String) wcAttributes
0094:                        .get(WEB_CONTAINER_MANAGED_SERVER);
0095:
0096:                //??setConfigFile();
0097:            }
0098:
0099:            public void postValidationInit() throws ConfigurationException {
0100:
0101:                wcTargetConfigdir = wcInstanceDir.substring(0, wcInstanceDir
0102:                        .lastIndexOf(fs));
0103:                wcDomain = wcInstanceDir.substring(wcInstanceDir
0104:                        .lastIndexOf(fs) + 1);
0105:                wcManagedServer = new Boolean(wcManagedServerStr)
0106:                        .booleanValue();
0107:
0108:                wcPrintableInstanceName = wcDomain + "." + wcTargetInstance;
0109:                setConfigFile();
0110:            }
0111:
0112:            private void setConfigFile() {
0113:                String wcConfigfileName = "startWebLogic.sh";
0114:                String wcManagedConfigfileName = "startManagedWebLogic.sh";
0115:                String wcConfigfileNameToUse;
0116:
0117:                wcConfigfileNameToUse = (wcManagedServer == false) ? wcConfigfileName
0118:                        : wcManagedConfigfileName;
0119:                wcConfigfile = new File(wcInstanceDir + fs
0120:                        + wcConfigfileNameToUse);
0121:            }
0122:
0123:            /**
0124:             * Deploys the WAR file on to the webcontainer instance
0125:             *
0126:             * @param warFile WAR file including full path
0127:             * @param uri Deployment URI
0128:             */
0129:            public void deploy(String warFile, String uri)
0130:                    throws ConfigurationException {
0131:                logger.log(Level.FINEST, "PSFB_CSPFT0049", new String[] {
0132:                        warFile, uri, wcPrintableInstanceName });
0133:                //For Admin Server the deploy is a manual step
0134:                if (wcManagedServer == false)
0135:                    return;
0136:
0137:                StringTokenizer st = new StringTokenizer(uri, "/");
0138:                uri = st.nextToken();
0139:                String command = wcJDKDir + fs + "bin" + fs + "java";
0140:                String[] args = new String[15];
0141:                args[0] = "-cp";
0142:                args[1] = wcHomeDir + fs + "server" + fs + "lib" + fs
0143:                        + "weblogic.jar";
0144:                args[2] = "weblogic.Deployer";
0145:                args[3] = "-adminurl";
0146:                args[4] = "t3://" + wcAdminHost + ":" + wcAdminPort;
0147:                args[5] = "-name";
0148:                args[6] = uri;
0149:                args[7] = "-username";
0150:                args[8] = wcAdminUser;
0151:                args[9] = "-password";
0152:                args[10] = wcAdminPassword;
0153:                args[11] = "-targets";
0154:                args[12] = wcTargetInstance;
0155:                args[13] = "-deploy";
0156:                args[14] = warFile;
0157:
0158:                execUtil.storeOutput(true);
0159:                try {
0160:
0161:                    int iRetCode = execUtil.exec(command, args);
0162:                    if (iRetCode != 0) {
0163:
0164:                        // 'deploy' failed for some reason
0165:                        String sError = execUtil.getError();
0166:                        if ((sError == null) || sError.trim().equals("")) {
0167:
0168:                            sError = "Deploy Failed";
0169:                        }
0170:
0171:                        // Throw configuration Exception
0172:                        throw new ConfigurationException(sError);
0173:                    }
0174:                } catch (Exception e) {
0175:                    if (logger.isLoggable(Level.SEVERE)) {
0176:                        LogRecord record = new LogRecord(Level.SEVERE,
0177:                                "PSFB_CSPFT0059");
0178:                        record.setParameters(new String[] { warFile, uri,
0179:                                wcPrintableInstanceName });
0180:                        record.setThrown(e);
0181:                        record.setLoggerName(logger.getName());
0182:                        logger.log(record);
0183:                    }
0184:                    throw new ConfigurationException(e);
0185:                }
0186:                logger.log(Level.FINEST, "PSFB_CSPFT0050", new String[] {
0187:                        "War file deployment output", execUtil.getOutput() });
0188:            }
0189:
0190:            public void redeploy(String instance, String uri, String deployDir)
0191:                    throws ConfigurationException {
0192:
0193:                logger.log(Level.FINEST, "PSFB_CSPFT0060", new String[] {
0194:                        instance, uri, deployDir });
0195:                //For Admin Server the deploy is a manual step
0196:                if (wcManagedServer == false)
0197:                    return;
0198:                String command = wcJDKDir + fs + "bin" + fs + "java";
0199:                String[] args = new String[14];
0200:                args[0] = "-cp";
0201:                args[1] = wcHomeDir + fs + "server" + fs + "lib" + fs
0202:                        + "weblogic.jar";
0203:                args[2] = "weblogic.Deployer";
0204:                args[3] = "-adminurl";
0205:                args[4] = "t3://" + wcAdminHost + ":" + wcAdminPort;
0206:                args[5] = "-name";
0207:                args[6] = uri;
0208:                args[7] = "-username";
0209:                args[8] = wcAdminUser;
0210:                args[9] = "-password";
0211:                args[10] = wcAdminPassword;
0212:                args[11] = "-targets";
0213:                args[12] = wcTargetInstance;
0214:                args[13] = "-redeploy";
0215:
0216:                execUtil.storeOutput(true);
0217:                try {
0218:                    execUtil.exec(command, args);
0219:                } catch (Exception e) {
0220:                    if (logger.isLoggable(Level.SEVERE)) {
0221:                        LogRecord record = new LogRecord(Level.SEVERE,
0222:                                "PSFB_CSPFT0061");
0223:                        record.setParameters(new String[] { instance, uri,
0224:                                deployDir });
0225:                        record.setThrown(e);
0226:                        record.setLoggerName(logger.getName());
0227:                        logger.log(record);
0228:                    }
0229:                    throw new ConfigurationException(e);
0230:                }
0231:                logger.log(Level.FINEST, "PSFB_CSPFT0050", new String[] {
0232:                        "War file redeployment output", execUtil.getOutput() });
0233:            }
0234:
0235:            /**
0236:             * Undeploys the WAR file from the webcontainer instance
0237:             *
0238:             * @param uri Deployment URI
0239:             */
0240:            public void undeploy(String uri) throws ConfigurationException {
0241:                logger
0242:                        .log(Level.FINEST, "PSFB_CSPFT0073",
0243:                                new String[] { uri });
0244:                //For Admin Server the deploy is a manual step
0245:                if (wcManagedServer == false)
0246:                    return;
0247:
0248:                StringTokenizer st = new StringTokenizer(uri, "/");
0249:                uri = st.nextToken();
0250:                String command = wcJDKDir + fs + "bin" + fs + "java";
0251:                String[] args = new String[14];
0252:                args[0] = "-cp";
0253:                args[1] = wcHomeDir + fs + "server" + fs + "lib" + fs
0254:                        + "weblogic.jar";
0255:                args[2] = "weblogic.Deployer";
0256:                args[3] = "-adminurl";
0257:                args[4] = "t3://" + wcAdminHost + ":" + wcAdminPort;
0258:                args[5] = "-name";
0259:                args[6] = uri;
0260:                args[7] = "-username";
0261:                args[8] = wcAdminUser;
0262:                args[9] = "-password";
0263:                args[10] = wcAdminPassword;
0264:                args[11] = "-targets";
0265:                args[12] = wcTargetInstance;
0266:                args[13] = "-undeploy";
0267:
0268:                execUtil.storeOutput(true);
0269:                try {
0270:                    execUtil.exec(command, args);
0271:                } catch (Exception e) {
0272:                    if (logger.isLoggable(Level.SEVERE)) {
0273:                        LogRecord record = new LogRecord(Level.SEVERE,
0274:                                "PSFB_CSPFT0062");
0275:                        record.setThrown(e);
0276:                        record.setLoggerName(logger.getName());
0277:                        logger.log(record);
0278:                    }
0279:                    throw new ConfigurationException(e);
0280:                }
0281:                logger.log(Level.FINEST, "PSFB_CSPFT0050", new String[] {
0282:                        "War file undeployment output", execUtil.getOutput() });
0283:            }
0284:
0285:            /**
0286:             * Configures the WebContainer with the classpath
0287:             * settings, JVM options and other settings needed
0288:             * for Identity Server SDK
0289:             */
0290:            public void doIdentitySDKConfig(final PSConfigContext configContext)
0291:                    throws ConfigurationException {
0292:
0293:                if (isIdentityServerSDKConfigured()) {
0294:                    logger.log(Level.INFO, "PSFB_CSPFT0014",
0295:                            new String[] { wcPrintableInstanceName });
0296:                    return;
0297:                }
0298:
0299:                String FS = File.separator;
0300:                String protocol = (String) wcAttributes.get(SCHEME);
0301:                String host = (String) wcAttributes.get(HOST);
0302:                String port = (String) wcAttributes.get(PORT);
0303:
0304:                String amProductLoc = configContext.getISBaseDir();
0305:                //Store the amconfig directory. We need it later.
0306:                amConfigDir = configContext.getISConfigDir();
0307:                String psDataDir = configContext.getPSDataDir();
0308:
0309:                int index = amProductLoc.lastIndexOf(FS);
0310:                String amProductDir = amProductLoc.substring(index + 1);
0311:                String amBaseDir = amProductLoc.substring(0, index);
0312:
0313:                logger.log(Level.FINEST, "PSFB_CSPFT0015",
0314:                        new String[] { wcPrintableInstanceName });
0315:
0316:                String amSilentName = psDataDir + FS + "tmp" + FS
0317:                        + "amsilent_ps." + FileUtil.getRandomDirName();
0318:
0319:                StringBuffer fileData = new StringBuffer();
0320:                fileData.append("BASEDIR=" + amBaseDir + nl).append(
0321:                        "PRODUCT_DIR=" + amProductDir + nl).append(
0322:                        "CONFIG_DIR=" + amConfigDir + nl + nl).append(
0323:                        "WL8_HOME=" + wcHomeDir + nl).append(
0324:                        "WL8_PROJECT_DIR=" + "user_projects" + nl).append(
0325:                        "WL8_CONFIG_LOCATION=" + wcTargetConfigdir + nl)
0326:                        .append("WL8_DOMAIN=" + wcDomain + nl).append(
0327:                                "WL8_INSTANCE=" + wcHomeDir + nl).append(
0328:                                "WL8_SERVER=" + wcTargetInstance + nl).append(
0329:                                "WL8_PROTOCOL=" + protocol + nl).append(
0330:                                "WL8_HOST=" + host + nl).append(
0331:                                "WL8_PORT=" + port + nl).append(
0332:                                "WL8_ADMIN=" + wcAdminUser + nl).append(
0333:                                "WL8_ADMINPASSWD=" + wcAdminPassword + nl)
0334:                        .append("WL8_ADMINPORT=" + wcAdminPort + nl).append(
0335:                                "WL8_JDK_HOME=" + wcJDKDir + nl);
0336:                /**
0337:                 * If AM version is 6.x then use container configuration scripts
0338:                 * else use amconfig script for container configuration
0339:                 * See 6284663 for more info.
0340:                 */
0341:                if (configContext.getAMVersion().equals("6")) {
0342:                    fileData.append("DEPLOY_LEVEL=4" + nl);
0343:                    amconfigScript = "amwl81config";
0344:                } else {
0345:                    fileData.append("DEPLOY_LEVEL=7" + nl).append(
0346:                            "JAVA_HOME=" + configContext.getJavaHome() + nl)
0347:                            .append("WEB_CONTAINER=WL8" + nl);
0348:                    amconfigScript = "amconfig";
0349:                }
0350:
0351:                File amSilentFile = new File(amSilentName);
0352:                try {
0353:                    FileWriter fwriter = new FileWriter(amSilentFile);
0354:                    fwriter.write(fileData.toString());
0355:                    fwriter.close();
0356:                } catch (IOException ioe) {
0357:                    if (logger.isLoggable(Level.SEVERE)) {
0358:                        logger.log(Level.SEVERE, "PSFB_CSPFT0016");
0359:                        LogRecord record = new LogRecord(Level.SEVERE,
0360:                                "PSFB_CSPFT0017");
0361:                        record
0362:                                .setParameters(new String[] { wcPrintableInstanceName });
0363:                        record.setThrown(ioe);
0364:                        record.setLoggerName(logger.getName());
0365:                        logger.log(record);
0366:                    }
0367:                    amSilentFile.delete();
0368:                    return;
0369:                }
0370:
0371:                String amwl81config = amProductLoc + fs + "bin" + fs
0372:                        + amconfigScript;
0373:                String args[] = { "-s", amSilentName };
0374:
0375:                logger.log(Level.FINEST, "PSFB_CSPFT0018",
0376:                        new String[] { amwl81config });
0377:                if (execUtil.exec(amwl81config, args) != 0) {
0378:                    logger.log(Level.SEVERE, "PSFB_CSPFT0019", new String[] {
0379:                            wcType, wcPrintableInstanceName });
0380:                } else {
0381:                    logger.log(Level.INFO, "PSFB_CSPFT0020", new String[] {
0382:                            wcType, wcPrintableInstanceName });
0383:                }
0384:
0385:                amSilentFile.delete();
0386:            }
0387:
0388:            private void computeAMClassPath(String amConfigDir) {
0389:
0390:                String AMClasspathKeyStr = "";
0391:                String OSStr = System.getProperty("os.name");
0392:                boolean linuxOS = (OSStr.indexOf("Linux") != -1) ? true : false;
0393:                boolean sunOS = (OSStr.indexOf("SunOS") != -1) ? true : false;
0394:                if (sunOS == true)
0395:                    AMClasspathKeyStr = "/etc/opt/SUNWam/config";
0396:                else if (linuxOS == true)
0397:                    AMClasspathKeyStr = "/etc/opt/sun/identity/config";
0398:                String str = FileUtil.findTextInFile(wcConfigfile,
0399:                        AMClasspathKeyStr);
0400:
0401:                if (!str.equals(""))
0402:                    AM_CLASSPATH = str.substring(10);
0403:                else
0404:                    AM_CLASSPATH = "";
0405:
0406:            }
0407:
0408:            private final boolean isIdentityServerSDKConfigured()
0409:                    throws ConfigurationException {
0410:                String amSDKJar = null;
0411:
0412:                amSDKJar = FileUtil.findTextInFile(wcConfigfile, "am_sdk.jar");
0413:                if (amSDKJar != null && amSDKJar.trim().length() > 0) {
0414:                    return true;
0415:                } else {
0416:                    return false;
0417:                }
0418:            }
0419:
0420:            public void createSymbolicLinks(final PSConfigContext configContext) {
0421:                String appDir = wcInstanceDir + fs + "applications";
0422:                //Check if the DefaultWebApp exists
0423:                String defWebApp = "DefaultWebApp";
0424:                File defWebAppDir = new File(appDir + fs + defWebApp);
0425:                if (!defWebAppDir.exists()) {
0426:                    //If DefaultWebApp does not exist extract and create it.
0427:                    String defWebAppJar = wcHomeDir + fs + "common" + fs
0428:                            + "templates" + fs + "applications" + fs
0429:                            + defWebApp + ".jar";
0430:                    String tmpDefWebAppPath = configContext.getPSDataDir() + fs
0431:                            + "WL81" + defWebApp;
0432:                    File tmpDefWebAppDir = new File(tmpDefWebAppPath);
0433:                    if (tmpDefWebAppDir.exists()) {
0434:                        if (tmpDefWebAppDir.isDirectory()) {
0435:                            FileUtil.deleteDir(tmpDefWebAppDir);
0436:                        } else {
0437:                            tmpDefWebAppDir.delete();
0438:                        }
0439:                    } else {
0440:                        FileUtil.makeDir(tmpDefWebAppPath);
0441:                    }
0442:
0443:                    try {
0444:                        FileUtil.extractJar(defWebAppJar, tmpDefWebAppPath);
0445:                    } catch (IOException ex) {
0446:                        if (logger.isLoggable(Level.SEVERE)) {
0447:                            LogRecord record = new LogRecord(Level.SEVERE,
0448:                                    "PSFB_CSPFT0063");
0449:                            record.setParameters(new String[] { defWebAppJar });
0450:                            record.setThrown(ex);
0451:                            record.setLoggerName(logger.getName());
0452:                            logger.log(record);
0453:                        }
0454:                    }
0455:
0456:                    //create the DefaultWebApp by copying from the extracted jar
0457:                    FileUtil.copyDir(tmpDefWebAppPath + fs + "_apps_" + fs
0458:                            + defWebApp, appDir + fs + defWebApp);
0459:
0460:                    //clean up temp dir
0461:                    FileUtil.deleteDir(tmpDefWebAppPath);
0462:                }
0463:
0464:                //Creating links for help, voice to webcontainer docs
0465:                String docsDir = appDir + fs + defWebApp;
0466:                String helpDirStr = docsDir + fs + "online_help" + fs
0467:                        + "docs_en_US";
0468:                File helpDir = new File(helpDirStr);
0469:                if (!helpDir.exists())
0470:                    helpDir.mkdirs();
0471:                String psHelpDir = configContext.getPSBaseDir() + fs + "docs"
0472:                        + fs + "public_html" + fs + "online_help" + fs
0473:                        + "docs_en_US";
0474:                String voiceDir = configContext.getPSBaseDir() + fs + "export"
0475:                        + fs + "voice";
0476:
0477:                OSTasks osTasks = OSTasksFactory.getOSTasks(configContext);
0478:                osTasks.createSymbolicLink(voiceDir, docsDir);
0479:                osTasks.createSymbolicLink(psHelpDir + fs + "ps", helpDirStr);
0480:                osTasks.createSymbolicLink(psHelpDir + fs + "ma", helpDirStr);
0481:
0482:                ////Store the psconfig directory. We need it later.
0483:                //logger.log(Level.FINEST, "PSFB_CSPFT0064");
0484:                psBaseDir = configContext.getPSBaseDir();
0485:            }
0486:
0487:            public boolean setNativeLibraryPath(String path) {
0488:                try {
0489:                    String retStr = FileUtil.findTextInFile(wcConfigfile,
0490:                            "LD_LIBRARY_PATH=");
0491:                    if (retStr != null && retStr.equals("")) {
0492:
0493:                        FileUtil.appendLineInFile(wcConfigfile, "SERVER_NAME=",
0494:                                "LD_LIBRARY_PATH=" + path);
0495:                        FileUtil.appendLineInFile(wcConfigfile,
0496:                                "LD_LIBRARY_PATH=", "export LD_LIBRARY_PATH");
0497:
0498:                    } else {
0499:                        //check if the path is already there
0500:                        if (retStr != null && retStr.indexOf(path) > 0) {
0501:                            return true;
0502:                        }
0503:                        FileUtil.replaceTokenInFile(wcConfigfile,
0504:                                "LD_LIBRARY_PATH=", "LD_LIBRARY_PATH=" + path
0505:                                        + cps);
0506:                    }
0507:                } catch (Exception e) {
0508:                    if (logger.isLoggable(Level.SEVERE)) {
0509:                        LogRecord record = new LogRecord(Level.SEVERE,
0510:                                "PSFB_CSPFT0027");
0511:                        record.setThrown(e);
0512:                        record.setLoggerName(logger.getName());
0513:                        logger.log(record);
0514:                    }
0515:                    return false;
0516:                }
0517:                return true;
0518:            }
0519:
0520:            /**
0521:             * Check if container has been configured for portal
0522:             * in the case of Admin Server
0523:             */
0524:            public boolean isPortalConfigured() {
0525:                if (!wcManagedServer) {
0526:                    String str = FileUtil.findTextInFile(wcConfigfile,
0527:                            "PS_CLASS_PATH=");
0528:                    if (str != null && !str.equals("")
0529:                            && str.indexOf(PORTAL_TEST_JAR) >= 0) {
0530:                        logger.log(Level.INFO, "PSFB_CSPFT0041");
0531:                        return true;
0532:                    }
0533:                } else {
0534:                    String str = FileUtil.findTextInFile(wcConfigfile,
0535:                            "PS_PORTAL_ID_" + wcTargetInstance + "=");
0536:                    if (str != null && !str.equals("")) {
0537:                        return true;
0538:                    }
0539:                }
0540:                return false;
0541:            }
0542:
0543:            /**
0544:             * Add string to classpath path
0545:             */
0546:            public boolean appendClasspath(String classPath) {
0547:                logger.log(Level.FINEST, "PSFB_CSPFT0072");
0548:                String str = FileUtil.findTextInFile(wcConfigfile,
0549:                        "PS_CLASS_PATH=");
0550:
0551:                if (str != null && !str.equals("")) {
0552:                    String serverCP = FileUtil.getQuotedKeyValueInText(
0553:                            "PS_CLASS_PATH", str);
0554:                    //filter out entries in classPath that already occour in serverCP
0555:                    String filteredClassPath = getFilteredClassPath(classPath,
0556:                            serverCP);
0557:                    FileUtil.replaceTokenInFile(wcConfigfile,
0558:                            "PS_CLASS_PATH=\"", "PS_CLASS_PATH=\""
0559:                                    + filteredClassPath + ":");
0560:                } else {
0561:                    FileUtil.appendLineInFile(wcConfigfile, "SERVER_NAME=",
0562:                            "PS_CLASS_PATH=\"" + classPath + "\"",
0563:                            FileUtil.APPEND_FIRST_OCCURANCE_STARTING_WITH);
0564:                }
0565:
0566:                //Okay, we are here, so PS_CLASSPATH is properly set.
0567:                // Now, see it it also occurs in the CLASSPATH.
0568:                str = FileUtil.findTextInFile(wcConfigfile, "CLASSPATH=");
0569:                if (str != null && !str.equals("")) {
0570:                    if (str.indexOf("$PS_CLASS_PATH") == -1) {
0571:                        if ((str.endsWith("\"")))
0572:                            str = str.substring(0, str.length() - 1) + cps
0573:                                    + "$PS_CLASS_PATH" + "\"";
0574:                        else
0575:                            str = str + cps + "$PS_CLASS_PATH";
0576:
0577:                        FileUtil.deleteLineInFile(wcConfigfile, "CLASSPATH=",
0578:                                FileUtil.DELETE_FIRST_OCCURANCE_STARTING_WITH);
0579:                        FileUtil.appendLineInFile(wcConfigfile,
0580:                                "PS_CLASS_PATH=", "\n" + str,
0581:                                FileUtil.APPEND_FIRST_OCCURANCE_STARTING_WITH);
0582:                    }
0583:                } else {
0584:                    FileUtil.appendLineInFile(wcConfigfile, "PS_CLASS_PATH=",
0585:                            "CLASSPATH=\"" + "$PS_CLASS_PATH" + "\"",
0586:                            FileUtil.APPEND_FIRST_OCCURANCE_STARTING_WITH);
0587:                }
0588:
0589:                //Store the classpath. We need it in misctasks.
0590:                psClassPath = classPath;
0591:                return true;
0592:            }
0593:
0594:            private void prepareWebLogicServerStartClasspath(String psClassPath) {
0595:                logger.log(Level.FINEST, "PSFB_CSPFT0071");
0596:                //For Admin Server the deploy is a manual step and we cannot prep the admin server
0597:                //server start classpath. Weblogic MBeans don't support this.
0598:                if (wcManagedServer == false)
0599:                    return;
0600:
0601:                //Set the AMClasspath. We need it for weblogic server start classpath setting.
0602:                computeAMClassPath(psBaseDir);
0603:                //This has to be done using weblogic jdk only.
0604:                String command = wcJDKDir + fs + "bin" + fs + "java";
0605:                String[] args = new String[11];
0606:                args[0] = "-cp";
0607:                args[1] = "." + cps + wcHomeDir + fs + "server" + fs + "lib"
0608:                        + fs + "weblogic.jar" + cps + psBaseDir + fs + "lib"
0609:                        + fs + "fabric.jar" + cps + psBaseDir + fs + "lib" + fs
0610:                        + "config.jar" + cps + psBaseDir + fs + "lib" + fs
0611:                        + "pslogcommon.jar";
0612:                args[2] = "com.sun.portal.fabric.tasks.WeblogicServerHelper";
0613:                args[3] = "-method";
0614:                args[4] = "setManagedServerClasspath";
0615:                args[5] = "-params";
0616:                args[6] = "t3://" + wcAdminHost + ":" + wcAdminPort;
0617:                args[7] = wcAdminUser;
0618:                args[8] = wcAdminPassword;
0619:                args[9] = wcTargetInstance;
0620:                args[10] = wcHomeDir + fs + "server" + fs + "lib" + fs
0621:                        + "weblogic.jar" + cps + psClassPath + cps + psBaseDir
0622:                        + fs + "web-src" + fs + "WEB-INF" + fs + "lib" + fs
0623:                        + "log4j-1.2.8.jar" + cps + AM_CLASSPATH;
0624:                execUtil.storeOutput(true);
0625:                execUtil.exec(command, args);
0626:
0627:                logger.log(Level.FINEST, "PSFB_CSPFT0050", new String[] {
0628:                        "Classpath for Weblogic Server Helper", args[1] });
0629:                logger.log(Level.FINEST, "PSFB_CSPFT0050", new String[] {
0630:                        "Prepare start-stop output", execUtil.getOutput() });
0631:            }
0632:
0633:            private void removeWebLogicServerStartClasspath() {
0634:                //logger.log(Level.FINEST, "PSFB_CSPFT0071");
0635:                //For Admin Server the deploy is a manual step and we cannot prep the admin server
0636:                //server start classpath. Weblogic MBeans don't support this.
0637:                if (wcManagedServer == false)
0638:                    return;
0639:                if (psBaseDir == null) {
0640:                    try {
0641:                        ResourceLoader rl = ResourceLoader.getInstance();
0642:                        Properties prop = rl.getProperties(PS_CONFIG_FILE);
0643:                        psBaseDir = prop.getProperty(PS_BASE_DIR);
0644:                    } catch (IOException e) {
0645:                        logger
0646:                                .log(Level.FINEST, "PSFB_CSPFT0335",
0647:                                        new String[] { "File Not Found",
0648:                                                PS_CONFIG_FILE });
0649:                    }
0650:                }
0651:                //This has to be done using weblogic jdk only.
0652:                String command = wcJDKDir + fs + "bin" + fs + "java";
0653:                String[] args = new String[10];
0654:                args[0] = "-cp";
0655:                args[1] = "." + cps + wcHomeDir + fs + "server" + fs + "lib"
0656:                        + fs + "weblogic.jar" + cps + psBaseDir + fs + "lib"
0657:                        + fs + "fabric.jar" + cps + psBaseDir + fs + "lib" + fs
0658:                        + "config.jar" + cps + psBaseDir + fs + "lib" + fs
0659:                        + "pslogcommon.jar";
0660:                args[2] = "com.sun.portal.fabric.tasks.WeblogicServerHelper";
0661:                args[3] = "-method";
0662:                args[4] = "removeManagedServerClasspath";
0663:                args[5] = "-params";
0664:                args[6] = "t3://" + wcAdminHost + ":" + wcAdminPort;
0665:                args[7] = wcAdminUser;
0666:                args[8] = wcAdminPassword;
0667:                args[9] = wcTargetInstance;
0668:                execUtil.storeOutput(true);
0669:                execUtil.exec(command, args);
0670:
0671:                logger.log(Level.FINEST, "PSFB_CSPFT0050", new String[] {
0672:                        "Classpath for Weblogic Server Helper", args[1] });
0673:                logger.log(Level.FINEST, "PSFB_CSPFT0050", new String[] {
0674:                        "Prepare start-stop output", execUtil.getOutput() });
0675:            }
0676:
0677:            private void prepareWebLogicServerStartArguments() {
0678:                logger.log(Level.FINEST, "PSFB_CSPFT0334");
0679:                //For Admin Server the deploy is a manual step and we cannot prep the admin server
0680:                //server start classpath. Weblogic MBeans don't support this.
0681:                if (wcManagedServer == false)
0682:                    return;
0683:
0684:                String jvmOptions = FileUtil.findTextInFile(wcConfigfile,
0685:                        "IS_OPTIONS=");
0686:                if (jvmOptions != null) {
0687:                    //if the string is enclosed in double-quotes
0688:                    if (jvmOptions.indexOf('"') > 0)
0689:                        jvmOptions = jvmOptions.substring(jvmOptions
0690:                                .indexOf('"') + 1, jvmOptions.lastIndexOf('"'));
0691:                    else
0692:                        jvmOptions = jvmOptions.substring(jvmOptions
0693:                                .indexOf('='));
0694:                }
0695:
0696:                //Set the AMClasspath. We need it for weblogic server start classpath setting.
0697:                computeAMClassPath(psBaseDir);
0698:                //This has to be done using weblogic jdk only.
0699:                String command = wcJDKDir + fs + "bin" + fs + "java";
0700:                String[] args = new String[11];
0701:                args[0] = "-cp";
0702:                args[1] = "." + cps + wcHomeDir + fs + "server" + fs + "lib"
0703:                        + fs + "weblogic.jar" + cps + psBaseDir + fs + "lib"
0704:                        + fs + "fabric.jar" + cps + psBaseDir + fs + "lib" + fs
0705:                        + "config.jar" + cps + psBaseDir + fs + "lib" + fs
0706:                        + "pslogcommon.jar";
0707:                args[2] = "com.sun.portal.fabric.tasks.WeblogicServerHelper";
0708:                args[3] = "-method";
0709:                args[4] = "setManagedServerArguments";
0710:                args[5] = "-params";
0711:                args[6] = "t3://" + wcAdminHost + ":" + wcAdminPort;
0712:                args[7] = wcAdminUser;
0713:                args[8] = wcAdminPassword;
0714:                args[9] = wcTargetInstance;
0715:                args[10] = "\"" + jvmOptions + "\"";
0716:                execUtil.storeOutput(true);
0717:                execUtil.exec(command, args);
0718:
0719:                logger.log(Level.FINEST, "PSFB_CSPFT0050", new String[] {
0720:                        "Classpath for Weblogic Server Helper", args[1] });
0721:                logger.log(Level.FINEST, "PSFB_CSPFT0050", new String[] {
0722:                        "Prepare start-stop arguments output",
0723:                        execUtil.getOutput() });
0724:            }
0725:
0726:            private void removeWebLogicServerStartArguments() {
0727:                String command = wcJDKDir + fs + "bin" + fs + "java";
0728:                String[] args = new String[10];
0729:                if (psBaseDir == null) {
0730:                    try {
0731:                        ResourceLoader rl = ResourceLoader.getInstance();
0732:                        Properties prop = rl.getProperties(PS_CONFIG_FILE);
0733:                        psBaseDir = prop.getProperty(PS_BASE_DIR);
0734:                    } catch (IOException e) {
0735:                        logger
0736:                                .log(Level.FINEST, "PSFB_CSPFT0335",
0737:                                        new String[] { "File Not Found",
0738:                                                PS_CONFIG_FILE });
0739:                    }
0740:                }
0741:                args[0] = "-cp";
0742:                args[1] = "." + cps + wcHomeDir + fs + "server" + fs + "lib"
0743:                        + fs + "weblogic.jar" + cps + psBaseDir + fs + "lib"
0744:                        + fs + "fabric.jar" + cps + psBaseDir + fs + "lib" + fs
0745:                        + "config.jar" + cps + psBaseDir + fs + "lib" + fs
0746:                        + "pslogcommon.jar";
0747:                args[2] = "com.sun.portal.fabric.tasks.WeblogicServerHelper";
0748:                args[3] = "-method";
0749:                args[4] = "removeManagedServerArguments";
0750:                args[5] = "-params";
0751:                args[6] = "t3://" + wcAdminHost + ":" + wcAdminPort;
0752:                args[7] = wcAdminUser;
0753:                args[8] = wcAdminPassword;
0754:                args[9] = wcTargetInstance;
0755:                execUtil.storeOutput(true);
0756:                execUtil.exec(command, args);
0757:
0758:                logger.log(Level.FINEST, "PSFB_CSPFT0050", new String[] {
0759:                        "Classpath for Weblogic Server Helper", args[1] });
0760:            }
0761:
0762:            //Method to set the jvm options related to portal
0763:            private void setPortalJVMOptions(String jvmOptions) {
0764:                String command = wcJDKDir + fs + "bin" + fs + "java";
0765:                String[] args = new String[11];
0766:                if (psBaseDir == null) {
0767:                    try {
0768:                        ResourceLoader rl = ResourceLoader.getInstance();
0769:                        Properties prop = rl.getProperties(PS_CONFIG_FILE);
0770:                        psBaseDir = prop.getProperty(PS_BASE_DIR);
0771:                    } catch (IOException e) {
0772:                        logger
0773:                                .log(Level.FINEST, "PSFB_CSPFT0335",
0774:                                        new String[] { "File Not Found",
0775:                                                PS_CONFIG_FILE });
0776:                    }
0777:                }
0778:                args[0] = "-cp";
0779:                args[1] = "." + cps + wcHomeDir + fs + "server" + fs + "lib"
0780:                        + fs + "weblogic.jar" + cps + psBaseDir + fs + "lib"
0781:                        + fs + "fabric.jar" + cps + psBaseDir + fs + "lib" + fs
0782:                        + "config.jar" + cps + psBaseDir + fs + "lib" + fs
0783:                        + "pslogcommon.jar";
0784:                args[2] = "com.sun.portal.fabric.tasks.WeblogicServerHelper";
0785:                args[3] = "-method";
0786:                args[4] = "setManagedServerArguments";
0787:                args[5] = "-params";
0788:                args[6] = "t3://" + wcAdminHost + ":" + wcAdminPort;
0789:                args[7] = wcAdminUser;
0790:                args[8] = wcAdminPassword;
0791:                args[9] = wcTargetInstance;
0792:                args[10] = "\"" + jvmOptions + "\"";
0793:                execUtil.storeOutput(true);
0794:                execUtil.exec(command, args);
0795:
0796:                logger.log(Level.FINEST, "PSFB_CSPFT0050", new String[] {
0797:                        "Classpath for Weblogic Server Helper", args[1] });
0798:                logger.log(Level.FINEST, "PSFB_CSPFT0050", new String[] {
0799:                        "Set Portal jvm arguments", jvmOptions });
0800:            }
0801:
0802:            private boolean createJVMOptionVariables(String option, String value) {
0803:                boolean success = false;
0804:
0805:                String strID = "";
0806:                if (option.equals(PORTAL_ID))
0807:                    strID = "PS_PORTAL_ID_";
0808:                else if (option.equals(INSTANCE_ID))
0809:                    strID = "PS_INSTANCE_ID_";
0810:
0811:                //First see if we already have the desired entry. That is  <wcTargetInstance>_PORTAL_ID=id
0812:                //If present simply come out
0813:                String str = FileUtil.findTextInFile(wcConfigfile, strID
0814:                        + wcTargetInstance + "=" + value);
0815:                if (str != null && !str.equals("")) {
0816:                    return success;
0817:                }
0818:                //If we are here it means the exact entry we want to put isn't there.
0819:                // Then see if we atleast have the variable, possibly set with a different value.
0820:                str = FileUtil.findTextInFile(wcConfigfile, strID
0821:                        + wcTargetInstance + "=");
0822:                if (str != null && !str.equals("")) {
0823:                    if (str.indexOf(value) == -1) {
0824:                        FileUtil.deleteLineInFile(wcConfigfile, strID
0825:                                + wcTargetInstance + "=");
0826:                        //Add the PS_OPTIONS only below the first occurance of line starting with
0827:                        // the SERVER_NAME
0828:                        success = FileUtil.appendLineInFile(wcConfigfile,
0829:                                "ADMIN_URL=", strID + wcTargetInstance + "="
0830:                                        + value,
0831:                                FileUtil.APPEND_FIRST_OCCURANCE_STARTING_WITH);
0832:                    }
0833:                } else {
0834:                    success = FileUtil.appendLineInFile(wcConfigfile,
0835:                            "ADMIN_URL=", strID + wcTargetInstance + "="
0836:                                    + value,
0837:                            FileUtil.APPEND_FIRST_OCCURANCE_STARTING_WITH);
0838:                }
0839:                return success;
0840:
0841:            }
0842:
0843:            /**
0844:             * Add string to PS_OPTIONS
0845:             */
0846:            public boolean addJVMOption(String option, String value) {
0847:                boolean success = false;
0848:
0849:                //Replace the portalID and InstanceId in the value with the $variable for weblogic.
0850:                String modifiedValue = value;
0851:
0852:                //The regex replace has problems. So using the String concatenation.
0853:                //The following block is to support multiple instances.
0854:                if (wcManagedServer == true
0855:                        && (option.equals(PORTAL_ID) || option
0856:                                .equals(INSTANCE_ID))) {
0857:                    int idx = value.indexOf(portalID);
0858:                    if (idx != -1)
0859:                        modifiedValue = value.substring(0, idx)
0860:                                + "`eval echo \\\\$PS_PORTAL_ID_${1}`";//+value.substring(idx+portalID.length()-1);
0861:                    idx = modifiedValue.indexOf(instanceID);
0862:                    if (idx != -1)
0863:                        modifiedValue = modifiedValue.substring(0, idx)
0864:                                + "`eval echo \\\\$PS_INSTANCE_ID_${1}`";//+value.substring(idx+instanceID.length()-1);
0865:
0866:                    //Calling these methods here may be avoided. They need to called only once.
0867:                    if (option.equals(PORTAL_ID))
0868:                        createJVMOptionVariables(PORTAL_ID, portalID);
0869:                    if (option.equals(INSTANCE_ID))
0870:                        createJVMOptionVariables(INSTANCE_ID, instanceID);
0871:
0872:                }
0873:                //The variable that holds the value to see if we have the PS javaoptions already
0874:                //inside PS_OPTIONS
0875:                String optionValuePair = "-D" + option + "=" + modifiedValue;
0876:
0877:                String str = FileUtil.findPatternInFile(wcConfigfile,
0878:                        "^\\s*[^#]*\\s*PS_OPTIONS=.*");
0879:                if (str != null && !str.equals("")) {
0880:                    if (str.indexOf(optionValuePair) == -1) {
0881:                        optionValuePair = str.substring(str.indexOf("\"") + 1,
0882:                                str.length() - 1)
0883:                                + " " + optionValuePair;
0884:                        FileUtil.deleteLineInFile(wcConfigfile, "PS_OPTIONS=");
0885:                        //Add the PS_OPTIONS only below the first occurance of line starting with
0886:                        // the SERVER_NAME
0887:                        success = FileUtil.appendLineInFile(wcConfigfile,
0888:                                "SERVER_NAME=", "PS_OPTIONS=\""
0889:                                        + optionValuePair + "\"",
0890:                                FileUtil.APPEND_FIRST_OCCURANCE_STARTING_WITH);
0891:                    }
0892:                } else {
0893:                    //Add the PS_OPTIONS only below the first occurance of line starting with
0894:                    // the SERVER_NAME
0895:                    success = FileUtil.appendLineInFile(wcConfigfile,
0896:                            "SERVER_NAME=", "PS_OPTIONS=\"" + optionValuePair
0897:                                    + "\"",
0898:                            FileUtil.APPEND_FIRST_OCCURANCE_STARTING_WITH);
0899:                }
0900:
0901:                if (option.equals(PORTAL_ID)) {
0902:                    optionValuePair = "-D" + option + "=" + portalID;
0903:                } else {
0904:                    if (option.equals(INSTANCE_ID)) {
0905:                        optionValuePair = "-D" + option + "=" + instanceID;
0906:                    } else {
0907:                        optionValuePair = "-D" + option + "=" + modifiedValue;
0908:                    }
0909:                }
0910:                if (wcManagedServer) {
0911:                    String sr = FileUtil.findTextInFile(wcConfigfile,
0912:                            "$JAVA_HOME/bin/java");
0913:                    if (sr != null && !sr.equals("")) {
0914:                        if (sr.indexOf("${PS_OPTIONS}") == -1
0915:                                && sr.indexOf("\\") >= 0) {
0916:                            sr = sr.substring(0, sr.indexOf("\\") - 1)
0917:                                    + " ${PS_OPTIONS}" + " \\";
0918:                            FileUtil.replaceLineInFile(wcConfigfile,
0919:                                    "$JAVA_HOME/bin/java", sr);
0920:                        }
0921:                    }
0922:                } else {
0923:                    String sr = FileUtil.findTextInFile(wcConfigfile,
0924:                            "${JAVA_HOME}/bin/java");
0925:                    if (sr != null && !sr.equals("")) {
0926:                        if (sr.indexOf("${PS_OPTIONS}") == -1
0927:                                && sr.indexOf("-Dweblogic") >= 0) {
0928:                            sr = sr.substring(0, sr.indexOf("-Dweblogic") - 1)
0929:                                    + " ${PS_OPTIONS} "
0930:                                    + sr.substring(sr.indexOf("-Dweblogic"));
0931:                            FileUtil.replaceLineInFile(wcConfigfile,
0932:                                    "${JAVA_HOME}/bin/java", sr);
0933:                        }
0934:                    }
0935:                }
0936:                setPortalJVMOptions(optionValuePair);
0937:                return success;
0938:            }
0939:
0940:            public void removeJarFromClassPath(String jarToRemove)
0941:                    throws ConfigurationException {
0942:                File wlFile = new File(wcInstanceDir + fs + "startWebLogic.sh");
0943:                File wlFileManaged = new File(wcInstanceDir + fs
0944:                        + "startManagedWebLogic.sh");
0945:                boolean wlFileExists = wlFile.exists();
0946:                boolean wlFileManagedExists = wlFileManaged.exists();
0947:                StringTokenizer st = new StringTokenizer(jarToRemove, cps);
0948:
0949:                //Remove the individual jars one by one.
0950:                while (st.hasMoreTokens()) {
0951:                    if (wlFileExists) {
0952:                        removeJarFromClassPath(wlFile, st.nextToken());
0953:                    }
0954:                    if (wlFileManagedExists) {
0955:                        removeJarFromClassPath(wlFileManaged, st.nextToken());
0956:                    }
0957:                }
0958:            }
0959:
0960:            private void removeJarFromClassPath(File wlFile, String jarPath)
0961:                    throws ConfigurationException {
0962:                try {
0963:                    String retStr = FileUtil.findTextInFile(wlFile, jarPath);
0964:                    if (retStr != null && !retStr.equals("")) {
0965:                        FileUtil.replaceTokenInFile(wlFile, jarPath + cps, "");
0966:                    }
0967:                } catch (Exception ioe) {
0968:                    throw new ConfigurationException(ioe.toString());
0969:                }
0970:            }
0971:
0972:            public void doMiscTasks(PSConfigContext configContext) {
0973:                logger.log(Level.FINEST, "PSFB_CSPFT0065");
0974:                //   WebLogicConfigWorkarounds() from wcconfig
0975:
0976:                File bsOrigFile = new File(configContext.getPSConfigDir() + fs
0977:                        + "bootstrapSystem.properties-orig");
0978:
0979:                if (!bsOrigFile.exists()) {
0980:                    try {
0981:                        FileUtil.copyFile(new File(configContext
0982:                                .getPSConfigDir()
0983:                                + fs + "bootstrapSystem.properties"),
0984:                                bsOrigFile, true);
0985:                    } catch (Exception e) {
0986:                        e.printStackTrace();
0987:                    }
0988:                }
0989:
0990:                try {
0991:                    FileUtil.copyFile(new File(configContext.getPSConfigDir()
0992:                            + fs + "WEBLOGIC.bootstrapSystem.properties"),
0993:                            new File(configContext.getPSConfigDir() + fs
0994:                                    + "bootstrapSystem.properties"));
0995:                } catch (Exception e) {
0996:                    e.printStackTrace();
0997:                }
0998:
0999:                prepareWebLogicServerStartClasspath(psClassPath);
1000:                prepareWebLogicServerStartArguments();
1001:                String memOptions = "-Xms256m -Xmx512m -Xss128k -XX:NewSize=168M -XX:MaxNewSize=168M -XX:PermSize=192M -XX:SoftRefLRUPolicyMSPerMB=0";
1002:                setPortalJVMOptions(memOptions);
1003:            }
1004:
1005:            public void configResource(Element root, String derbyHost,
1006:                    String derbyPort, String databaseName, String poolName) {
1007:
1008:                createConnectionPool(root, poolName);
1009:                createResource(root, poolName);
1010:            }
1011:
1012:            private void createConnectionPool(Element root, String poolName) {
1013:
1014:                String[] args = new String[12];
1015:                String command = wcJDKDir + fs + "bin" + fs + "java";
1016:
1017:                args[0] = "-cp";
1018:                args[1] = wcHomeDir + fs + "server" + fs + "lib" + fs
1019:                        + "weblogic.jar";
1020:                args[2] = "weblogic.Admin";
1021:                args[3] = "-adminurl";
1022:                args[4] = "t3://" + wcAdminHost + ":" + wcAdminPort;
1023:                args[5] = "-username";
1024:                args[6] = wcAdminUser;
1025:                args[7] = "-password";
1026:                args[8] = wcAdminPassword;
1027:                args[9] = "CREATE_POOL";
1028:                args[10] = poolName;
1029:                args[11] = "url=" + root.getAttributeValue("url") + ","
1030:                        + "driver=" + root.getAttributeValue("driverClassName")
1031:                        + "," + "maxCapacity="
1032:                        + root.getAttributeValue("maxActive") + ","
1033:                        + "props=user=" + root.getAttributeValue("username")
1034:                        + ";" + "password="
1035:                        + root.getAttributeValue("password");
1036:
1037:                execUtil.storeOutput(true);
1038:                execUtil.exec(command, args);
1039:                logger
1040:                        .log(Level.FINEST, "PSFB_CSPFT0088", execUtil
1041:                                .getOutput());
1042:
1043:                setTargetsToConnectionPool();
1044:            }
1045:
1046:            private void createResource(Element root, String poolName) {
1047:
1048:                String[] args = new String[12];
1049:                String command = wcJDKDir + fs + "bin" + fs + "java";
1050:                int endIndx = poolName.indexOf("Pool");
1051:                String resourceName = poolName.substring(0, endIndx);
1052:
1053:                args[0] = "-cp";
1054:                args[1] = wcHomeDir + fs + "server" + fs + "lib" + fs
1055:                        + "weblogic.jar";
1056:                args[2] = "weblogic.Admin";
1057:                args[3] = "-adminurl";
1058:                args[4] = "t3://" + wcAdminHost + ":" + wcAdminPort;
1059:                args[5] = "-username";
1060:                args[6] = wcAdminUser;
1061:                args[7] = "-password";
1062:                args[8] = wcAdminPassword;
1063:                args[9] = "CREATE";
1064:                args[10] = "-mbean";
1065:                args[11] = wcDomain + ":Name=" + resourceName
1066:                        + ",Type=JDBCTxDataSource";
1067:
1068:                execUtil.storeOutput(true);
1069:                execUtil.exec(command, args);
1070:                logger
1071:                        .log(Level.FINEST, "PSFB_CSPFT0090", execUtil
1072:                                .getOutput());
1073:
1074:                String[] args1 = new String[18];
1075:
1076:                args1[0] = "-cp";
1077:                args1[1] = wcHomeDir + fs + "server" + fs + "lib" + fs
1078:                        + "weblogic.jar";
1079:                args1[2] = "weblogic.Admin";
1080:                args1[3] = "-adminurl";
1081:                args1[4] = "t3://" + wcAdminHost + ":" + wcAdminPort;
1082:                args1[5] = "-username";
1083:                args1[6] = wcAdminUser;
1084:                args1[7] = "-password";
1085:                args1[8] = wcAdminPassword;
1086:                args1[9] = "SET";
1087:                args1[10] = "-mbean";
1088:                args1[11] = wcDomain + ":Name=" + resourceName
1089:                        + ",Type=JDBCTxDataSource";
1090:                args1[12] = "-property";
1091:                args1[13] = "PoolName";
1092:                args1[14] = "\"" + poolName + "\"";
1093:                args1[15] = "-property";
1094:                args1[16] = "JNDIName";
1095:                args1[17] = "\"" + root.getAttributeValue("name") + "\"";
1096:
1097:                execUtil.storeOutput(true);
1098:                execUtil.exec(command, args1);
1099:                logger
1100:                        .log(Level.FINEST, "PSFB_CSPFT0091", execUtil
1101:                                .getOutput());
1102:
1103:                setTargetsToDatasource(root.getAttributeValue("name"));
1104:            }
1105:
1106:            private void setTargetsToConnectionPool() {
1107:
1108:                //This has to be done using weblogic jdk only.
1109:                String command = wcJDKDir + fs + "bin" + fs + "java";
1110:                String[] args = new String[10];
1111:                args[0] = "-cp";
1112:                args[1] = "." + cps + wcHomeDir + fs + "server" + fs + "lib"
1113:                        + fs + "weblogic.jar" + cps + psLibDir + fs
1114:                        + "fabric.jar" + cps + psLibDir + fs + "config.jar"
1115:                        + cps + psLibDir + fs + "pslogcommon.jar";
1116:                args[2] = "com.sun.portal.fabric.tasks.WeblogicServerHelper";
1117:                args[3] = "-method";
1118:                args[4] = "setTargetsToConnectionPools";
1119:                args[5] = "-params";
1120:                args[6] = "t3://" + wcAdminHost + ":" + wcAdminPort;
1121:                args[7] = wcAdminUser;
1122:                args[8] = wcAdminPassword;
1123:                args[9] = wcTargetInstance;
1124:                execUtil.storeOutput(true);
1125:                execUtil.exec(command, args);
1126:
1127:                logger
1128:                        .log(Level.FINEST, "PSFB_CSPFT0100", execUtil
1129:                                .getOutput());
1130:                logger.log(Level.FINEST, "PSFB_CSPFT0050", new String[] {
1131:                        "Classpath for Weblogic Server Helper", args[1] });
1132:            }
1133:
1134:            private void setTargetsToDatasource(String jndiName) {
1135:
1136:                //This has to be done using weblogic jdk only.
1137:                String command = wcJDKDir + fs + "bin" + fs + "java";
1138:                String[] args = new String[11];
1139:                args[0] = "-cp";
1140:                args[1] = "." + cps + wcHomeDir + fs + "server" + fs + "lib"
1141:                        + fs + "weblogic.jar" + cps + psLibDir + fs
1142:                        + "fabric.jar" + cps + psLibDir + fs + "config.jar"
1143:                        + cps + psLibDir + fs + "pslogcommon.jar";
1144:                args[2] = "com.sun.portal.fabric.tasks.WeblogicServerHelper";
1145:                args[3] = "-method";
1146:                args[4] = "setTargetsToDatasources";
1147:                args[5] = "-params";
1148:                args[6] = "t3://" + wcAdminHost + ":" + wcAdminPort;
1149:                args[7] = wcAdminUser;
1150:                args[8] = wcAdminPassword;
1151:                args[9] = wcTargetInstance;
1152:                args[10] = jndiName;
1153:                execUtil.storeOutput(true);
1154:                execUtil.exec(command, args);
1155:
1156:                logger
1157:                        .log(Level.FINEST, "PSFB_CSPFT0100", execUtil
1158:                                .getOutput());
1159:                logger.log(Level.FINEST, "PSFB_CSPFT0050", new String[] {
1160:                        "Classpath for Weblogic Server Helper", args[1] });
1161:            }
1162:
1163:            public void unConfigResource(String jndiName, String poolName) {
1164:                removeTargetsToConnectionPool();
1165:                removeTargetsToDatasource(jndiName);
1166:            }
1167:
1168:            private void removeConnectionPool(String poolName) {
1169:                logger.log(Level.INFO, "Removing ConnectionPool:", poolName);
1170:                removeTargetsToConnectionPool();
1171:                String[] args = new String[12];
1172:                String command = wcJDKDir + fs + "bin" + fs + "java";
1173:
1174:                args[0] = "-cp";
1175:                args[1] = wcHomeDir + fs + "server" + fs + "lib" + fs
1176:                        + "weblogic.jar";
1177:                args[2] = "weblogic.Admin";
1178:                args[3] = "-adminurl";
1179:                args[4] = "t3://" + wcAdminHost + ":" + wcAdminPort;
1180:                args[5] = "-username";
1181:                args[6] = wcAdminUser;
1182:                args[7] = "-password";
1183:                args[8] = wcAdminPassword;
1184:                args[9] = "DELETE_POOL";
1185:                args[10] = "-poolName";
1186:                args[11] = poolName;
1187:                execUtil.storeOutput(true);
1188:                execUtil.exec(command, args);
1189:                logger
1190:                        .log(Level.FINEST, "PSFB_CSPFT0340", execUtil
1191:                                .getOutput());
1192:
1193:            }
1194:
1195:            private void removeResource(String poolName, String jndiName) {
1196:
1197:                removeTargetsToDatasource(jndiName);
1198:                String[] args = new String[12];
1199:                String command = wcJDKDir + fs + "bin" + fs + "java";
1200:                int endIndx = poolName.indexOf("Pool");
1201:                String resourceName = poolName.substring(0, endIndx);
1202:
1203:                args[0] = "-cp";
1204:                args[1] = wcHomeDir + fs + "server" + fs + "lib" + fs
1205:                        + "weblogic.jar";
1206:                args[2] = "weblogic.Admin";
1207:                args[3] = "-adminurl";
1208:                args[4] = "t3://" + wcAdminHost + ":" + wcAdminPort;
1209:                args[5] = "-username";
1210:                args[6] = wcAdminUser;
1211:                args[7] = "-password";
1212:                args[8] = wcAdminPassword;
1213:                args[9] = "DELETE";
1214:                args[10] = "-mbean";
1215:                args[11] = wcDomain + ":Name=" + resourceName
1216:                        + ",Type=JDBCTxDataSource";
1217:
1218:                execUtil.storeOutput(true);
1219:                execUtil.exec(command, args);
1220:                logger
1221:                        .log(Level.FINEST, "PSFB_CSPFT0339", execUtil
1222:                                .getOutput());
1223:            }
1224:
1225:            private void removeTargetsToConnectionPool() {
1226:
1227:                //This has to be done using weblogic jdk only.
1228:                String command = wcJDKDir + fs + "bin" + fs + "java";
1229:                String[] args = new String[10];
1230:                args[0] = "-cp";
1231:                args[1] = "." + cps + wcHomeDir + fs + "server" + fs + "lib"
1232:                        + fs + "weblogic.jar" + cps + psLibDir + fs
1233:                        + "fabric.jar" + cps + psLibDir + fs + "config.jar"
1234:                        + cps + psLibDir + fs + "pslogcommon.jar";
1235:                args[2] = "com.sun.portal.fabric.tasks.WeblogicServerHelper";
1236:                args[3] = "-method";
1237:                args[4] = "removeTargetsToConnectionPools";
1238:                args[5] = "-params";
1239:                args[6] = "t3://" + wcAdminHost + ":" + wcAdminPort;
1240:                args[7] = wcAdminUser;
1241:                args[8] = wcAdminPassword;
1242:                args[9] = wcTargetInstance;
1243:                execUtil.storeOutput(true);
1244:                execUtil.exec(command, args);
1245:
1246:                logger
1247:                        .log(Level.FINEST, "PSFB_CSPFT0338", execUtil
1248:                                .getOutput());
1249:                logger.log(Level.FINEST, "PSFB_CSPFT0050", new String[] {
1250:                        "Classpath for Weblogic Server Helper", args[1] });
1251:            }
1252:
1253:            private void removeTargetsToDatasource(String jndiName) {
1254:
1255:                //This has to be done using weblogic jdk only.
1256:                String command = wcJDKDir + fs + "bin" + fs + "java";
1257:                String[] args = new String[11];
1258:                args[0] = "-cp";
1259:                args[1] = "." + cps + wcHomeDir + fs + "server" + fs + "lib"
1260:                        + fs + "weblogic.jar" + cps + psLibDir + fs
1261:                        + "fabric.jar" + cps + psLibDir + fs + "config.jar"
1262:                        + cps + psLibDir + fs + "pslogcommon.jar";
1263:                args[2] = "com.sun.portal.fabric.tasks.WeblogicServerHelper";
1264:                args[3] = "-method";
1265:                args[4] = "removeTargetsToDatasources";
1266:                args[5] = "-params";
1267:                args[6] = "t3://" + wcAdminHost + ":" + wcAdminPort;
1268:                args[7] = wcAdminUser;
1269:                args[8] = wcAdminPassword;
1270:                args[9] = wcTargetInstance;
1271:                args[10] = jndiName;
1272:                execUtil.storeOutput(true);
1273:                execUtil.exec(command, args);
1274:
1275:                logger
1276:                        .log(Level.FINEST, "PSFB_CSPFT0337", execUtil
1277:                                .getOutput());
1278:                logger.log(Level.FINEST, "PSFB_CSPFT0050", new String[] {
1279:                        "Classpath for Weblogic Server Helper", args[1] });
1280:            }
1281:
1282:            /**
1283:             * Starts the webcontainer instance
1284:             *
1285:             */
1286:            public void start() {
1287:
1288:                logger.log(Level.FINEST, "PSFB_CSPFT0074");
1289:                //If it is Admin server, do not try starting it.
1290:                if (wcManagedServer == false)
1291:                    return;
1292:
1293:                String[] args = new String[11];
1294:                String command = wcJDKDir + fs + "bin" + fs + "java";
1295:
1296:                args[0] = "-cp";
1297:                args[1] = wcHomeDir + fs + "server" + fs + "lib" + fs
1298:                        + "weblogic.jar";
1299:                args[2] = "weblogic.Admin";
1300:                args[3] = "-adminurl";
1301:                args[4] = "t3://" + wcAdminHost + ":" + wcAdminPort;
1302:                args[5] = "-username";
1303:                args[6] = wcAdminUser;
1304:                args[7] = "-password";
1305:                args[8] = wcAdminPassword;
1306:                args[9] = "START";
1307:                args[10] = wcTargetInstance;
1308:
1309:                execUtil.storeOutput(true);
1310:                execUtil.exec(command, args);
1311:                logger.log(Level.FINEST, "PSFB_CSPFT0050", new String[] {
1312:                        "Weblogic Server Start output", execUtil.getOutput() });
1313:            }
1314:
1315:            /**
1316:             * Stops the webcontainer instance
1317:             *
1318:             */
1319:            public void stop() {
1320:
1321:                logger.log(Level.FINEST, "PSFB_CSPFT0075");
1322:                //If it is Admin server, do not try stopping it.
1323:                if (wcManagedServer == false)
1324:                    return;
1325:
1326:                String[] args = new String[11];
1327:                String command = wcJDKDir + fs + "bin" + fs + "java";
1328:                args[0] = "-cp";
1329:                args[1] = wcHomeDir + fs + "server" + fs + "lib" + fs
1330:                        + "weblogic.jar";
1331:                args[2] = "weblogic.Admin";
1332:                args[3] = "-adminurl";
1333:                args[4] = "t3://" + wcAdminHost + ":" + wcAdminPort;
1334:                args[5] = "-username";
1335:                args[6] = wcAdminUser;
1336:                args[7] = "-password";
1337:                args[8] = wcAdminPassword;
1338:                args[9] = "FORCESHUTDOWN";
1339:                args[10] = wcTargetInstance;
1340:
1341:                execUtil.storeOutput(true);
1342:                execUtil.exec(command, args);
1343:                logger.log(Level.FINEST, "PSFB_CSPFT0050", new String[] {
1344:                        "Weblogic Server Stop output", execUtil.getOutput() });
1345:            }
1346:
1347:            /**
1348:             * Validate web container
1349:             */
1350:            public void validate() throws ValidationException {
1351:
1352:                // validate data before calling the constructor
1353:                if (!checkNotNullOrEmpty(WEB_CONTAINER_INSTANCE,
1354:                        wcTargetInstance)) {
1355:
1356:                    throw new ValidationException("Invalid Instance Name");
1357:                }
1358:
1359:                if (!checkNotNull(WEB_CONTAINER_ADMIN_UID, wcAdminUser)) {
1360:
1361:                    throw new ValidationException("Invalid Admin User");
1362:                }
1363:
1364:                if (!checkNotNull(WEB_CONTAINER_ADMIN_PASSWORD,
1365:                        wcAdminPassword, true)) {
1366:
1367:                    throw new ValidationException("Invalid Admin Password");
1368:                }
1369:
1370:                if (!checkNotNullOrEmpty(WEB_CONTAINER_ADMIN_SCHEME,
1371:                        wcAdminProtocol)) {
1372:
1373:                    throw new ValidationException("Invalid Admin Scheme");
1374:                }
1375:
1376:                if (!checkNotNullOrEmpty(WEB_CONTAINER_ADMIN_HOST, wcAdminHost)) {
1377:
1378:                    throw new ValidationException("Invalid Admin Host");
1379:                }
1380:
1381:                if (!checkNotNullOrEmpty(WEB_CONTAINER_ADMIN_PORT, wcAdminPort)) {
1382:
1383:                    throw new ValidationException("Invalid Admin Port");
1384:                }
1385:
1386:                if (!checkNotNullOrEmpty(WEB_CONTAINER_MANAGED_SERVER,
1387:                        wcManagedServerStr)) {
1388:
1389:                    throw new ValidationException(
1390:                            "Invalid Managed Server Status");
1391:                }
1392:
1393:                if (!checkDirExists(WEB_CONTAINER_INSTANCE_DIR, wcInstanceDir)) {
1394:
1395:                    throw new ValidationException(
1396:                            "Invalid Instance Directory = " + wcInstanceDir);
1397:                }
1398:
1399:                if (!checkDirExists(WEB_CONTAINER_INSTALL_DIR, wcHomeDir)) {
1400:
1401:                    throw new ValidationException(
1402:                            "Invalid Install Directory = " + wcHomeDir);
1403:                }
1404:
1405:                if (!checkDirExists(WEB_CONTAINER_JDK_DIR, wcJDKDir)) {
1406:
1407:                    throw new ValidationException("Invalid JDK Directory = "
1408:                            + wcJDKDir);
1409:                }
1410:
1411:                // Validate Instant host & port
1412:                String host = (String) wcAttributes.get(HOST);
1413:                String port = (String) wcAttributes.get(PORT);
1414:                boolean bIsValidHostNamePort = validateInstanceHostNamePort(
1415:                        host, port);
1416:
1417:                if (!bIsValidHostNamePort) {
1418:
1419:                    throw new ValidationException("Invalid Instance Host/Port");
1420:                }
1421:
1422:                if ((wcAdminPort == null) || (wcAdminPort.length() <= 0)) {
1423:
1424:                    throw new ValidationException("Invalid Admin Port");
1425:                }
1426:
1427:                // Validate Admin host & port
1428:                bIsValidHostNamePort = validateAdminHostNamePort(wcAdminHost,
1429:                        wcAdminPort);
1430:
1431:                if (!bIsValidHostNamePort) {
1432:
1433:                    throw new ValidationException("Invalid Admin Host/Port");
1434:                }
1435:
1436:                // TODO: Check if the Server is running by checking the Port Connection
1437:                // TODO: Validate instance uid/password
1438:                // TODO: Validate Admin uid/password/Port/Host
1439:                String javadbdir = null;
1440:                try {
1441:                    ResourceLoader rl = ResourceLoader.getInstance();
1442:                    Properties prop = rl.getProperties(PS_CONFIG_FILE);
1443:                    javadbdir = prop.getProperty(DERBY_LIB_DIR);
1444:                } catch (IOException e) {
1445:                    logger.log(Level.FINEST, "PSFB_CSPFT0335", new String[] {
1446:                            "File Not Found", PS_CONFIG_FILE });
1447:                }
1448:                String derbyclientpath = javadbdir + "/derbyclient.jar";
1449:                if (!FileUtil.fileExists(derbyclientpath)) {
1450:                    throw new ValidationException(derbyclientpath
1451:                            + " does not exist");
1452:                }
1453:                File configfl = new File(wcInstanceDir + "/config.xml");
1454:                if (!FileUtil.findTextInFile(configfl, "8.1.5.0").equals("")) {
1455:                    if (wcManagedServer) {
1456:                        File startscript = new File(wcInstanceDir
1457:                                + "/startManagedWebLogic.sh");
1458:                        if (FileUtil.findTextInFile(startscript,
1459:                                derbyclientpath).equals("")) {
1460:                            throw new ValidationException(
1461:                                    "Please add derbyclient.jar in the CLASSPATH of startManagedWebLogic.sh "
1462:                                            + "and restart the managed server using startManagedWebLogich.sh");
1463:                        }
1464:                    } else {
1465:                        File startscript = new File(wcInstanceDir
1466:                                + "/startWebLogic.sh");
1467:                        if (FileUtil.findTextInFile(startscript,
1468:                                derbyclientpath).equals("")) {
1469:                            throw new ValidationException(
1470:                                    "Please add derbyclient.jar in the CLASSPATH of startWebLogic.sh and restart the admin server");
1471:                        }
1472:                    }
1473:                }
1474:            }
1475:
1476:            public boolean removeClasspath(String classpath) {
1477:                if (wcManagedServer) {
1478:                    String strSomeInstancePortalID = FileUtil
1479:                            .findPatternInFile(wcConfigfile,
1480:                                    "^\\s*[^#]*\\s*PS_PORTAL_ID_[^$].*");
1481:                    boolean someInstanceExist = (strSomeInstancePortalID != null && !strSomeInstancePortalID
1482:                            .equals("")) ? true : false;
1483:
1484:                    if (someInstanceExist == false) {
1485:                        logger
1486:                                .log(Level.FINEST, "PSFB_CSPFT0050",
1487:                                        new String[] { "Removing classpath",
1488:                                                classpath });
1489:                        String str = FileUtil.findTextInFile(wcConfigfile,
1490:                                "PS_CLASS_PATH=");
1491:
1492:                        if (str != null && !str.equals("")) {
1493:                            FileUtil
1494:                                    .deleteLineInFile(
1495:                                            wcConfigfile,
1496:                                            "PS_CLASS_PATH=",
1497:                                            FileUtil.DELETE_FIRST_OCCURANCE_STARTING_WITH);
1498:                        }
1499:                        // Remove from CLASSPATH.
1500:                        str = FileUtil.findTextInFile(wcConfigfile,
1501:                                "$PS_CLASS_PATH");
1502:                        if (str != null && !str.equals("")) {
1503:                            //FileUtil.replaceTokenInFile(wcConfigfile, "\\$PS_CLASS_PATH=",""); Did not work!!
1504:                            int idx = str.indexOf("$PS_CLASS_PATH");
1505:                            str = str.substring(0, idx - 1)
1506:                                    + str.substring(idx + 14);
1507:                            FileUtil.deleteLineInFile(wcConfigfile,
1508:                                    "$PS_CLASS_PATH",
1509:                                    FileUtil.DELETE_FIRST_OCCURANCE);
1510:                            FileUtil
1511:                                    .appendLineInFile(
1512:                                            wcConfigfile,
1513:                                            "resetFd",
1514:                                            "\n" + str,
1515:                                            FileUtil.APPEND_FIRST_OCCURANCE_STARTING_WITH);
1516:                        }
1517:                        return true;
1518:                    }
1519:                } else {
1520:                    String str = FileUtil.findTextInFile(wcConfigfile,
1521:                            "PS_CLASS_PATH=");
1522:                    if (str != null && !str.equals("")) {
1523:                        FileUtil.deleteLineInFile(wcConfigfile,
1524:                                "PS_CLASS_PATH=",
1525:                                FileUtil.DELETE_FIRST_OCCURANCE_STARTING_WITH);
1526:                    }
1527:                    str = FileUtil.findTextInFile(wcConfigfile,
1528:                            "$PS_CLASS_PATH");
1529:                    if (str != null && !str.equals("")) {
1530:                        //FileUtil.replaceTokenInFile(wcConfigfile, "\\$PS_CLASS_PATH=",""); Did not work!!
1531:                        int idx = str.indexOf("$PS_CLASS_PATH");
1532:                        str = str.substring(0, idx - 1)
1533:                                + str.substring(idx + 14);
1534:                        FileUtil.deleteLineInFile(wcConfigfile,
1535:                                "$PS_CLASS_PATH",
1536:                                FileUtil.DELETE_FIRST_OCCURANCE);
1537:                        FileUtil.appendLineInFile(wcConfigfile, "SERVER_NAME=",
1538:                                "\n" + str,
1539:                                FileUtil.APPEND_FIRST_OCCURANCE_STARTING_WITH);
1540:                        return true;
1541:                    }
1542:                }
1543:                return false;
1544:            }
1545:
1546:            public boolean removeJVMOption(String option, String value) {
1547:                boolean success = false;
1548:                String optionValuePair = "-D" + option + "=" + value;
1549:
1550:                logger.log(Level.FINEST, "PSFB_CSPFT0058",
1551:                        new String[] { optionValuePair });
1552:                success = FileUtil.deleteLineInFile(wcConfigfile,
1553:                        "PS_PORTAL_ID_" + wcTargetInstance);
1554:                success = FileUtil.deleteLineInFile(wcConfigfile,
1555:                        "PS_INSTANCE_ID_" + wcTargetInstance);
1556:
1557:                //We need to remove from the java options only if there are no instances left that
1558:                // still require the java options configuration.
1559:                String strSomeInstancePortalID = FileUtil.findPatternInFile(
1560:                        wcConfigfile, "^\\s*[^#]*\\s*PS_PORTAL_ID_[^$].*");
1561:                boolean someInstanceExist = (strSomeInstancePortalID != null && !strSomeInstancePortalID
1562:                        .equals("")) ? true : false;
1563:
1564:                if (someInstanceExist == false) {
1565:                    String str = FileUtil.findTextInFile(wcConfigfile,
1566:                            "PS_OPTIONS=");
1567:                    if (str != null && !str.equals("")) {
1568:                        // The objective here is to get string property=value we desire.
1569:                        // The property here is the option as provided in the method parameter.
1570:                        int idx = str.indexOf("-D" + option);
1571:                        int idx2 = 0;
1572:                        if (idx != -1) {
1573:                            //Now rewrite the PS_OPTIONS
1574:                            idx2 = str.indexOf(" -D", idx);
1575:                            // We know the if next three characters are " -D", the the property is
1576:                            // is in the middle. Else this property=value was the last in the PS_OPTIONS.
1577:                            if (idx2 != -1) {
1578:                                str = str.substring(0, idx)
1579:                                        + str
1580:                                                .substring(str.indexOf(" -D",
1581:                                                        idx));
1582:                                FileUtil.deleteLineInFile(wcConfigfile,
1583:                                        "PS_OPTIONS=");
1584:                                success = FileUtil
1585:                                        .appendLineInFile(
1586:                                                wcConfigfile,
1587:                                                "SERVER_NAME=",
1588:                                                str,
1589:                                                FileUtil.APPEND_FIRST_OCCURANCE_STARTING_WITH);
1590:                            } else {
1591:                                FileUtil.deleteLineInFile(wcConfigfile,
1592:                                        "PS_OPTIONS=");
1593:                                //str=str.substring(0,idx)+(str.startsWith("PS_OPTIONS=\"")?"\"":"");
1594:                                if (wcManagedServer) {
1595:                                    String sr = FileUtil
1596:                                            .findTextInFile(wcConfigfile,
1597:                                                    "$JAVA_HOME/bin/java");
1598:                                    if (sr != null && !sr.equals("")) {
1599:                                        if (sr.indexOf("${PS_OPTIONS}") != -1) {
1600:                                            sr = sr
1601:                                                    .substring(
1602:                                                            0,
1603:                                                            sr
1604:                                                                    .indexOf("${PS_OPTIONS}") - 1)
1605:                                                    + " \\";
1606:                                            FileUtil.replaceLineInFile(
1607:                                                    wcConfigfile,
1608:                                                    "$JAVA_HOME/bin/java", sr);
1609:                                        }
1610:                                        success = true;
1611:                                    }
1612:                                } else {
1613:                                    String sr = FileUtil.findTextInFile(
1614:                                            wcConfigfile,
1615:                                            "${JAVA_HOME}/bin/java");
1616:                                    if (sr != null && !sr.equals("")) {
1617:                                        if (sr.indexOf("${PS_OPTIONS}") != -1
1618:                                                && sr.indexOf("-Dweblogic") != -1) {
1619:                                            sr = sr
1620:                                                    .substring(
1621:                                                            0,
1622:                                                            sr
1623:                                                                    .indexOf("${PS_OPTIONS}") - 1)
1624:                                                    + " "
1625:                                                    + sr
1626:                                                            .substring(sr
1627:                                                                    .indexOf("-Dweblogic"));
1628:                                            FileUtil
1629:                                                    .replaceLineInFile(
1630:                                                            wcConfigfile,
1631:                                                            "${JAVA_HOME}/bin/java",
1632:                                                            sr);
1633:                                        }
1634:                                    }
1635:                                }
1636:                            }
1637:                        }
1638:                    }
1639:                }
1640:                return success;
1641:            }
1642:
1643:            public boolean removeNativeLibraryPath(String path) {
1644:                logger.log(Level.FINEST, "PSFB_CSPFT0066");
1645:                try {
1646:                    String pathToDelete = "/usr/lib/lwp";
1647:                    String retStr = FileUtil.findTextInFile(wcConfigfile,
1648:                            "LD_LIBRARY_PATH=");
1649:                    if (retStr != null && !retStr.equals("")
1650:                            && retStr.trim().startsWith("LD_LIBRARY_PATH=")) {
1651:                        FileUtil.replaceTokenInFile(wcConfigfile, pathToDelete,
1652:                                "");
1653:                        logger.log(Level.FINEST, "PSFB_CSPFT0078",
1654:                                new String[] { "/usr/lib/lwp", retStr,
1655:                                        wcConfigfile.getAbsolutePath() });
1656:                    } else {
1657:                        logger.log(Level.FINEST, "PSFB_CSPFT0079");
1658:                        return false;
1659:                    }
1660:                } catch (Exception e) {
1661:                    if (logger.isLoggable(Level.SEVERE)) {
1662:                        LogRecord record = new LogRecord(Level.SEVERE,
1663:                                "PSFB_CSPFT0030");
1664:                        record.setThrown(e);
1665:                        record.setLoggerName(logger.getName());
1666:                        logger.log(record);
1667:                    }
1668:                    return false;
1669:                }
1670:                return true;
1671:            }
1672:
1673:            public void deleteSymbolicLinks(final PSConfigContext configContext) {
1674:                logger.log(Level.FINEST, "PSFB_CSPFT0070");
1675:                try {
1676:                    String appDir = wcInstanceDir + fs + "applications";
1677:                    String defWebApp = "DefaultWebApp";
1678:                    String docsDir = appDir + fs + defWebApp;
1679:                    String helpDir = docsDir + fs + "online_help" + fs
1680:                            + "docs_en_US";
1681:                    OSTasks osTasks = OSTasksFactory.getOSTasks(configContext);
1682:                    osTasks.removeSymbolicLink(docsDir + fs + "voice");
1683:                    osTasks.removeSymbolicLink(helpDir + fs + "ps");
1684:                    osTasks.removeSymbolicLink(helpDir + fs + "ma");
1685:                } catch (Exception e) {
1686:                    if (logger.isLoggable(Level.SEVERE)) {
1687:                        LogRecord record = new LogRecord(Level.SEVERE,
1688:                                "PSFB_CSPFT0038");
1689:                        record.setThrown(e);
1690:                        record.setLoggerName(logger.getName());
1691:                        logger.log(record);
1692:                    }
1693:                }
1694:            }
1695:
1696:            // TODO: need to implement this method
1697:            public void undoMiscTasks(PSConfigContext configContext) {
1698:                removeWebLogicServerStartArguments();
1699:                removeWebLogicServerStartClasspath();
1700:            }
1701:
1702:            //Stub method
1703:            public boolean doJVMMemorySettings() {
1704:                return false;
1705:            }
1706:
1707:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.