Source Code Cross Referenced for JESAS81Impl.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:         * Copyright 2004 Sun Microsystems, Inc. All
0003:         * rights reserved. Use of this product is subject
0004:         * to license terms. Federal Acquisitions:
0005:         * Commercial Software -- Government Users
0006:         * Subject to Standard License Terms and
0007:         * Conditions.
0008:         *
0009:         * Sun, Sun Microsystems, the Sun logo, and Sun ONE
0010:         * are trademarks or registered trademarks of Sun Microsystems,
0011:         * Inc. in the United States and other countries.
0012:         */package com.sun.portal.fabric.tasks;
0013:
0014:        import java.io.File;
0015:        import java.io.FileWriter;
0016:        import java.io.IOException;
0017:        import java.util.Date;
0018:        import java.util.Map;
0019:        import java.util.logging.Level;
0020:        import java.util.logging.Logger;
0021:        import java.util.logging.LogRecord;
0022:        import java.io.*;
0023:        import java.net.*;
0024:
0025:        import org.jdom.Element;
0026:
0027:        import com.sun.portal.admin.common.context.PSConfigContext;
0028:        import com.sun.portal.fabric.util.FileUtil;
0029:        import com.sun.portal.fabric.util.os.OSTasks;
0030:        import com.sun.portal.fabric.util.os.OSTasksFactory;
0031:        import com.sun.portal.log.common.PortalLogger;
0032:        import com.sun.portal.util.Platform;
0033:
0034:        public class JESAS81Impl extends WebContainerBase {
0035:
0036:            private static final String CLASSPATH_PREFIX = "java-config.classpath-prefix";
0037:            private static final String CLASSPATH_SUFFIX = "java-config.classpath-suffix";
0038:            private static final String SERVER_CLASSPATH = "java-config.server-classpath";
0039:            private static final String NATIVE_LIBRARY_PATH = "java-config.native-library-path-prefix";
0040:            private static final String WEB_CONTAINER_COMMAND = "WebConatinerCommand";
0041:            private static final String POLICY_START_TAG = "// START OF ADDITIONS FOR ";
0042:            private static final String POLICY_END_TAG = "// END OF ADDITIONS FOR ";
0043:
0044:            private String wcHomeDir = null;
0045:            private String wcInstanceDir = null;
0046:            private String wcTargetInstance = null;
0047:            private String wcTargetDomain = null;
0048:            private String wcDocRootDir = null;
0049:            private String wcAdminUser = null;
0050:            private String wcAdminPassword = null;
0051:            private String wcMasterPassword = null;
0052:            private String wcAdminPasswordFilePath = null;
0053:            private String wcAdminProtocol = null;
0054:            private String wcAdminHost = null;
0055:            private String wcAdminPort = null;
0056:            private String wcDeployURI = null;
0057:            private String command = null;
0058:            private boolean bIsDAS = false;
0059:            private static Logger logger = PortalLogger
0060:                    .getLogger(JESAS81Impl.class);
0061:
0062:            /**
0063:             * Constructor
0064:             *
0065:             * @param wcAttributes WebContainer Information as a Map
0066:             * @param logger Logger
0067:             */
0068:            public JESAS81Impl(final Map wcAttributes) {
0069:
0070:                super (wcAttributes);
0071:
0072:                wcHomeDir = (String) wcAttributes
0073:                        .get(WEB_CONTAINER_INSTALL_DIR);
0074:                wcInstanceDir = (String) wcAttributes
0075:                        .get(WEB_CONTAINER_INSTANCE_DIR);
0076:                wcTargetInstance = (String) wcAttributes
0077:                        .get(WEB_CONTAINER_INSTANCE);
0078:                wcTargetDomain = (String) wcAttributes
0079:                        .get(WEB_CONTAINER_DOMAIN);
0080:                wcDocRootDir = (String) wcAttributes
0081:                        .get(WEB_CONTAINER_DOC_ROOT);
0082:                wcAdminUser = (String) wcAttributes
0083:                        .get(WEB_CONTAINER_ADMIN_UID);
0084:                wcAdminPassword = (String) wcAttributes
0085:                        .get(WEB_CONTAINER_ADMIN_PASSWORD);
0086:                wcMasterPassword = (String) wcAttributes
0087:                        .get(WEB_CONTAINER_MASTER_PASSWORD);
0088:                wcAdminProtocol = (String) wcAttributes
0089:                        .get(WEB_CONTAINER_ADMIN_SCHEME);
0090:                wcAdminHost = (String) wcAttributes
0091:                        .get(WEB_CONTAINER_ADMIN_HOST);
0092:                wcAdminPort = (String) wcAttributes
0093:                        .get(WEB_CONTAINER_ADMIN_PORT);
0094:                wcDeployURI = "portal";
0095:
0096:                execUtil.storeOutput(true);
0097:                execUtil.storeError(true);
0098:
0099:                // Set the location of asadmin util
0100:                command = wcHomeDir + fs + Platform.getCommand("asadmin");
0101:
0102:                // create password file
0103:                createPasswordFile();
0104:            }
0105:
0106:            public void postValidationInit() throws ConfigurationException {
0107:
0108:                // Is this DAS ?
0109:                bIsDAS = isDAS();
0110:
0111:                // Printable Web Container Instance Name
0112:                wcPrintableInstanceName = wcTargetDomain + "."
0113:                        + wcTargetInstance;
0114:            }
0115:
0116:            public void start() throws ConfigurationException {
0117:
0118:                String[] args = (bIsDAS) ? new String[6] : new String[10];
0119:
0120:                if (bIsDAS) {
0121:
0122:                    args[0] = "start-domain";
0123:                    args[1] = "--user";
0124:                    args[2] = wcAdminUser;
0125:                    args[3] = "--passwordfile";
0126:                    args[4] = wcAdminPasswordFilePath;
0127:                    args[5] = wcTargetDomain;
0128:                } else {
0129:
0130:                    args[0] = "start-instance";
0131:                    args[1] = "--user";
0132:                    args[2] = wcAdminUser;
0133:                    args[3] = "--passwordfile";
0134:                    args[4] = wcAdminPasswordFilePath;
0135:                    args[5] = "--host";
0136:                    args[6] = wcAdminHost;
0137:                    args[7] = "--port";
0138:                    args[8] = wcAdminPort;
0139:                    args[9] = wcTargetInstance;
0140:                }
0141:
0142:                logger.log(Level.INFO, "PSFB_CSPFT0103");
0143:                int iRetCode = execUtil.exec(command, args);
0144:                if (iRetCode != 0) {
0145:
0146:                    // 'start-domain' failed for some reason
0147:                    String sError = execUtil.getError();
0148:                    logger.log(Level.SEVERE, "PSFB_CSPFT0012", new String[] {
0149:                            getCommand(command, args),
0150:                            (sError != null) ? sError : "" });
0151:                }
0152:            }
0153:
0154:            public void stop() throws ConfigurationException {
0155:
0156:                String[] args = (bIsDAS) ? new String[2] : new String[10];
0157:
0158:                if (bIsDAS) {
0159:
0160:                    args[0] = "stop-domain";
0161:                    args[1] = wcTargetDomain;
0162:                } else {
0163:
0164:                    args[0] = "stop-instance";
0165:                    args[1] = "--user";
0166:                    args[2] = wcAdminUser;
0167:                    args[3] = "--passwordfile";
0168:                    args[4] = wcAdminPasswordFilePath;
0169:                    args[5] = "--host";
0170:                    args[6] = wcAdminHost;
0171:                    args[7] = "--port";
0172:                    args[8] = wcAdminPort;
0173:                    args[9] = wcTargetInstance;
0174:                }
0175:
0176:                logger.log(Level.INFO, "PSFB_CSPFT0102");
0177:                int iRetCode = execUtil.exec(command, args);
0178:                if (iRetCode != 0) {
0179:
0180:                    // 'stop-domain' failed for some reason
0181:                    String sError = execUtil.getError();
0182:                    logger.log(Level.SEVERE, "PSFB_CSPFT0012", new String[] {
0183:                            getCommand(command, args),
0184:                            (sError != null) ? sError : "" });
0185:                }
0186:            }
0187:
0188:            /**
0189:             * Deploys the WAR file on to the webcontainer instance
0190:             *
0191:             * @param warFile WAR file including full path
0192:             * @param uri Deployment URI
0193:             */
0194:            public void deploy(final String warFile, final String uri)
0195:                    throws ConfigurationException {
0196:
0197:                // First try creating the application reference of the web
0198:                // application on the target.
0199:                // It can fail if the application has not been deployed on
0200:                // any instance of the same domain.
0201:                // If Failed, try actually deploying it, else retun Success.
0202:
0203:                String name = (uri.charAt(0) == '/') ? uri.substring(1) : uri;
0204:                int iRetCode = createApplicationReferenceOnTarget(name);
0205:                if (iRetCode != 0) {
0206:
0207:                    // Final resort, deploy the application on the target as
0208:                    // creation of application reference failed.
0209:                    String[] args = new String[16];
0210:
0211:                    args[0] = "deploy";
0212:                    args[1] = "--user";
0213:                    args[2] = wcAdminUser;
0214:                    args[3] = "--passwordfile";
0215:                    args[4] = wcAdminPasswordFilePath;
0216:                    args[5] = "--host";
0217:                    args[6] = wcAdminHost;
0218:                    args[7] = "--port";
0219:                    args[8] = wcAdminPort;
0220:                    args[9] = "--contextroot";
0221:                    args[10] = uri;
0222:                    args[11] = "--name";
0223:                    args[12] = name;
0224:                    args[13] = "--target";
0225:                    args[14] = wcTargetInstance;
0226:                    args[15] = warFile;
0227:
0228:                    iRetCode = execUtil.exec(command, args);
0229:                    if (iRetCode != 0) {
0230:
0231:                        // 'deploy' failed for some reason
0232:                        String sError = execUtil.getError();
0233:                        if ((sError == null) || sError.trim().equals("")) {
0234:
0235:                            sError = "Deploy Failed";
0236:                        }
0237:                        logger.log(Level.SEVERE, "PSFB_CSPFT0012",
0238:                                new String[] { getCommand(command, args),
0239:                                        sError });
0240:
0241:                        // Throw configuration Exception
0242:                        throw new ConfigurationException("Deploy Failed");
0243:                    }
0244:                }
0245:            }
0246:
0247:            /**
0248:             * Undeploys the WAR file from the webcontainer instance
0249:             *
0250:             * @param uri Deployment URI
0251:             */
0252:            public void undeploy(final String uri)
0253:                    throws ConfigurationException {
0254:
0255:                // First try undeploying the web application.
0256:                // It can fail for the foloowing 2 reasons.
0257:                // 1. Web application is not deployed on the
0258:                //    given target.
0259:                // 2. web application has application reference
0260:                //    on atleast one another instance within the
0261:                //    same domain.
0262:                // If Failed for reason 1, then just quit.
0263:                // If Failed for reason 2, then delete the application
0264:                // reference on the target instance.
0265:
0266:                String name = (uri.charAt(0) == '/') ? uri.substring(1) : uri;
0267:                String[] args = new String[12];
0268:
0269:                args[0] = "undeploy";
0270:                args[1] = "--user";
0271:                args[2] = wcAdminUser;
0272:                args[3] = "--passwordfile";
0273:                args[4] = wcAdminPasswordFilePath;
0274:                args[5] = "--host";
0275:                args[6] = wcAdminHost;
0276:                args[7] = "--port";
0277:                args[8] = wcAdminPort;
0278:                args[9] = "--target";
0279:                args[10] = wcTargetInstance;
0280:                args[11] = name;
0281:
0282:                int iRetCode = execUtil.exec(command, args);
0283:                if (iRetCode != 0) {
0284:
0285:                    String sError = execUtil.getError();
0286:                    if ((sError != null)
0287:                            && (0 <= sError.indexOf("already deployed"))) {
0288:
0289:                        // already deployed on other target, the best you
0290:                        // can do is delete application reference.
0291:                        iRetCode = deleteApplicationReferenceFromTarget(name);
0292:                    } else if ((sError != null)
0293:                            && (0 <= sError.indexOf("not registered"))) {
0294:
0295:                        // Component not registered
0296:                        logger.log(Level.SEVERE, "PSFB_CSPFT0013",
0297:                                new String[] { name, wcTargetDomain });
0298:                    } else {
0299:
0300:                        // 'undeploy' failed for some reason
0301:                        logger.log(Level.SEVERE, "PSFB_CSPFT0012",
0302:                                new String[] { getCommand(command, args),
0303:                                        (sError != null) ? sError : "" });
0304:                        // Throw configuration Exception
0305:                        throw new ConfigurationException("Undeploy Failed");
0306:
0307:                    }
0308:                }
0309:            }
0310:
0311:            /**
0312:             * Set a value for a key in Web Container configuration file.
0313:             */
0314:            private void wcSet(final String key, final String value)
0315:                    throws ConfigurationException {
0316:
0317:                String[] args = new String[10];
0318:
0319:                args[0] = "set";
0320:                args[1] = "--user";
0321:                args[2] = wcAdminUser;
0322:                args[3] = "--passwordfile";
0323:                args[4] = wcAdminPasswordFilePath;
0324:                args[5] = "--host";
0325:                args[6] = wcAdminHost;
0326:                args[7] = "--port";
0327:                args[8] = wcAdminPort;
0328:                args[9] = wcTargetInstance + "." + key + "=" + value;
0329:
0330:                int iRetCode = 0;
0331:
0332:                File wsClspthFile = null;
0333:                try {
0334:                    wsClspthFile = File.createTempFile("wsclasspath", ".cls");
0335:                    String wsClspthName = wsClspthFile.getAbsolutePath();
0336:                    FileWriter fwriter = new FileWriter(wsClspthFile);
0337:                    for (int i = 0; i < args.length; i++) {
0338:                        fwriter.write(args[i] + " ");
0339:                    }
0340:                    fwriter.close();
0341:
0342:                    String[] args1 = { "multimode", "-f",
0343:                            wsClspthFile.getAbsolutePath().replace('\\', '/') };
0344:
0345:                    iRetCode = execUtil.exec(command, args1);
0346:
0347:                    wsClspthFile.delete();
0348:
0349:                } catch (IOException e) {
0350:                    String sError = execUtil.getError();
0351:                    logger.log(Level.SEVERE, "PSFB_CSPFT0012", new String[] {
0352:                            getCommand(command, args),
0353:                            (sError != null) ? sError : "" });
0354:                }
0355:
0356:                if (iRetCode != 0) {
0357:
0358:                    // 'set' failed for some reason
0359:                    String sError = execUtil.getError();
0360:                    logger.log(Level.SEVERE, "PSFB_CSPFT0012", new String[] {
0361:                            getCommand(command, args),
0362:                            (sError != null) ? sError : "" });
0363:                }
0364:            }
0365:
0366:            private boolean isWinOS() {
0367:                return Platform.name.indexOf("windows") != -1;
0368:            }
0369:
0370:            /**
0371:             * Fetch Value from web container configuration file for a key.
0372:             */
0373:            private final String wcGet(final String key)
0374:                    throws ConfigurationException {
0375:
0376:                String[] args = new String[10];
0377:
0378:                args[0] = "get";
0379:                args[1] = "--user";
0380:                args[2] = wcAdminUser;
0381:                args[3] = "--passwordfile";
0382:                args[4] = wcAdminPasswordFilePath;
0383:                args[5] = "--host";
0384:                args[6] = wcAdminHost;
0385:                args[7] = "--port";
0386:                args[8] = wcAdminPort;
0387:                args[9] = wcTargetInstance + "." + key;
0388:
0389:                int iRetCode = execUtil.exec(command, args);
0390:                if (iRetCode != 0) {
0391:
0392:                    // 'get' failed for some reason
0393:                    String sError = execUtil.getError();
0394:                    logger.log(Level.SEVERE, "PSFB_CSPFT0012", new String[] {
0395:                            getCommand(command, args),
0396:                            (sError != null) ? sError : "" });
0397:                }
0398:
0399:                String value = (iRetCode == 0) ? execUtil.getOutput()
0400:                        : execUtil.getError();
0401:
0402:                if (iRetCode == 0) {
0403:
0404:                    int iIndex = value.indexOf("=");
0405:                    if (iIndex >= 0) {
0406:
0407:                        value = value.substring(iIndex + 1);
0408:                        value = value.trim();
0409:                    }
0410:                }
0411:
0412:                return value;
0413:            }
0414:
0415:            public boolean removeJVMOption(final String key, final String value) {
0416:
0417:                String[] args = new String[12];
0418:
0419:                args[0] = "delete-jvm-options";
0420:                args[1] = "--user";
0421:                args[2] = wcAdminUser;
0422:                args[3] = "--passwordfile";
0423:                args[4] = wcAdminPasswordFilePath;
0424:                args[5] = "--host";
0425:                args[6] = wcAdminHost;
0426:                args[7] = "--port";
0427:                args[8] = wcAdminPort;
0428:                args[9] = "--target";
0429:                args[10] = wcTargetInstance;
0430:                args[11] = getJVMOptionString(key, value);
0431:
0432:                int iRetCode = execUtil.exec(command, args);
0433:                if (iRetCode != 0) {
0434:
0435:                    // 'delete-jvm-option' failed for some reason
0436:                    String sError = execUtil.getError();
0437:                    logger.log(Level.SEVERE, "PSFB_CSPFT0012", new String[] {
0438:                            getCommand(command, args),
0439:                            (sError != null) ? sError : "" });
0440:                }
0441:
0442:                return true;
0443:            }
0444:
0445:            public boolean addJVMOption(final String key, final String value) {
0446:
0447:                String[] args = new String[12];
0448:
0449:                args[0] = "create-jvm-options";
0450:                args[1] = "--user";
0451:                args[2] = wcAdminUser;
0452:                args[3] = "--passwordfile";
0453:                args[4] = wcAdminPasswordFilePath;
0454:                args[5] = "--host";
0455:                args[6] = wcAdminHost;
0456:                args[7] = "--port";
0457:                args[8] = wcAdminPort;
0458:                args[9] = "--target";
0459:                args[10] = wcTargetInstance;
0460:                if (isWinOS())
0461:                    args[11] = getJVMOptionString(key, value).replaceAll("-",
0462:                            "\\\\-").replaceAll(":", "\\\\:");
0463:                else
0464:                    args[11] = getJVMOptionString(key, value);
0465:
0466:                int iRetCode = execUtil.exec(command, args);
0467:                if (iRetCode != 0) {
0468:
0469:                    // 'create-jvm-option' failed for some reason
0470:                    String sError = execUtil.getError();
0471:                    logger.log(Level.SEVERE, "PSFB_CSPFT0012", new String[] {
0472:                            getCommand(command, args),
0473:                            (sError != null) ? sError : "" });
0474:                }
0475:
0476:                return true;
0477:            }
0478:
0479:            private String getJVMOptionString(String key, String value) {
0480:                StringBuffer option = new StringBuffer();
0481:                if (key.startsWith("-")) {
0482:                    if (value == null || value.trim().equals("")) {
0483:                        //If no value specified
0484:                        option.append("\"").append(key).append("\"");
0485:                    } else {
0486:                        //Any option other than user defined option (-D)
0487:                        option.append("\"").append(key).append("=").append(
0488:                                value).append("\"");
0489:                    }
0490:                } else {
0491:                    //user defined options
0492:                    option.append("\"").append("-D").append(key).append("=")
0493:                            .append(value).append("\"");
0494:                }
0495:                return option.toString();
0496:            }
0497:
0498:            /**
0499:             * Configures the WebContainer with the classpath
0500:             * settings, JVM options and other settings needed
0501:             * for Identity Server SDK
0502:             */
0503:            public void doIdentitySDKConfig(final PSConfigContext configContext)
0504:                    throws ConfigurationException {
0505:
0506:                if (isIdentityServerSDKConfigured()) {
0507:                    logger.log(Level.SEVERE, "PSFB_CSPFT0014",
0508:                            new String[] { wcPrintableInstanceName });
0509:                    return;
0510:                }
0511:
0512:                String protocol = (String) wcAttributes.get(SCHEME);
0513:                String port = (String) wcAttributes.get(PORT);
0514:
0515:                String amProductLoc = configContext.getISBaseDir();
0516:                String amConfigDir = configContext.getISConfigDir();
0517:                String psDataDir = configContext.getPSDataDir();
0518:
0519:                int index = amProductLoc.lastIndexOf(fs);
0520:                String amProductDir = amProductLoc.substring(index + 1);
0521:                String amBaseDir = amProductLoc.substring(0, index);
0522:
0523:                logger.log(Level.SEVERE, "PSFB_CSPFT0015",
0524:                        new String[] { wcPrintableInstanceName });
0525:
0526:                String amSilentName = psDataDir + fs + "tmp" + fs
0527:                        + "amsilent_ps." + FileUtil.getRandomDirName();
0528:
0529:                StringBuffer fileData = new StringBuffer();
0530:                fileData.append("BASEDIR=" + amBaseDir + nl).append(
0531:                        "PRODUCT_DIR=" + amProductDir + nl).append(
0532:                        "CONFIG_DIR=" + amConfigDir + nl + nl).append(
0533:                        "AS81_HOME=" + wcHomeDir + nl).append(
0534:                        "AS81_DOMAIN=" + wcTargetDomain + nl).append(
0535:                        "AS81_INSTANCE_DIR=" + wcInstanceDir + nl).append(
0536:                        "AS81_INSTANCE=" + wcTargetInstance + nl).append(
0537:                        "AS81_DOCS_DIR=" + wcDocRootDir + nl).append(
0538:                        "AS81_IS_SECURE=false" + nl).append(
0539:                        "AS81_ADMIN_IS_SECURE=true" + nl).append(
0540:                        "AS81_PROTOCOL=" + protocol + nl).append(
0541:                        "AS81_HOST=" + wcAdminHost + nl).append(
0542:                        "AS81_PORT=" + port + nl).append(
0543:                        "AS81_ADMIN=" + wcAdminUser + nl).append(
0544:                        "AS81_ADMINPASSWD=" + wcAdminPassword + nl).append(
0545:                        "AS81_ADMINPORT=" + wcAdminPort + nl).append(
0546:                        "DEPLOY_LEVEL=7" + nl).append(
0547:                        "JAVA_HOME=" + configContext.getJavaHome() + nl)
0548:                        .append("WEB_CONTAINER=AS8" + nl);
0549:
0550:                File amSilentFile = new File(amSilentName);
0551:                try {
0552:                    FileWriter fwriter = new FileWriter(amSilentFile);
0553:                    fwriter.write(fileData.toString());
0554:                    fwriter.close();
0555:                } catch (IOException ioe) {
0556:                    if (logger.isLoggable(Level.SEVERE)) {
0557:                        logger.log(Level.SEVERE, "PSFB_CSPFT0016");
0558:                        LogRecord record = new LogRecord(Level.SEVERE,
0559:                                "PSFB_CSPFT0017");
0560:                        record
0561:                                .setParameters(new String[] { wcPrintableInstanceName });
0562:                        record.setThrown(ioe);
0563:                        record.setLoggerName(logger.getName());
0564:                        logger.log(record);
0565:                    }
0566:
0567:                    amSilentFile.delete();
0568:                    return;
0569:                }
0570:
0571:                String amconfig = amProductLoc + fs + "bin" + fs + "amconfig";
0572:                String args[] = { "-s", amSilentFile.getAbsolutePath() };
0573:
0574:                logger.log(Level.SEVERE, "PSFB_CSPFT0018",
0575:                        new String[] { amconfig });
0576:                if (execUtil.exec(amconfig, args) != 0) {
0577:                    logger.log(Level.SEVERE, "PSFB_CSPFT0019", new String[] {
0578:                            wcType, wcPrintableInstanceName });
0579:                } else {
0580:                    logger.log(Level.INFO, "PSFB_CSPFT0020", new String[] {
0581:                            wcType, wcPrintableInstanceName });
0582:                }
0583:
0584:                amSilentFile.delete();
0585:            }
0586:
0587:            private final boolean isDAS() {
0588:
0589:                return wcTargetInstance.equals("server");
0590:            }
0591:
0592:            private void wcReconfig() throws ConfigurationException {
0593:
0594:                stop();
0595:                start();
0596:                logger.log(Level.INFO, "PSFB_CSPFT0104");
0597:            }
0598:
0599:            private final int createApplicationReferenceOnTarget(
0600:                    final String sRefName) {
0601:
0602:                // Create an application reference on target
0603:                String[] args = new String[12];
0604:
0605:                args[0] = "create-application-ref";
0606:                args[1] = "--user";
0607:                args[2] = wcAdminUser;
0608:                args[3] = "--passwordfile";
0609:                args[4] = wcAdminPasswordFilePath;
0610:                args[5] = "--host";
0611:                args[6] = wcAdminHost;
0612:                args[7] = "--port";
0613:                args[8] = wcAdminPort;
0614:                args[9] = "--target";
0615:                args[10] = wcTargetInstance;
0616:                args[11] = sRefName;
0617:
0618:                int iRetCode = execUtil.exec(command, args);
0619:                if (iRetCode != 0 || isWinOS()) {
0620:
0621:                    String sError = execUtil.getError();
0622:                    if ((sError != null)
0623:                            && (0 <= sError.indexOf("already exists"))) {
0624:
0625:                        // Application reference already created.
0626:                        // so return 0 (success)
0627:                        logger.log(Level.SEVERE, "PSFB_CSPFT0021",
0628:                                new String[] { sRefName,
0629:                                        wcPrintableInstanceName });
0630:                        iRetCode = 0;
0631:                    } else if ((sError != null)
0632:                            && (0 <= sError.indexOf("not registered"))) {
0633:
0634:                        // Component not registered
0635:                        logger.log(Level.SEVERE, "PSFB_CSPFT0022",
0636:                                new String[] { sRefName, wcTargetDomain });
0637:                        if (isWinOS())
0638:                            iRetCode = -1;
0639:                    } else {
0640:
0641:                        // 'create-application-ref' failed for some reason
0642:                        logger.log(Level.SEVERE, "PSFB_CSPFT0012",
0643:                                new String[] { getCommand(command, args),
0644:                                        (sError != null) ? sError : "" });
0645:                        if (isWinOS())
0646:                            iRetCode = -1;
0647:                    }
0648:                }
0649:
0650:                return iRetCode;
0651:            }
0652:
0653:            private final int deleteApplicationReferenceFromTarget(
0654:                    final String sRefName) {
0655:
0656:                // Delete an application reference from target
0657:                String[] args = new String[12];
0658:
0659:                args[0] = "delete-application-ref";
0660:                args[1] = "--user";
0661:                args[2] = wcAdminUser;
0662:                args[3] = "--passwordfile";
0663:                args[4] = wcAdminPasswordFilePath;
0664:                args[5] = "--host";
0665:                args[6] = wcAdminHost;
0666:                args[7] = "--port";
0667:                args[8] = wcAdminPort;
0668:                args[9] = "--target";
0669:                args[10] = wcTargetInstance;
0670:                args[11] = sRefName;
0671:
0672:                int iRetCode = execUtil.exec(command, args);
0673:                if (iRetCode != 0) {
0674:
0675:                    String sError = execUtil.getError();
0676:                    if ((sError != null)
0677:                            && (0 <= sError
0678:                                    .indexOf("does not have a reference"))) {
0679:
0680:                        // Application reference already created.
0681:                        // so return 0 (success)
0682:                        logger.log(Level.SEVERE, "PSFB_CSPFT0023",
0683:                                new String[] { wcPrintableInstanceName,
0684:                                        sRefName });
0685:                        iRetCode = 0;
0686:                    } else if ((sError != null)
0687:                            && (0 <= sError.indexOf("not registered"))) {
0688:
0689:                        // Component not registered
0690:                        // so return 0 (success)
0691:                        logger.log(Level.SEVERE, "PSFB_CSPFT0024",
0692:                                new String[] { sRefName, wcTargetDomain });
0693:                        iRetCode = 0;
0694:                    } else {
0695:
0696:                        // 'undeploy' failed for some reason
0697:                        logger.log(Level.SEVERE, "PSFB_CSPFT0012",
0698:                                new String[] { getCommand(command, args),
0699:                                        (sError != null) ? sError : "" });
0700:                    }
0701:                }
0702:
0703:                return iRetCode;
0704:            }
0705:
0706:            private final boolean isIdentityServerSDKConfigured()
0707:                    throws ConfigurationException {
0708:
0709:                // Fetch the classpath from domain.xml of the server instance,
0710:                // and check for 'am_sdk.jar' in it.
0711:                String sValue = wcGet(CLASSPATH_SUFFIX);
0712:
0713:                return (sValue != null) && (sValue.indexOf("am_sdk.jar") > 0);
0714:            }
0715:
0716:            private void createPasswordFile() {
0717:
0718:                StringBuffer fileData = new StringBuffer();
0719:
0720:                fileData.append("AS_ADMIN_PASSWORD=" + wcAdminPassword + nl);
0721:
0722:                if ((wcMasterPassword != null)
0723:                        && (wcMasterPassword.length() > 0)) {
0724:
0725:                    fileData.append("AS_ADMIN_MASTERPASSWORD="
0726:                            + wcMasterPassword + nl);
0727:                }
0728:
0729:                try {
0730:
0731:                    Date curDate = new Date();
0732:                    String sTmpFile = "" + curDate.getTime();
0733:                    File appPasswordFile = File.createTempFile(sTmpFile, "");
0734:                    appPasswordFile.deleteOnExit();
0735:                    if (!isWinOS())
0736:                        wcAdminPasswordFilePath = appPasswordFile
0737:                                .getAbsolutePath();
0738:                    else
0739:                        wcAdminPasswordFilePath = appPasswordFile
0740:                                .getAbsolutePath().replace('\\', '/');
0741:                    FileWriter fwriter = new FileWriter(appPasswordFile);
0742:                    fwriter.write(fileData.toString());
0743:                    fwriter.close();
0744:                } catch (IOException ioe) {
0745:
0746:                    if (logger.isLoggable(Level.SEVERE)) {
0747:                        LogRecord record = new LogRecord(Level.SEVERE,
0748:                                "PSFB_CSPFT0025");
0749:                        record.setThrown(ioe);
0750:                        record.setLoggerName(logger.getName());
0751:                        logger.log(record);
0752:                    }
0753:                }
0754:            }
0755:
0756:            protected void finalize() throws Throwable {
0757:
0758:                super .finalize();
0759:                if ((wcAdminPasswordFilePath != null)
0760:                        && !wcAdminPasswordFilePath.trim().equals("")) {
0761:
0762:                    File fAdminPasswordFile = new File(wcAdminPasswordFilePath);
0763:                    if (fAdminPasswordFile.isFile()) {
0764:
0765:                        fAdminPasswordFile.delete();
0766:                    }
0767:                }
0768:            }
0769:
0770:            /**
0771:             * Validate web container
0772:             */
0773:            public void validate() throws ValidationException {
0774:
0775:                // validate data before calling the constructor
0776:                if (!checkNotNullOrEmpty(WEB_CONTAINER_INSTANCE,
0777:                        wcTargetInstance)) {
0778:
0779:                    throw new ValidationException("Invalid Instance Name");
0780:                }
0781:
0782:                if (!checkNotNullOrEmpty(WEB_CONTAINER_DOMAIN, wcTargetDomain)) {
0783:
0784:                    throw new ValidationException("Invalid Domain Name");
0785:                }
0786:
0787:                if (!checkNotNull(WEB_CONTAINER_ADMIN_UID, wcAdminUser)) {
0788:
0789:                    throw new ValidationException("Invalid Admin User");
0790:                }
0791:
0792:                if (!checkNotNull(WEB_CONTAINER_ADMIN_PASSWORD,
0793:                        wcAdminPassword, true)) {
0794:
0795:                    throw new ValidationException("Invalid Admin Password");
0796:                }
0797:
0798:                if (!checkNotNullOrEmpty(WEB_CONTAINER_ADMIN_SCHEME,
0799:                        wcAdminProtocol)) {
0800:
0801:                    throw new ValidationException("Invalid Admin Scheme");
0802:                }
0803:
0804:                if (!checkNotNullOrEmpty(WEB_CONTAINER_ADMIN_HOST, wcAdminHost)) {
0805:
0806:                    throw new ValidationException("Invalid Admin Host");
0807:                }
0808:
0809:                if (!checkNotNullOrEmpty(WEB_CONTAINER_ADMIN_PORT, wcAdminPort)) {
0810:
0811:                    throw new ValidationException("Invalid Admin Port");
0812:                }
0813:
0814:                if (!checkDirExists(WEB_CONTAINER_INSTANCE_DIR, wcInstanceDir)) {
0815:
0816:                    throw new ValidationException(
0817:                            "Invalid Instance Directory = " + wcInstanceDir);
0818:                }
0819:
0820:                if (!checkDirExists(WEB_CONTAINER_DOC_ROOT, wcDocRootDir)) {
0821:
0822:                    throw new ValidationException(
0823:                            "Invalid Doc Root Directory = " + wcDocRootDir);
0824:                }
0825:
0826:                if (!checkDirExists(WEB_CONTAINER_INSTALL_DIR, wcHomeDir)) {
0827:
0828:                    throw new ValidationException(
0829:                            "Invalid Install Directory = " + wcHomeDir);
0830:                }
0831:
0832:                String sPathToASAdminCommand = null;
0833:                sPathToASAdminCommand = wcHomeDir + fs
0834:                        + Platform.getCommand("asadmin");
0835:                if (!checkFileExists(WEB_CONTAINER_COMMAND,
0836:                        sPathToASAdminCommand)) {
0837:
0838:                    throw new ValidationException(
0839:                            "Invalid path to 'asadmin' = "
0840:                                    + sPathToASAdminCommand);
0841:                }
0842:
0843:                // Validate Instant host & port
0844:                String host = (String) wcAttributes.get(HOST);
0845:                String port = (String) wcAttributes.get(PORT);
0846:                boolean bIsValidHostNamePort = validateInstanceHostNamePort(
0847:                        host, port);
0848:
0849:                if (!bIsValidHostNamePort) {
0850:
0851:                    throw new ValidationException("Invalid Instance Host/Port");
0852:                }
0853:
0854:                // Validate Admin host & port
0855:                bIsValidHostNamePort = validateAdminHostNamePort(wcAdminHost,
0856:                        wcAdminPort);
0857:
0858:                if (!bIsValidHostNamePort) {
0859:
0860:                    throw new ValidationException("Invalid Admin Host/Port");
0861:                }
0862:
0863:                boolean bIsValidateDomainDir = validateDomainDir(wcInstanceDir);
0864:                if (!bIsValidateDomainDir) {
0865:                    throw new ValidationException("Invalid Instance directory");
0866:                }
0867:
0868:                // Validating if AS ports, passwords and is AS running by getting a value that
0869:                // is sure to be set. In this case server classpath
0870:                try {
0871:
0872:                    String sClassPathSuffix = wcGet(SERVER_CLASSPATH);
0873:                    String sFieldName = wcTargetDomain + "." + wcTargetInstance
0874:                            + "." + SERVER_CLASSPATH;
0875:                    if (!checkNotNullOrEmpty(sFieldName, sClassPathSuffix)) {
0876:
0877:                        throw new ValidationException(
0878:                                "Could not fetch the value of " + sFieldName);
0879:                    }
0880:                } catch (ConfigurationException e) {
0881:
0882:                    throw new ValidationException(e);
0883:                }
0884:            }
0885:
0886:            private boolean validateDomainDir(String wcInstanceDir) {
0887:                String InstaceConfigDir = wcInstanceDir + File.separator
0888:                        + "config";
0889:                try {
0890:                    File file = new File(InstaceConfigDir);
0891:                    String absolutepath = file.getAbsolutePath();
0892:                    String fileName = absolutepath + File.separator
0893:                            + "server.policy";
0894:                    if (FileUtil.fileExists(fileName)) {
0895:                        return true;
0896:                    } else {
0897:                        return false;
0898:                    }
0899:                } catch (SecurityException se) {
0900:
0901:                    logger
0902:                            .log(Level.SEVERE, "PSFB_CSPFT0341",
0903:                                    InstaceConfigDir);
0904:                    return false;
0905:                }
0906:
0907:            }
0908:
0909:            public boolean isPortalConfigured() {
0910:                boolean retValue = false;
0911:                try {
0912:                    String sValue = wcGet(CLASSPATH_SUFFIX);
0913:                    //Does the classpath contain the PORTAL_TEST_JAR?
0914:                    retValue = !((sValue == null) || (sValue
0915:                            .indexOf(PORTAL_TEST_JAR) < 0));
0916:                } catch (Exception e) {
0917:                    logger.log(Level.SEVERE, "PSFB_CSPFT0202", e);
0918:                }
0919:
0920:                if (retValue) {
0921:                    logger.log(Level.INFO, "PSFB_CSPFT0041");
0922:                }
0923:
0924:                return retValue;
0925:            }
0926:
0927:            /**
0928:             * Set container classpath
0929:             * @param classpath
0930:             * @return true if classpath set successfully
0931:             */
0932:            public boolean appendClasspath(String classpath) {
0933:                //By default setting to CLASSPATH_SUFFIX
0934:                return appendClasspath(classpath, CLASSPATH_SUFFIX);
0935:            }
0936:
0937:            /**
0938:             * Set container classpath
0939:             * @param classpath
0940:             * @param target - CLASSPATH_SUFFIX/CLASSPATH_PREFIX
0941:             * @return true if classpath set successfully
0942:             */
0943:            private boolean appendClasspath(String classpath, String target) {
0944:                try {
0945:                    // Set classpath-suffix
0946:                    if ((classpath != null) && (classpath.trim().length() > 0)) {
0947:
0948:                        // Only if classpath is not null
0949:                        String sValue = wcGet(target);
0950:
0951:                        if ((sValue != null) && (sValue.length() > 0)) {
0952:
0953:                            String mergedCP = getMergedClassPath(classpath,
0954:                                    sValue);
0955:                            //If merged classpath is the same as the original, dont bother setting, just return
0956:                            if (sValue.equals(mergedCP))
0957:                                return true;
0958:                            else
0959:                                sValue = mergedCP;
0960:
0961:                        } else {
0962:
0963:                            sValue = classpath;
0964:                        }
0965:
0966:                        if (sValue != null) {
0967:
0968:                            wcSet(target, sValue);
0969:                        } else {
0970:
0971:                            return false;
0972:                        }
0973:                    }
0974:                } catch (Exception e) {
0975:
0976:                    if (logger.isLoggable(Level.SEVERE)) {
0977:                        LogRecord record = new LogRecord(Level.SEVERE,
0978:                                "PSFB_CSPFT0026");
0979:                        record.setThrown(e);
0980:                        record.setLoggerName(logger.getName());
0981:                        logger.log(record);
0982:                    }
0983:
0984:                    return false;
0985:                }
0986:
0987:                return true;
0988:            }
0989:
0990:            public boolean setNativeLibraryPath(String path) {
0991:
0992:                try {
0993:                    String sValue = wcGet(NATIVE_LIBRARY_PATH);
0994:                    String myPath = "." + cps + path;
0995:                    int startIndex = sValue.indexOf(myPath);
0996:                    if (startIndex < 0) {
0997:                        String sValue1 = myPath
0998:                                + (sValue.trim().equals("") ? ""
0999:                                        : (cps + sValue));
1000:                        wcSet(NATIVE_LIBRARY_PATH, sValue1);
1001:                    } else {
1002:                        return false;
1003:                    }
1004:                } catch (Exception e) {
1005:                    if (logger.isLoggable(Level.SEVERE)) {
1006:                        LogRecord record = new LogRecord(Level.SEVERE,
1007:                                "PSFB_CSPFT0027");
1008:                        record.setThrown(e);
1009:                        record.setLoggerName(logger.getName());
1010:                        logger.log(record);
1011:                    }
1012:                    return false;
1013:                }
1014:
1015:                return true;
1016:            }
1017:
1018:            public void createSymbolicLinks(final PSConfigContext configContext) {
1019:
1020:                try {
1021:                    String helpDir = wcDocRootDir + fs + "online_help" + fs
1022:                            + "docs_en_US";
1023:                    String psHelpDir = configContext.getPSBaseDir() + fs
1024:                            + "docs" + fs + "public_html" + fs + "online_help"
1025:                            + fs + "docs_en_US";
1026:                    String voiceDir = configContext.getPSBaseDir() + fs
1027:                            + "export" + fs + "voice";
1028:
1029:                    OSTasks osTasks = OSTasksFactory.getOSTasks(configContext);
1030:                    osTasks.createSymbolicLink(voiceDir, wcDocRootDir);
1031:                    osTasks.createSymbolicLink(psHelpDir + fs + "ps", helpDir);
1032:                    osTasks.createSymbolicLink(psHelpDir + fs + "ma", helpDir);
1033:                } catch (Exception e) {
1034:
1035:                    if (logger.isLoggable(Level.SEVERE)) {
1036:                        LogRecord record = new LogRecord(Level.SEVERE,
1037:                                "PSFB_CSPFT0040");
1038:                        record.setThrown(e);
1039:                        record.setLoggerName(logger.getName());
1040:                        logger.log(record);
1041:                    }
1042:                }
1043:            }
1044:
1045:            public void doMiscTasks(final PSConfigContext configContext) {
1046:
1047:                try {
1048:                    doJVMMemorySettings();
1049:                    doPolicyConfig(configContext);
1050:
1051:                    //Workaround for WSRP bug #6322542
1052:                    appendClasspath(getWsrpJaxRpcClasspath(configContext),
1053:                            CLASSPATH_PREFIX);
1054:                } catch (Exception e) {
1055:                    if (logger.isLoggable(Level.SEVERE)) {
1056:                        LogRecord record = new LogRecord(Level.SEVERE,
1057:                                "PSFB_CSPFT0101");
1058:                        record.setThrown(e);
1059:                        record.setLoggerName(logger.getName());
1060:                        logger.log(record);
1061:                    }
1062:                }
1063:            }
1064:
1065:            /**
1066:             * Do required container memory settings if the appserver vm setting are the default
1067:             *  i.e. if -Xmx512m setting is found
1068:             */
1069:            public boolean doJVMMemorySettings() {
1070:                try {
1071:                    String vmOptions = wcGet("java-config.jvm-options");
1072:                    //If no Xms settings are found
1073:                    if (vmOptions.indexOf("-Xss") < 0) {
1074:                        //removeJVMOption("-Xmx512m", "");
1075:                        addJVMOption("-Xms512m", "");
1076:                        addJVMOption("-Xss128k", "");
1077:                        addJVMOption("-XX:NewSize", "168M");
1078:                        addJVMOption("-XX:MaxNewSize", "168M");
1079:                        addJVMOption("-XX:PermSize", "192M");
1080:                        addJVMOption("-XX:MaxPermSize", "192M");
1081:                        addJVMOption("-XX:+DisableExplicitGC", "");
1082:                        addJVMOption("-XX:SoftRefLRUPolicyMSPerMB", "0");
1083:                        addJVMOption("-XX:+PrintGCTimeStamps", "");
1084:                        addJVMOption("-XX:+PrintHeapAtGC", "");
1085:                        addJVMOption("-XX:+PrintClassHistogram", "");
1086:                        addJVMOption("-Xloggc:" + wcInstanceDir + fs + "logs"
1087:                                + fs + "gc.log", "");
1088:
1089:                        return true;
1090:                    }
1091:                } catch (Exception e) {
1092:
1093:                    if (logger.isLoggable(Level.SEVERE)) {
1094:                        LogRecord record = new LogRecord(Level.SEVERE,
1095:                                "PSFB_CSPFT0026");
1096:                        record.setThrown(e);
1097:                        record.setLoggerName(logger.getName());
1098:                        logger.log(record);
1099:                    }
1100:                }
1101:
1102:                return false;
1103:            }
1104:
1105:            private String getWsrpJaxRpcClasspath(
1106:                    final PSConfigContext configContext) {
1107:                //Workaround for WSRP bug #6322542
1108:                String JAXLib = configContext.getJAXLibDir() + fs;
1109:                String pfxCP = JAXLib + "xmldsig.jar" + cps + JAXLib
1110:                        + "security-plugin.jar" + cps + JAXLib + "xmlsec.jar"
1111:                        + cps + JAXLib + "xws-security.jar" + cps + JAXLib
1112:                        + "xws-security_jaxrpc.jar" + cps;
1113:                return pfxCP;
1114:            }
1115:
1116:            /**
1117:             * Do the required appserver server policy settings
1118:             * @param configContext - Portal configuration context
1119:             */
1120:
1121:            private void doPolicyConfig(final PSConfigContext configContext) {
1122:
1123:                try {
1124:
1125:                    String policy = wcInstanceDir + fs + "config" + fs
1126:                            + "server.policy";
1127:                    File file = new File(policy);
1128:
1129:                    String productMarker = configContext.getPortalProductName()
1130:                            + " " + configContext.getPortalVersion();
1131:                    String str = FileUtil.findTextInFile(file, productMarker);
1132:                    if ((str == null) || str.equals("")) {
1133:
1134:                        StringBuffer buf = new StringBuffer();
1135:                        buf.append(nl);
1136:                        buf.append(POLICY_START_TAG).append(productMarker)
1137:                                .append(nl);
1138:                        buf.append("grant {").append(nl);
1139:
1140:                        //generic policy settings
1141:                        buf
1142:                                .append(
1143:                                        "    permission java.util.PropertyPermission \"*\",\"read,write\";")
1144:                                .append(nl);
1145:                        buf
1146:                                .append(
1147:                                        "    permission java.lang.RuntimePermission \"writeFileDescriptor\";")
1148:                                .append(nl);
1149:                        buf
1150:                                .append(
1151:                                        "    permission java.lang.RuntimePermission \"createClassLoader\";")
1152:                                .append(nl);
1153:                        buf
1154:                                .append(
1155:                                        "    permission java.io.FilePermission \"\\${/}-\", \"read,write,execute,delete\";")
1156:                                .append(nl);
1157:                        buf.append(nl);
1158:
1159:                        //console policy settings
1160:                        buf.append("//  Used by psconsole app").append(nl);
1161:                        buf
1162:                                .append(
1163:                                        "    permission java.security.SecurityPermission \"insertProvider.SunSASL\";")
1164:                                .append(nl);
1165:                        buf
1166:                                .append(
1167:                                        "    permission java.security.SecurityPermission \"insertProvider.SunJSSE\";")
1168:                                .append(nl);
1169:                        buf
1170:                                .append(
1171:                                        "    permission java.lang.RuntimePermission \"getProtectionDomain\";")
1172:                                .append(nl);
1173:                        buf.append(nl);
1174:
1175:                        //wsrp xws identity propagation
1176:                        buf
1177:                                .append(
1178:                                        "//  Used by wsrp xws identity propagation CR:6355658")
1179:                                .append(nl);
1180:                        buf
1181:                                .append(
1182:                                        "    permission javax.security.auth.AuthPermission \"modifyPrivateCredentials\";")
1183:                                .append(nl);
1184:                        buf.append(nl);
1185:
1186:                        //monitoring policy settings
1187:                        String sPsMonitoringConfigDir = configContext
1188:                                .getPSConfigDir()
1189:                                + fs
1190:                                + "domains"
1191:                                + fs
1192:                                + domainID
1193:                                + fs
1194:                                + "portals" + fs + portalID + fs + instanceID;
1195:                        String sPsInstanceConfigDir = sPsMonitoringConfigDir
1196:                                + fs + "-";
1197:                        buf.append("//  Used by Monitoring").append(nl);
1198:                        buf
1199:                                .append(
1200:                                        "    permission java.io.FilePermission \"")
1201:                                .append(sPsInstanceConfigDir)
1202:                                .append("\", \"read, write, execute, delete\";")
1203:                                .append(nl);
1204:                        buf
1205:                                .append(
1206:                                        "    permission java.lang.RuntimePermission \"accessClassInPackage.*\";")
1207:                                .append(nl);
1208:                        buf
1209:                                .append(
1210:                                        "    permission java.lang.RuntimePermission \"setContextClassLoader\";")
1211:                                .append(nl);
1212:                        buf
1213:                                .append(
1214:                                        "    permission java.net.SocketPermission \"localhost:-\", \"accept, connect, listen\";")
1215:                                .append(nl);
1216:                        buf
1217:                                .append(
1218:                                        "    permission java.security.SecurityPermission \"createAccessControlContext\";")
1219:                                .append(nl);
1220:                        buf
1221:                                .append(
1222:                                        "    permission java.security.SecurityPermission \"insertProvider.PortalServer\";")
1223:                                .append(nl);
1224:                        buf
1225:                                .append(
1226:                                        "    permission java.security.SecurityPermission \"putProviderProperty.PortalServer\";")
1227:                                .append(nl);
1228:                        buf
1229:                                .append(
1230:                                        "    permission java.util.PropertyPermission \"*\", \"read\";")
1231:                                .append(nl);
1232:                        buf
1233:                                .append(
1234:                                        "    permission java.util.PropertyPermission \"com.sun.portal.*\", \"read, write\";")
1235:                                .append(nl);
1236:                        buf
1237:                                .append(
1238:                                        "    permission java.util.logging.LoggingPermission \"control\";")
1239:                                .append(nl);
1240:                        buf
1241:                                .append(
1242:                                        "    permission javax.management.MBeanPermission \"javax.management.*\", \"*\";")
1243:                                .append(nl);
1244:                        buf
1245:                                .append(
1246:                                        "    permission javax.management.MBeanPermission \"com.sun.jdmk.*\", \"*\";")
1247:                                .append(nl);
1248:                        buf
1249:                                .append(
1250:                                        "    permission javax.management.MBeanPermission \"com.sun.portal.*\", \"*\";")
1251:                                .append(nl);
1252:                        buf
1253:                                .append(
1254:                                        "    permission javax.management.MBeanServerPermission \"createMBeanServer\";")
1255:                                .append(nl);
1256:                        buf
1257:                                .append(
1258:                                        "    permission javax.management.MBeanServerPermission \"findMBeanServer\";")
1259:                                .append(nl);
1260:                        buf
1261:                                .append(
1262:                                        "    permission javax.management.MBeanTrustPermission \"register\";")
1263:                                .append(nl);
1264:                        if (configContext.getJESMFLibDir() != null) {
1265:                            buf
1266:                                    .append(
1267:                                            "    permission javax.management.MBeanPermission \"com.sun.cmm.*\", \"*\";")
1268:                                    .append(nl);
1269:                            buf
1270:                                    .append(
1271:                                            "    permission javax.management.MBeanPermission \"com.sun.mfwk.*\", \"*\";")
1272:                                    .append(nl);
1273:                        }
1274:                        buf.append(nl);
1275:
1276:                        //community policy settings
1277:                        buf.append("//  Used by Community").append(nl);
1278:                        buf
1279:                                .append(
1280:                                        "    permission java.lang.RuntimePermission \"getClassLoader\";")
1281:                                .append(nl);
1282:                        buf
1283:                                .append(
1284:                                        "    permission javax.jdo.spi.JDOPermission \"getMetadata\";")
1285:                                .append(nl);
1286:                        buf
1287:                                .append(
1288:                                        "    permission javax.jdo.spi.JDOPermission \"setStateManager\";")
1289:                                .append(nl);
1290:                        buf
1291:                                .append(
1292:                                        "    permission java.lang.reflect.ReflectPermission \"suppressAccessChecks\";")
1293:                                .append(nl);
1294:                        buf.append(nl);
1295:
1296:                        //sra netfile settings
1297:                        //Note: the policy settings are made even if sra is not installed
1298:                        buf.append("//  Used by SRA NetFile").append(nl);
1299:                        buf
1300:                                .append(
1301:                                        "    permission java.net.SocketPermission \"*\", \"connect,accept,listen,resolve\";")
1302:                                .append(nl);
1303:                        buf
1304:                                .append(
1305:                                        "    permission java.net.NetPermission \"*\", \"specifyStreamHandler\";")
1306:                                .append(nl);
1307:                        buf.append(nl);
1308:
1309:                        buf.append("};").append(nl);
1310:                        buf.append(POLICY_END_TAG).append(productMarker)
1311:                                .append(nl);
1312:                        buf.append(nl);
1313:
1314:                        FileUtil.appendToFile(file, buf.toString(), false);
1315:                    }
1316:
1317:                } catch (Exception e) {
1318:                    if (logger.isLoggable(Level.SEVERE)) {
1319:                        LogRecord record = new LogRecord(Level.SEVERE,
1320:                                "PSFB_CSPFT0028");
1321:                        record.setThrown(e);
1322:                        record.setLoggerName(logger.getName());
1323:                        logger.log(record);
1324:                    }
1325:                }
1326:            }
1327:
1328:            public void configResource(Element root, String derbyHost,
1329:                    String derbyPort, String databaseName, String poolName) {
1330:
1331:                createConnectionPool(root, derbyHost, derbyPort, databaseName,
1332:                        poolName);
1333:                createResources(root, poolName);
1334:            }
1335:
1336:            public void createConnectionPool(Element root, String derbyHost,
1337:                    String derbyPort, String databaseName, String poolName) {
1338:
1339:                String[] args = new String[22];
1340:
1341:                args[0] = "create-jdbc-connection-pool";
1342:                args[1] = "--user";
1343:                args[2] = wcAdminUser;
1344:                args[3] = "--passwordfile";
1345:                args[4] = wcAdminPasswordFilePath;
1346:                args[5] = "--host";
1347:                args[6] = wcAdminHost;
1348:                args[7] = "--port";
1349:                args[8] = wcAdminPort;
1350:                args[9] = "--datasourceclassname";
1351:                String dataSourceClassName = root
1352:                        .getAttributeValue("dataSourceClassName.SJSAS81");
1353:                if (dataSourceClassName != null
1354:                        && !dataSourceClassName.equals("")
1355:                        && dataSourceClassName.length() > 0) {
1356:                    args[10] = dataSourceClassName;
1357:                } else {
1358:                    args[10] = root.getAttributeValue("dataSourceClassName");
1359:                }
1360:                args[11] = "--restype";
1361:                args[12] = root.getAttributeValue("type");
1362:                args[13] = "--maxpoolsize";
1363:                args[14] = root.getAttributeValue("maxActive");
1364:                args[15] = "--maxwait";
1365:                args[16] = root.getAttributeValue("maxWait");
1366:                args[17] = "--idletimeout";
1367:                args[18] = root.getAttributeValue("maxIdle");
1368:                args[19] = "--property";
1369:                args[20] = "serverName=" + derbyHost + ":portNumber="
1370:                        + derbyPort + ":User="
1371:                        + root.getAttributeValue("username") + ":Password="
1372:                        + root.getAttributeValue("password") + ":databaseName="
1373:                        + databaseName;
1374:                args[21] = poolName;
1375:
1376:                int iRetCode = execUtil.exec(command, args);
1377:                if (iRetCode != 0) {
1378:
1379:                    // 'create-jdbc-connection-pool' failed for some reason
1380:                    String sError = execUtil.getError();
1381:                    logger.log(Level.SEVERE, "PSFB_CSPFT0012", new String[] {
1382:                            getCommand(command, args),
1383:                            (sError != null) ? sError : "" });
1384:                }
1385:            }
1386:
1387:            public void createResources(Element root, String poolName) {
1388:
1389:                String[] args = new String[14];
1390:                args[0] = "create-jdbc-resource";
1391:                args[1] = "--user";
1392:                args[2] = wcAdminUser;
1393:                args[3] = "--passwordfile";
1394:                args[4] = wcAdminPasswordFilePath;
1395:                args[5] = "--host";
1396:                args[6] = wcAdminHost;
1397:                args[7] = "--port";
1398:                args[8] = wcAdminPort;
1399:                args[9] = "--connectionpoolid";
1400:                args[10] = poolName;
1401:                args[11] = "--target";
1402:                args[12] = wcTargetInstance;
1403:                args[13] = root.getAttributeValue("name");
1404:
1405:                execUtil.exec(command, args);
1406:                int iRetCode = execUtil.exec(command, args);
1407:                if (iRetCode != 0) {
1408:
1409:                    // 'create-jdbc-resource' failed for some reason
1410:                    String sError = execUtil.getError();
1411:                    logger.log(Level.SEVERE, "PSFB_CSPFT0012", new String[] {
1412:                            getCommand(command, args),
1413:                            (sError != null) ? sError : "" });
1414:                }
1415:            }
1416:
1417:            public void removeConnectionPool(String poolName) {
1418:
1419:                String[] args = new String[11];
1420:                //asadmin delete-jdbc-connection-pool --user user --cascade=true connection_pool_id
1421:                args[0] = "delete-jdbc-connection-pool";
1422:                args[1] = "--user";
1423:                args[2] = wcAdminUser;
1424:                args[3] = "--passwordfile";
1425:                args[4] = wcAdminPasswordFilePath;
1426:                args[5] = "--host";
1427:                args[6] = wcAdminHost;
1428:                args[7] = "--port";
1429:                args[8] = wcAdminPort;
1430:                args[9] = "--cascade=true";
1431:                args[10] = poolName;
1432:
1433:                execUtil.exec(command, args);
1434:            }
1435:
1436:            public void removeResource(String jndiName) {
1437:
1438:                String[] args = new String[10];
1439:                //asadmin delete-jdbc-resource --user user jndi_name
1440:                args[0] = "delete-jdbc-resource";
1441:                args[1] = "--user";
1442:                args[2] = wcAdminUser;
1443:                args[3] = "--passwordfile";
1444:                args[4] = wcAdminPasswordFilePath;
1445:                args[5] = "--host";
1446:                args[6] = wcAdminHost;
1447:                args[7] = "--port";
1448:                args[8] = wcAdminPort;
1449:                args[9] = jndiName;
1450:                execUtil.exec(command, args);
1451:            }
1452:
1453:            public void unConfigResource(String jndiName, String poolName) {
1454:                // Fix for 6497904 - uninstall/delete-instance does not delete resources
1455:                //removeConnectionPool(poolName);
1456:                //removeResource(jndiName);
1457:            }
1458:
1459:            /**
1460:             * remove from container classpath
1461:             * @param classpath
1462:             * @return true if classpath set successfully
1463:             */
1464:            public boolean removeClasspath(String classpath) {
1465:                //By default removing from CLASSPATH_SUFFIX
1466:                return removeClasspath(classpath, CLASSPATH_SUFFIX);
1467:            }
1468:
1469:            /**
1470:             * remove from container classpath
1471:             * @param classpath
1472:             * @param target - CLASSPATH_SUFFIX/CLASSPATH_PREFIX
1473:             * @return true if classpath set successfully
1474:             */
1475:            private boolean removeClasspath(String classpath, String target) {
1476:
1477:                boolean bRet = false;
1478:                try {
1479:                    // Only if cllasspath is not null
1480:                    String sValue2 = wcGet(target);
1481:                    int startIndex1 = sValue2.indexOf(classpath);
1482:                    if (startIndex1 >= 0) {
1483:                        sValue2 = sValue2.replaceAll(classpath, cps);
1484:                        bRet = true;
1485:                    } else if (isPortalConfigured()) {
1486:                        String[] sPaths = classpath.split(cps);
1487:                        for (int i = 0; i < sPaths.length; i++) {
1488:                            sValue2 = sValue2.replaceAll(cps + sPaths[i] + cps,
1489:                                    cps);
1490:                        }
1491:                        bRet = true;
1492:                    }
1493:                    if (bRet) {
1494:                        String sCpsPattern = cps + "[" + cps + "]*";
1495:                        sValue2 = sValue2.replaceAll(sCpsPattern, cps);
1496:                        wcSet(target, sValue2);
1497:                    }
1498:                } catch (Exception e) {
1499:                    if (logger.isLoggable(Level.SEVERE)) {
1500:                        LogRecord record = new LogRecord(Level.SEVERE,
1501:                                "PSFB_CSPFT0029");
1502:                        record.setThrown(e);
1503:                        record.setLoggerName(logger.getName());
1504:                        logger.log(record);
1505:                    }
1506:                }
1507:                return bRet;
1508:
1509:            }
1510:
1511:            public boolean removeNativeLibraryPath(String path) {
1512:
1513:                try {
1514:                    String sValue = wcGet(NATIVE_LIBRARY_PATH);
1515:                    String myPath = "." + cps + path;
1516:                    int startIndex = sValue.indexOf(myPath);
1517:                    if (startIndex >= 0) {
1518:                        String sValue1 = sValue.replaceAll(myPath, "");
1519:                        wcSet(NATIVE_LIBRARY_PATH, sValue1);
1520:                    } else {
1521:                        // TODO::Tokenize and replace.
1522:                        return false;
1523:                    }
1524:                } catch (Exception e) {
1525:                    if (logger.isLoggable(Level.SEVERE)) {
1526:                        LogRecord record = new LogRecord(Level.SEVERE,
1527:                                "PSFB_CSPFT0030");
1528:                        record.setThrown(e);
1529:                        record.setLoggerName(logger.getName());
1530:                        logger.log(record);
1531:                    }
1532:                    return false;
1533:                }
1534:
1535:                return true;
1536:            }
1537:
1538:            public void deleteSymbolicLinks(final PSConfigContext configContext) {
1539:
1540:                // Removing links for help, voice to webcontainer docs
1541:                try {
1542:                    String helpDir = wcDocRootDir + fs + "online_help" + fs
1543:                            + "docs_en_US";
1544:
1545:                    OSTasks osTasks = OSTasksFactory.getOSTasks(configContext);
1546:                    osTasks.removeSymbolicLink(wcDocRootDir + fs + "voice");
1547:                    osTasks.removeSymbolicLink(helpDir + fs + "ps");
1548:                    osTasks.removeSymbolicLink(helpDir + fs + "ma");
1549:                } catch (Exception e) {
1550:                    if (logger.isLoggable(Level.SEVERE)) {
1551:                        LogRecord record = new LogRecord(Level.SEVERE,
1552:                                "PSFB_CSPFT0038");
1553:                        record.setThrown(e);
1554:                        record.setLoggerName(logger.getName());
1555:                        logger.log(record);
1556:                    }
1557:                }
1558:            }
1559:
1560:            public void undoMiscTasks(final PSConfigContext configContext) {
1561:
1562:                try {
1563:                    String policy = wcInstanceDir + fs + "config" + fs
1564:                            + "server.policy";
1565:                    File file = new File(policy);
1566:
1567:                    //delete policies for portal server from start portal policies tag
1568:                    // to end portal policies tag
1569:                    String productMarker = configContext.getPortalProductName()
1570:                            + " " + configContext.getPortalVersion();
1571:                    FileUtil.deleteSectionInFile(file, POLICY_START_TAG
1572:                            + productMarker, POLICY_END_TAG + productMarker);
1573:
1574:                    //Workaround for WSRP bug #6322542
1575:                    removeClasspath(getWsrpJaxRpcClasspath(configContext),
1576:                            CLASSPATH_PREFIX);
1577:
1578:                    wcReconfig();
1579:                } catch (Exception e) {
1580:                    if (logger.isLoggable(Level.SEVERE)) {
1581:                        LogRecord record = new LogRecord(Level.SEVERE,
1582:                                "PSFB_CSPFT0031");
1583:                        record.setThrown(e);
1584:                        record.setLoggerName(logger.getName());
1585:                        logger.log(record);
1586:                    }
1587:                }
1588:            }
1589:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.