Source Code Cross Referenced for JESWS6Impl.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) 


001:        /**
002:         * $Id: JESWS6Impl.java,v 1.38 2006/06/07 11:33:37 pj105554 Exp $
003:         * Copyright 2004 Sun Microsystems, Inc. All
004:         * rights reserved. Use of this product is subject
005:         * to license terms. Federal Acquisitions:
006:         * Commercial Software -- Government Users
007:         * Subject to Standard License Terms and
008:         * Conditions.
009:         *
010:         * Sun, Sun Microsystems, the Sun logo, and Sun ONE
011:         * are trademarks or registered trademarks of Sun Microsystems,
012:         * Inc. in the United States and other countries.
013:         */package com.sun.portal.fabric.tasks;
014:
015:        import java.io.File;
016:        import java.io.FileWriter;
017:        import java.io.IOException;
018:
019:        import java.util.Map;
020:        import java.util.logging.Level;
021:        import java.util.logging.Logger;
022:        import java.util.logging.LogRecord;
023:
024:        import org.jdom.Element;
025:        import org.jdom.output.Format;
026:        import org.jdom.output.XMLOutputter;
027:
028:        import java.util.List;
029:        import java.util.Iterator;
030:        import org.jdom.input.SAXBuilder;
031:        import org.jdom.Document;
032:
033:        import com.sun.portal.admin.common.context.PSConfigContext;
034:        import com.sun.portal.fabric.util.FileUtil;
035:        import com.sun.portal.fabric.util.os.OSTasks;
036:        import com.sun.portal.fabric.util.os.OSTasksFactory;
037:        import com.sun.portal.log.common.PortalLogger;
038:
039:        public class JESWS6Impl extends WebContainerBase {
040:
041:            private String wcHomeDir = null;
042:            private String wcInstance = null;
043:            private String wcInstanceDir = null;
044:            private String wcScheme = null;
045:            private String wcCertDBPassword = null;
046:            private String wdeploy = null;
047:            private String amconfigScript = null;
048:            private final String certDBPasswordFile = "password.conf";
049:            private boolean isConfiguredforSSL = false;
050:            private static File wcConfigFile = null;
051:            private static Logger logger = PortalLogger
052:                    .getLogger(JESWS6Impl.class);
053:
054:            /**
055:             *  Web container server class path token
056:             */
057:            private static final String CLASSPATHSUFFIX = "classpathsuffix";
058:
059:            /**
060:             *  Web container native library path token
061:             */
062:            private static final String LIBPATH = "nativelibrarypathprefix";
063:
064:            /**
065:             * Constructor
066:             *
067:             * @param wcAttributes WebContainer Information as a Map
068:             */
069:            public JESWS6Impl(final Map wcAttributes) {
070:
071:                super (wcAttributes);
072:
073:                wcHomeDir = (String) wcAttributes
074:                        .get(WEB_CONTAINER_INSTALL_DIR);
075:                wcInstance = (String) wcAttributes.get(WEB_CONTAINER_INSTANCE);
076:                wcInstanceDir = (String) wcAttributes
077:                        .get(WEB_CONTAINER_INSTANCE_DIR);
078:                wcScheme = (String) wcAttributes.get(SCHEME);
079:                if (wcScheme.equalsIgnoreCase("HTTPS")) {
080:                    isConfiguredforSSL = true;
081:                    wcCertDBPassword = (String) wcAttributes
082:                            .get(WEB_CONTAINER_CERTDB_PASSWORD);
083:                }
084:            }
085:
086:            public void postValidationInit() throws ConfigurationException {
087:
088:                wdeploy = wcHomeDir + fs + "bin" + fs + "https" + fs + "bin"
089:                        + fs + "wdeploy";
090:
091:                wcConfigFile = new File(wcInstanceDir + fs + "config" + fs
092:                        + "server.xml");
093:
094:                wcPrintableInstanceName = wcInstance;
095:            }
096:
097:            /**
098:             * Deploys the WAR file on to the webcontainer instance
099:             *
100:             * @param warFile WAR file including full path
101:             * @param uri Deployment URI
102:             */
103:            public void deploy(String warFile, String uri)
104:                    throws ConfigurationException {
105:
106:                String[] args = { "deploy", "-u", uri, "-i", wcInstance, "-v",
107:                        "https-" + wcInstance, warFile };
108:                int iRetCode = execUtil.exec(wdeploy, args);
109:                if (iRetCode != 0) {
110:
111:                    // 'deploy' failed for some reason
112:                    String sError = execUtil.getError();
113:                    if ((sError == null) || sError.trim().equals("")) {
114:
115:                        sError = "Deploy Failed";
116:                    }
117:
118:                    logger.log(Level.SEVERE, "PSFB_CSPFT0012", new String[] {
119:                            getCommand(wdeploy, args), sError });
120:                    // Throw configuration Exception
121:                    throw new ConfigurationException(sError);
122:                }
123:            }
124:
125:            /**
126:             * Undeploys the WAR file from the webcontainer instance
127:             *
128:             * @param uri Deployment URI
129:             */
130:            public void undeploy(String uri) throws ConfigurationException {
131:
132:                String[] args = { "delete", "-u", uri, "-i", wcInstance, "-v",
133:                        "https-" + wcInstance, "hard" };
134:                execUtil.exec(wdeploy, args);
135:            }
136:
137:            /**
138:             * Configures the WebContainer with the classpath
139:             * settings, JVM options and other settings needed
140:             * for Identity Server SDK
141:             */
142:            public void doIdentitySDKConfig(final PSConfigContext configContext)
143:                    throws ConfigurationException {
144:
145:                logger.log(Level.INFO, "PSFB_CSPFT0244");
146:                if (isIdentityServerSDKConfigured()) {
147:                    logger.log(Level.INFO, "PSFB_CSPFT0245");
148:                    return;
149:                }
150:
151:                String host = (String) wcAttributes.get(HOST);
152:                String port = (String) wcAttributes.get(PORT);
153:
154:                String amProductLoc = configContext.getISBaseDir();
155:                String amConfigDir = configContext.getISConfigDir();
156:                String psDataDir = configContext.getPSDataDir();
157:
158:                int index = amProductLoc.lastIndexOf(fs);
159:                String amProductDir = amProductLoc.substring(index + 1);
160:                String amBaseDir = amProductLoc.substring(0, index);
161:
162:                logger.log(Level.FINEST, "PSFB_CSPFT0015",
163:                        new String[] { wcPrintableInstanceName });
164:
165:                String amSilentName = psDataDir + fs + "tmp" + fs
166:                        + "amsilent_ps." + FileUtil.getRandomDirName();
167:
168:                StringBuffer fileData = new StringBuffer();
169:
170:                fileData.append("BASEDIR=" + amBaseDir + nl).append(
171:                        "PRODUCT_DIR=" + amProductDir + nl).append(
172:                        "CONFIG_DIR=" + amConfigDir + nl).append(
173:                        "WS61_HOME=" + wcHomeDir + nl).append(
174:                        "WS61_INSTANCE=https-" + wcInstance + nl).append(
175:                        "WS61_PROTOCOL=" + wcScheme + nl).append(
176:                        "WS61_HOST=" + host + nl).append(
177:                        "WS61_PORT=" + port + nl).append("WS61_ADMIN=" + nl)
178:                        .append("WS61_ADMINPASSWD=" + nl).append(
179:                                "WS61_ADMINPORT=" + nl);
180:                /**
181:                 * If AM version is 6.x then use container configuration scripts
182:                 * else use amconfig script for container configuration
183:                 * See 6284663 for more info.
184:                 */
185:                if (configContext.getAMVersion().equals("6")) {
186:                    fileData.append("DEPLOY_LEVEL=4" + nl);
187:                    amconfigScript = "amws61config";
188:                } else {
189:                    fileData.append("DEPLOY_LEVEL=7" + nl).append(
190:                            "JAVA_HOME=" + configContext.getJavaHome() + nl)
191:                            .append("WEB_CONTAINER=WS6" + nl);
192:                    amconfigScript = "amconfig";
193:                }
194:
195:                File amSilentFile = new File(amSilentName);
196:                try {
197:                    FileWriter fwriter = new FileWriter(amSilentFile);
198:                    fwriter.write(fileData.toString());
199:                    fwriter.close();
200:                } catch (IOException e) {
201:                    if (logger.isLoggable(Level.SEVERE)) {
202:                        logger.log(Level.SEVERE, "PSFB_CSPFT0016");
203:                        LogRecord record = new LogRecord(Level.SEVERE,
204:                                "PSFB_CSPFT0017");
205:                        record
206:                                .setParameters(new String[] { wcPrintableInstanceName });
207:                        record.setThrown(e);
208:                        record.setLoggerName(logger.getName());
209:                        logger.log(record);
210:                    }
211:
212:                    amSilentFile.delete();
213:                    return;
214:                }
215:
216:                String amws61config = amProductLoc + fs + "bin" + fs
217:                        + amconfigScript;
218:                String args[] = { "-s", amSilentName };
219:
220:                logger.log(Level.FINEST, "PSFB_CSPFT0018",
221:                        new String[] { amws61config });
222:                if (execUtil.exec(amws61config, args) != 0) {
223:                    logger.log(Level.SEVERE, "PSFB_CSPFT0019", new String[] {
224:                            wcType, wcPrintableInstanceName });
225:                } else {
226:                    logger.log(Level.INFO, "PSFB_CSPFT0020", new String[] {
227:                            wcType, wcPrintableInstanceName });
228:                }
229:
230:                amSilentFile.delete();
231:            }
232:
233:            public boolean addJVMOption(String option, String value) {
234:                if (doesJVMOptionExist(option))
235:                    return false;
236:                StringBuffer vmoption = new StringBuffer("<JVMOPTIONS>-D");
237:                vmoption.append(option);
238:                vmoption.append("=");
239:                vmoption.append(value);
240:                vmoption.append("</JVMOPTIONS>");
241:                return FileUtil.appendLineInFile(wcConfigFile,
242:                        "java.util.logging.manager", vmoption.toString());
243:            }
244:
245:            public boolean doesJVMOptionExist(String option) {
246:                boolean exists = false;
247:                String optionLine = FileUtil.findPatternInFile(wcConfigFile,
248:                        ".*JVMOPTIONS.*" + option + ".*");
249:                if (optionLine != null) {
250:                    exists = true;
251:                    logger.log(Level.INFO, "PSFB_CSPFT0092", new String[] {
252:                            option, wcInstance });
253:                }
254:                return exists;
255:            }
256:
257:            private final boolean isIdentityServerSDKConfigured() {
258:
259:                String amSDKJar = null;
260:                amSDKJar = FileUtil.findTextInFile(wcConfigFile, "am_sdk.jar");
261:                if (amSDKJar != null && amSDKJar.trim().length() > 0) {
262:                    return true;
263:                }
264:                return false;
265:            }
266:
267:            public boolean removeJVMOption(String option, String value) {
268:                return FileUtil.deleteLineInFile(wcConfigFile, option);
269:            }
270:
271:            private String getNativeLibraryPath() {
272:                String text = FileUtil.findTextInFile(wcConfigFile, LIBPATH);
273:                return FileUtil.getQuotedKeyValueInText(LIBPATH, text);
274:            }
275:
276:            public boolean setNativeLibraryPath(String path) {
277:                String curLibPath = getNativeLibraryPath();
278:                if (curLibPath == null) {
279:                    logger.log(Level.INFO, "PSFB_CSPFT0042",
280:                            new String[] { LIBPATH });
281:                } else {
282:                    if (curLibPath.indexOf(path) >= 0) {
283:                        logger.log(Level.INFO, "PSFB_CSPFT0043", new String[] {
284:                                LIBPATH, path });
285:                        return false;
286:                    }
287:                    StringBuffer curLib = new StringBuffer(LIBPATH);
288:                    curLib.append("=\"");
289:                    curLib.append(curLibPath);
290:                    curLib.append("\"");
291:
292:                    StringBuffer newLib = new StringBuffer(LIBPATH);
293:                    newLib.append("=\"");
294:                    if (!"".equals(curLibPath)) {
295:                        newLib.append(curLibPath);
296:                        newLib.append(cps);
297:                    }
298:                    newLib.append(path);
299:                    newLib.append("\"");
300:
301:                    return FileUtil.replaceTokenInFile(wcConfigFile, curLib
302:                            .toString(), newLib.toString());
303:                }
304:                return false;
305:            }
306:
307:            public boolean removeNativeLibraryPath(String path) {
308:                String curLibPath = getNativeLibraryPath();
309:                if (curLibPath == null) {
310:                    logger.log(Level.INFO, "PSFB_CSPFT0044",
311:                            new String[] { LIBPATH });
312:                } else {
313:                    if (curLibPath.indexOf(path) < 0) {
314:                        logger.log(Level.INFO, "PSFB_CSPFT0045", new String[] {
315:                                LIBPATH, path });
316:                        return false;
317:                    }
318:                    StringBuffer curLib = new StringBuffer(LIBPATH);
319:                    curLib.append("=\"");
320:                    curLib.append(curLibPath);
321:                    curLib.append("\"");
322:
323:                    StringBuffer newLib = new StringBuffer(LIBPATH);
324:                    newLib.append("=\"");
325:                    if (!"".equals(curLibPath)) {
326:                        String[] remPath = curLibPath.split(path);
327:                        for (int idx = 0; idx < remPath.length; idx++)
328:                            newLib.append(remPath[idx]);
329:                    }
330:                    newLib.append("\"");
331:
332:                    return FileUtil.replaceTokenInFile(wcConfigFile, curLib
333:                            .toString(), newLib.toString());
334:                }
335:                return false;
336:            }
337:
338:            public void start() throws ConfigurationException {
339:                boolean ispasswordFileExists = false;
340:                FileWriter fwriter = null;
341:                File passwordFile = null;
342:
343:                if (isConfiguredforSSL) {
344:                    passwordFile = new File(wcInstanceDir + "config"
345:                            + certDBPasswordFile);
346:                    if (passwordFile.exists()) {
347:                        ispasswordFileExists = true;
348:                    } else {
349:                        StringBuffer fileData = new StringBuffer();
350:                        fileData.append("internal:" + wcCertDBPassword);
351:                        try {
352:                            fwriter = new FileWriter(passwordFile);
353:                            fwriter.write(fileData.toString());
354:                            fwriter.close();
355:                        } catch (IOException e) {
356:                            logger.log(Level.INFO, "PSFB_CSPFT0083", e);
357:                        }
358:                    }
359:                }
360:
361:                logger.log(Level.INFO, "PSFB_CSPFT0103");
362:                // TODO check for output and throw exception if not successful
363:                String wsStart = wcInstanceDir + fs + "start";
364:                execUtil.exec(wsStart, null);
365:
366:                if (ispasswordFileExists) {
367:                    passwordFile.deleteOnExit();
368:                }
369:            }
370:
371:            public void stop() throws ConfigurationException {
372:
373:                logger.log(Level.INFO, "PSFB_CSPFT0102");
374:                // TODO check for output and throw exception if not successful
375:                String wsStop = wcInstanceDir + fs + "stop";
376:                execUtil.exec(wsStop, null);
377:            }
378:
379:            /**
380:             * Validate web container
381:             */
382:            public void validate() throws ValidationException {
383:
384:                // validate data before calling the constructor
385:                if (!checkNotNullOrEmpty(WEB_CONTAINER_INSTANCE, wcInstance)) {
386:
387:                    throw new ValidationException("Invalid Instance Name");
388:                }
389:
390:                if (!checkDirExists(WEB_CONTAINER_INSTALL_DIR, wcHomeDir)) {
391:
392:                    throw new ValidationException(
393:                            "Invalid Install Directory = " + wcHomeDir);
394:                }
395:
396:                if (!checkDirExists(WEB_CONTAINER_INSTANCE_DIR, wcInstanceDir)) {
397:
398:                    throw new ValidationException(
399:                            "Invalid Instance Directory = " + wcInstanceDir);
400:                }
401:
402:                String wcDocRootDir = (String) wcAttributes
403:                        .get(WEB_CONTAINER_DOC_ROOT);
404:                if (!checkDirExists(WEB_CONTAINER_DOC_ROOT, wcDocRootDir)) {
405:
406:                    throw new ValidationException(
407:                            "Invalid Doc Root Directory = " + wcDocRootDir);
408:                }
409:
410:                // Validate Instant host & port
411:                String host = (String) wcAttributes.get(HOST);
412:                String port = (String) wcAttributes.get(PORT);
413:                boolean bIsValidHostNamePort = validateInstanceHostNamePort(
414:                        host, port);
415:
416:                if (!bIsValidHostNamePort) {
417:
418:                    throw new ValidationException("Invalid Instance Host/Port");
419:                }
420:
421:                if (isConfiguredforSSL
422:                        && !checkNotNull(WEB_CONTAINER_CERTDB_PASSWORD,
423:                                wcCertDBPassword, true)) {
424:
425:                    throw new ValidationException(
426:                            "Cert DB Password can NOT be NULL.");
427:                }
428:
429:                // Validate Admin host & port
430:                /*??bIsValidHostNamePort = validateAdminHostNamePort(wcAdminHost, wcAdminPort);
431:
432:                if (!bIsValidHostNamePort) {
433:
434:                   throw new ValidationException("Invalid Admin Host/Port");
435:                }??*/
436:
437:                // TODO: Check if the Server is running by checking the Port Connection
438:                // TODO: Validate instance uid/password
439:                // TODO: Validate Admin uid/password/Port/Host
440:            }
441:
442:            public boolean isPortalConfigured() {
443:                String str = FileUtil.findTextInFile(wcConfigFile,
444:                        CLASSPATHSUFFIX + "=");
445:                if (str != null && !str.equals("")
446:                        && str.indexOf(PORTAL_TEST_JAR) >= 0) {
447:                    logger.log(Level.INFO, "PSFB_CSPFT0041");
448:                    return true;
449:                } else {
450:                    return false;
451:                }
452:            }
453:
454:            private String getServerClassPath() {
455:                String text = FileUtil.findTextInFile(wcConfigFile,
456:                        CLASSPATHSUFFIX);
457:                return FileUtil.getQuotedKeyValueInText(CLASSPATHSUFFIX, text);
458:            }
459:
460:            public boolean appendClasspath(String classpath) {
461:
462:                try {
463:                    String serverCP = getServerClassPath();
464:                    if (serverCP != null && !serverCP.equals("")) {
465:
466:                        //filter out entries in classpath that already occour in serverCP
467:                        String mergedClassPath = getMergedClassPath(classpath,
468:                                serverCP);
469:
470:                        // Set the classpath
471:                        logger.log(Level.INFO, "PSFB_CSPFT0046",
472:                                new String[] { mergedClassPath,
473:                                        wcConfigFile.getAbsolutePath() });
474:                        FileUtil.replaceTokenInFile(wcConfigFile, serverCP,
475:                                mergedClassPath);
476:                    } else {
477:                        return false;
478:                    }
479:                } catch (Exception e) {
480:                    if (logger.isLoggable(Level.SEVERE)) {
481:                        LogRecord record = new LogRecord(Level.SEVERE,
482:                                "PSFB_CSPFT0026");
483:                        record.setThrown(e);
484:                        record.setLoggerName(logger.getName());
485:                        logger.log(record);
486:                    }
487:                    return false;
488:                }
489:                return true;
490:            }
491:
492:            public void createSymbolicLinks(final PSConfigContext configContext) {
493:
494:                //Creating links for help, voice to webcontainer docs
495:                try {
496:                    String docsDir = wcHomeDir + fs + "docs";
497:                    String helpDir = docsDir + fs + "online_help" + fs
498:                            + "docs_en_US";
499:                    String psHelpDir = configContext.getPSBaseDir() + fs
500:                            + "docs" + fs + "public_html" + fs + "online_help"
501:                            + fs + "docs_en_US";
502:                    String voiceDir = configContext.getPSBaseDir() + fs
503:                            + "export" + fs + "voice";
504:
505:                    OSTasks osTasks = OSTasksFactory.getOSTasks(configContext);
506:                    osTasks.createSymbolicLink(voiceDir, docsDir);
507:                    osTasks.createSymbolicLink(psHelpDir + fs + "ps", helpDir);
508:                    osTasks.createSymbolicLink(psHelpDir + fs + "ma", helpDir);
509:                } catch (Exception e) {
510:                    if (logger.isLoggable(Level.SEVERE)) {
511:                        LogRecord record = new LogRecord(Level.SEVERE,
512:                                "PSFB_CSPFT0040");
513:                        record.setThrown(e);
514:                        record.setLoggerName(logger.getName());
515:                        logger.log(record);
516:                    }
517:                }
518:            }
519:
520:            /**
521:             * Do required container memory settings if the appserver vm setting are the default
522:             *  i.e. if -Xmx256m setting is found
523:             *  Note: A webserver restart  is required before these settings come into play.
524:             *  The calling class should decide whether to do the restart
525:             */
526:            public boolean doJVMMemorySettings() {
527:                //JVM settings
528:                String defJVMSetting = "<JVMOPTIONS>-Xmx256m</JVMOPTIONS>";
529:                String reqJVMSetting = "<JVMOPTIONS>-Xmx512M</JVMOPTIONS>\n"
530:                        + "<JVMOPTIONS>-Xms512M</JVMOPTIONS>\n"
531:                        + "<JVMOPTIONS>-Xss128k</JVMOPTIONS>\n"
532:                        + "<JVMOPTIONS>-XX:NewSize=168M</JVMOPTIONS>\n"
533:                        + "<JVMOPTIONS>-XX:MaxNewSize=168M</JVMOPTIONS>\n"
534:                        + "<JVMOPTIONS>-XX:PermSize=192M</JVMOPTIONS>\n"
535:                        + "<JVMOPTIONS>-XX:MaxPermSize=192M</JVMOPTIONS>\n"
536:                        + "<JVMOPTIONS>-XX:+DisableExplicitGC</JVMOPTIONS>\n"
537:                        + "<JVMOPTIONS>-XX:SoftRefLRUPolicyMSPerMB=0</JVMOPTIONS>\n"
538:                        + "<JVMOPTIONS>-XX:+PrintGCTimeStamps</JVMOPTIONS>\n"
539:                        + "<JVMOPTIONS>-XX:+PrintHeapAtGC</JVMOPTIONS>\n"
540:                        + "<JVMOPTIONS>-XX:+PrintClassHistogram</JVMOPTIONS>\n"
541:                        + "<JVMOPTIONS>-Xloggc:" + wcInstanceDir + fs + "logs"
542:                        + fs + "gc.log</JVMOPTIONS>";
543:
544:                return FileUtil.replaceLineInFile(wcConfigFile, defJVMSetting,
545:                        reqJVMSetting);
546:            }
547:
548:            public void doMiscTasks(PSConfigContext configContext) {
549:                String wcConfigDir = wcInstanceDir + fs + "config";
550:                String objConf = wcConfigDir + fs + "obj.conf";
551:
552:                try {
553:                    File file = new File(objConf);
554:                    FileUtil.deleteLineInFile(file, "fn=index-common");
555:                } catch (Exception e) {
556:                    if (logger.isLoggable(Level.SEVERE)) {
557:                        logger.log(Level.SEVERE, "PSFB_CSPFT0039");
558:                        LogRecord record = new LogRecord(Level.SEVERE,
559:                                "PSFB_CSPFT0028");
560:                        record.setThrown(e);
561:                        record.setLoggerName(logger.getName());
562:                        logger.log(record);
563:                    }
564:                }
565:
566:                try {
567:                    doJVMMemorySettings();
568:                } catch (Exception e) {
569:                    if (logger.isLoggable(Level.SEVERE)) {
570:                        logger.log(Level.SEVERE, "PSFB_CSPFT0101");
571:                        LogRecord record = new LogRecord(Level.SEVERE,
572:                                "PSFB_CSPFT0101");
573:                        record.setThrown(e);
574:                        record.setLoggerName(logger.getName());
575:                        logger.log(record);
576:                    }
577:                }
578:            }
579:
580:            public void configResource(Element root, String derbyHost,
581:                    String derbyPort, String databaseName, String poolName) {
582:                try {
583:                    Element resource = new Element("RESOURCES");
584:                    Element jdbcConnectionPool = new Element(
585:                            "JDBCCONNECTIONPOOL");
586:                    Element jdbcResource = new Element("JDBCRESOURCE");
587:                    Element property1 = new Element("PROPERTY");
588:                    Element property2 = new Element("PROPERTY");
589:                    Element property3 = new Element("PROPERTY");
590:                    Element property4 = new Element("PROPERTY");
591:                    Element property5 = new Element("PROPERTY");
592:
593:                    jdbcConnectionPool.setAttribute("name", poolName);
594:                    String dataSourceClassName = root
595:                            .getAttributeValue("dataSourceClassName.SJSWS6");
596:                    if (dataSourceClassName != null
597:                            && !dataSourceClassName.equals("")
598:                            && dataSourceClassName.length() > 0) {
599:                        jdbcConnectionPool.setAttribute("datasourceclassname",
600:                                dataSourceClassName);
601:                    } else {
602:                        jdbcConnectionPool.setAttribute("datasourceclassname",
603:                                root.getAttributeValue("dataSourceClassName"));
604:                    }
605:                    jdbcConnectionPool.setAttribute("steadypoolsize", "8");
606:                    jdbcConnectionPool.setAttribute("maxpoolsize", root
607:                            .getAttributeValue("maxActive"));
608:                    jdbcConnectionPool.setAttribute("poolresizequantity", "2");
609:                    jdbcConnectionPool.setAttribute("idletimeout", root
610:                            .getAttributeValue("maxIdle"));
611:                    jdbcConnectionPool.setAttribute("maxwaittime", root
612:                            .getAttributeValue("maxWait"));
613:                    jdbcConnectionPool.setAttribute(
614:                            "connectionvalidationrequired", "off");
615:                    jdbcConnectionPool.setAttribute(
616:                            "connectionvalidationmethod", "auto-commit");
617:                    jdbcConnectionPool.setAttribute("validationtablename", "");
618:                    jdbcConnectionPool
619:                            .setAttribute("failallconnections", "off");
620:                    jdbcConnectionPool.setAttribute(
621:                            "transactionisolationlevel", "read-uncommitted");
622:                    jdbcConnectionPool.setAttribute("isolationlevelguaranteed",
623:                            "off");
624:
625:                    property1.setAttribute("name", "serverName");
626:                    property1.setAttribute("value", derbyHost);
627:
628:                    property2.setAttribute("name", "portNumber");
629:                    property2.setAttribute("value", derbyPort);
630:
631:                    property3.setAttribute("name", "User");
632:                    property3.setAttribute("value", root
633:                            .getAttributeValue("username"));
634:
635:                    property4.setAttribute("name", "Password");
636:                    property4.setAttribute("value", root
637:                            .getAttributeValue("password"));
638:
639:                    property5.setAttribute("name", "databaseName");
640:                    property5.setAttribute("value", databaseName);
641:
642:                    jdbcResource.setAttribute("jndiname", root
643:                            .getAttributeValue("name"));
644:                    jdbcResource.setAttribute("poolname", poolName);
645:                    jdbcResource.setAttribute("enabled", "on");
646:
647:                    jdbcConnectionPool.addContent(property1);
648:                    jdbcConnectionPool.addContent(property2);
649:                    jdbcConnectionPool.addContent(property3);
650:                    jdbcConnectionPool.addContent(property4);
651:                    jdbcConnectionPool.addContent(property5);
652:
653:                    resource.addContent(jdbcConnectionPool);
654:                    resource.addContent(jdbcResource);
655:
656:                    XMLOutputter output = new XMLOutputter(Format
657:                            .getPrettyFormat());
658:                    String outputStr = output.outputString(resource);
659:
660:                    String outputStr1 = output.outputString(jdbcConnectionPool);
661:                    String outputStr2 = output.outputString(jdbcResource);
662:
663:                    FileUtil.deleteLineInFile(wcConfigFile, "<RESOURCES/>");
664:                    String resStr = FileUtil.findTextInFile(wcConfigFile,
665:                            "<RESOURCES>");
666:                    if (resStr.equals("") || resStr == null
667:                            || resStr.length() == 0) {
668:                        FileUtil.appendLineInFile(wcConfigFile, "</SECURITY>",
669:                                outputStr,
670:                                FileUtil.APPEND_FIRST_OCCURANCE_STARTING_WITH);
671:                    } else {
672:                        FileUtil.appendLineInFile(wcConfigFile, "<RESOURCES>",
673:                                outputStr2,
674:                                FileUtil.APPEND_FIRST_OCCURANCE_STARTING_WITH);
675:                        FileUtil.appendLineInFile(wcConfigFile, "<RESOURCES>",
676:                                outputStr1,
677:                                FileUtil.APPEND_FIRST_OCCURANCE_STARTING_WITH);
678:                    }
679:
680:                } catch (Exception e) {
681:                    logger.log(Level.SEVERE, "PSFB_CSPFT0087", e.getMessage());
682:
683:                }
684:
685:            }
686:
687:            public void unConfigResource(String jndiName, String poolName) {
688:                try {
689:                    SAXBuilder builder = new SAXBuilder();
690:                    Document serverXMLDoc = builder.build(wcConfigFile);
691:                    Element rootElement = serverXMLDoc.getRootElement();
692:
693:                    Element resourcesElement = rootElement.getChild("JAVA")
694:                            .getChild("RESOURCES");
695:                    List resList = null;
696:                    Iterator resIterator = null;
697:                    Element currResource = null;
698:
699:                    resList = resourcesElement
700:                            .getChildren("JDBCCONNECTIONPOOL");
701:                    resIterator = resList.iterator();
702:                    while (resIterator.hasNext()) {
703:                        currResource = (Element) resIterator.next();
704:                        if (currResource.getAttributeValue("name").equals(
705:                                poolName)) {
706:                            resourcesElement.removeContent(currResource);
707:                            break;
708:                        }
709:                    }
710:
711:                    resList = resourcesElement.getChildren("JDBCRESOURCE");
712:                    resIterator = resList.iterator();
713:                    while (resIterator.hasNext()) {
714:                        currResource = (Element) resIterator.next();
715:                        if (currResource.getAttributeValue("jndiname").equals(
716:                                jndiName)) {
717:                            resourcesElement.removeContent(currResource);
718:                            break;
719:                        }
720:                    }
721:                    XMLOutputter serializer = new XMLOutputter();
722:                    serializer.output(serverXMLDoc,
723:                            new FileWriter(wcConfigFile));
724:
725:                } catch (Exception e) {
726:                    logger.log(Level.SEVERE, "PSFB_CSPFT0087", e.getMessage());
727:
728:                }
729:            }
730:
731:            public boolean removeClasspath(String classpath) {
732:                boolean removedCp = false;
733:                try {
734:                    String sOldClasspath = FileUtil.findTextInFile(
735:                            wcConfigFile, CLASSPATHSUFFIX);
736:                    String sNewClasspath = sOldClasspath.replaceAll(classpath,
737:                            cps);
738:                    removedCp = !sNewClasspath.equals(sOldClasspath);
739:                    if (!removedCp && isPortalConfigured()) {
740:                        String[] sPaths = classpath.split(cps);
741:                        sNewClasspath = sOldClasspath;
742:                        for (int i = 0; i < sPaths.length; i++) {
743:                            sNewClasspath = sNewClasspath.replaceAll(cps
744:                                    + sPaths[i] + cps, cps);
745:                        }
746:                        removedCp = !sNewClasspath.equals(sOldClasspath);
747:                    }
748:
749:                    if (removedCp) {
750:                        String sCpsPattern = cps + "[" + cps + "]*";
751:                        sNewClasspath = sNewClasspath.replaceAll(sCpsPattern,
752:                                cps);
753:                        FileUtil.replaceLineInFile(wcConfigFile, sOldClasspath,
754:                                sNewClasspath);
755:                    }
756:                } catch (Exception e) {
757:                    if (logger.isLoggable(Level.SEVERE)) {
758:                        LogRecord record = new LogRecord(Level.SEVERE,
759:                                "PSFB_CSPFT0029");
760:                        record.setThrown(e);
761:                        record.setLoggerName(logger.getName());
762:                        logger.log(record);
763:                    }
764:                    return false;
765:                }
766:                return removedCp;
767:            }
768:
769:            public void deleteSymbolicLinks(final PSConfigContext configContext) {
770:                try {
771:                    String docsDir = wcHomeDir + fs + "docs";
772:                    String helpDir = docsDir + fs + "online_help" + fs
773:                            + "docs_en_US";
774:                    OSTasks osTasks = OSTasksFactory.getOSTasks(configContext);
775:                    osTasks.removeSymbolicLink(docsDir + fs + "voice");
776:                    osTasks.removeSymbolicLink(helpDir + fs + "ps");
777:                    osTasks.removeSymbolicLink(helpDir + fs + "ma");
778:                } catch (Exception e) {
779:                    if (logger.isLoggable(Level.SEVERE)) {
780:                        LogRecord record = new LogRecord(Level.SEVERE,
781:                                "PSFB_CSPFT0038");
782:                        record.setThrown(e);
783:                        record.setLoggerName(logger.getName());
784:                        logger.log(record);
785:                    }
786:                }
787:            }
788:
789:            public void undoMiscTasks(PSConfigContext configContext) {
790:                // TODO: need to implement this method
791:            }
792:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.