Source Code Cross Referenced for DeployPortletBean.java in  » Portal » Open-Portal » com » sun » portal » admin » console » desktop » 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.admin.console.desktop 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /**
0002:         * $Id: DeployPortletBean.java,v 1.29 2006/10/24 16:36:00 cathywu Exp $
0003:         * Copyright 2005 Sun Microsystems, Inc. All
0004:         * rights reserved. Use of this product is subject
0005:         * to license terms. Federal Acquisitions:
0006:         * Commercial Software -- Government Users
0007:         * Subject to Standard License Terms and
0008:         * Conditions.
0009:         *
0010:         * Sun, Sun Microsystems, the Sun logo, and Sun ONE
0011:         * are trademarks or registered trademarks of Sun Microsystems,
0012:         * Inc. in the United States and other countries.
0013:         */package com.sun.portal.admin.console.desktop;
0014:
0015:        import java.util.ArrayList;
0016:        import java.util.LinkedList;
0017:        import java.util.Iterator;
0018:        import java.util.Map;
0019:        import java.util.HashMap;
0020:        import java.util.Set;
0021:        import java.util.HashSet;
0022:        import java.util.List;
0023:        import java.util.Properties;
0024:        import java.util.logging.Level;
0025:
0026:        import java.text.MessageFormat;
0027:
0028:        import java.io.File;
0029:        import java.io.InputStream;
0030:        import java.io.FileInputStream;
0031:        import java.io.FileOutputStream;
0032:        import java.io.FileNotFoundException;
0033:        import java.io.IOException;
0034:        import java.io.Serializable;
0035:
0036:        import java.net.InetAddress;
0037:        import java.net.UnknownHostException;
0038:
0039:        //JMX
0040:        import javax.management.ObjectName;
0041:        import javax.management.InstanceNotFoundException;
0042:        import javax.management.MBeanException;
0043:        import javax.management.MalformedObjectNameException;
0044:        import javax.management.MBeanServerConnection;
0045:
0046:        //JSF
0047:        import javax.faces.validator.ValidatorException;
0048:        import javax.faces.el.VariableResolver;
0049:        import javax.faces.context.FacesContext;
0050:        import javax.faces.component.UIComponent;
0051:        import javax.faces.application.FacesMessage;
0052:        import javax.faces.event.ActionEvent;
0053:
0054:        import com.sun.web.ui.component.Upload;
0055:        import com.sun.web.ui.model.UploadedFile;
0056:        import com.sun.web.ui.event.WizardEvent;
0057:        import com.sun.web.ui.event.WizardEventListener;
0058:
0059:        //Admin Framework
0060:        import com.sun.portal.admin.common.util.AdminClientUtil;
0061:        import com.sun.portal.admin.common.InstanceAttributes;
0062:        import com.sun.portal.admin.common.util.UploadDownloadException;
0063:        import com.sun.portal.admin.common.PSMBeanException;
0064:        import com.sun.portal.admin.console.common.PortalBaseBean;
0065:        import com.sun.portal.admin.console.common.LoginBean;
0066:        import com.sun.portal.admin.console.fabric.ListPortalsBean;
0067:
0068:        /**
0069:         * @author cathywu
0070:         */
0071:        public class DeployPortletBean extends PortalBaseBean implements 
0072:                WizardEventListener, Serializable {
0073:
0074:            public static final String RB_NAME = "desktop";
0075:            //error keys send from mbean
0076:            public static final String ERROR_STREAMREAD = "portlet.errorStreamRead";
0077:            public static final String ERROR_INVALIDWEBAPPNAME = "portlet.errorInvalidWebAppName";
0078:            public static final String CONSOLE = "console";
0079:            public static final String LOCAL = "local";
0080:
0081:            public static final int WAR = 1;
0082:            public static final int ROLES = 2;
0083:            public static final int USERS = 3;
0084:
0085:            private Thread t;
0086:            private String cancelText = "Cancel";
0087:            private Map rbMap;
0088:            private String warFileName = null;
0089:            //ui:upload variables
0090:            transient private UploadedFile uploadedWarFile;
0091:            transient private UploadedFile uploadedRolesFile;
0092:            transient private UploadedFile uploadedUsersFile;
0093:            //path value input from user, passed in by hidden field
0094:            private String warPath = "";
0095:            private String rolesPath = "";
0096:            private String usersPath = "";
0097:            //full file path uploaded from the server side
0098:            private String warFile = null;
0099:            private String file = null;
0100:            private String ufile = null;
0101:
0102:            private String rolesFileName = null;
0103:            private String usersFileName = null;
0104:            private String warName = null;
0105:            //other variables used in jsp
0106:            private boolean disableUndeploy = false;
0107:            private boolean inProgress = false;
0108:            private String server = null;
0109:
0110:            private File lookin = null;
0111:            private boolean rb0Selected = true;
0112:            private boolean rb1Selected = false;
0113:            private boolean rb3Selected = true;
0114:            private boolean rb4Selected = false;
0115:            private boolean rb5Selected = true;
0116:            private boolean rb6Selected = false;
0117:
0118:            //Member variables for portalId, JMXConnection, and pasHost
0119:            private String dn;
0120:            private String portalId;
0121:            private MBeanServerConnection mbsc;
0122:            private String pasHost;
0123:            private boolean isLocal = true;
0124:            private String tmpDest = null;
0125:            private boolean clientTmpFile = false;
0126:
0127:            //alert member variables
0128:            private Boolean displayError;
0129:            private String alertSummary;
0130:            private String alertDetail;
0131:            private String alertType;
0132:
0133:            //webcontainer type
0134:            private boolean hasWebLogicAdminServerInstance = false;
0135:
0136:            public DeployPortletBean() {
0137:                if (t != null) {
0138:                    t.interrupt();
0139:                }
0140:
0141:                rbMap = getResourceStringMap(RB_NAME);
0142:                if (rbMap != null) {
0143:                    cancelText = (String) rbMap.get("cancel.button");
0144:                }
0145:                if (mbsc == null) {
0146:                    mbsc = getMBeanServerConnection();
0147:                }
0148:
0149:                dn = (String) getCurrentDN();
0150:                portalId = getPortalId();
0151:                setDisplayError(Boolean.FALSE);
0152:
0153:                if (portalId == null) {
0154:                    FacesContext context = FacesContext.getCurrentInstance();
0155:                    VariableResolver vr = context.getApplication()
0156:                            .getVariableResolver();
0157:                    Object obj = (Object) vr.resolveVariable(context,
0158:                            "ListPortalsBean");
0159:                    if ((obj != null) && (obj instanceof  ListPortalsBean)) {
0160:                        ListPortalsBean epropsbean = (ListPortalsBean) obj;
0161:                        portalId = epropsbean.getCurrentPortal();
0162:                        setSessionAttribute(ATTR_SELECTED_PORTAL, portalId);
0163:                    }
0164:                }
0165:
0166:                if (dn == null) {
0167:                    dn = GLOBAL_LOCATION_DN;
0168:                }
0169:
0170:                try {
0171:                    server = InetAddress.getLocalHost().getHostName();
0172:                } catch (UnknownHostException ukhe) {
0173:                    server = "localhost";
0174:                }
0175:
0176:                String osName = System.getProperty("os.name").toUpperCase();
0177:                if (osName.startsWith("WINDOW")) {
0178:                    lookin = new File("c:\\\\");
0179:                } else {
0180:                    lookin = new File("/");
0181:                }
0182:
0183:                hasWebLogicAdminServerInstance = hasWebLogicAdminServerInstance(portalId);
0184:            }
0185:
0186:            /**
0187:             * File chooser methods
0188:             */
0189:
0190:            public String getServer() {
0191:                return server;
0192:            }
0193:
0194:            /**
0195:             * Lookin
0196:             */
0197:            public File getLookin() {
0198:                return lookin;
0199:            }
0200:
0201:            /**
0202:             * War file name methods
0203:             */
0204:
0205:            public String getWarPath() {
0206:                return warPath;
0207:            }
0208:
0209:            public void setWarPath(String path) {
0210:                warPath = path;
0211:            }
0212:
0213:            public String getWarFileName() {
0214:                return warFileName;
0215:            }
0216:
0217:            public void setWarFileName(String value) {
0218:                warFileName = value;
0219:            }
0220:
0221:            public UploadedFile getUploadedWarFile() {
0222:                return this .uploadedWarFile;
0223:            }
0224:
0225:            public void setUploadedWarFile(UploadedFile file) {
0226:                this .uploadedWarFile = file;
0227:            }
0228:
0229:            public void setRb0Selected(boolean o) {
0230:                rb0Selected = o;
0231:            }
0232:
0233:            public boolean getRb0Selected() {
0234:                return rb0Selected;
0235:            }
0236:
0237:            public void setRb1Selected(boolean o) {
0238:                rb1Selected = o;
0239:            }
0240:
0241:            public boolean getRb1Selected() {
0242:                return rb1Selected;
0243:            }
0244:
0245:            public boolean getIsLocal() {
0246:                //calling isLocal() from PortalBaseBean
0247:                log(Level.INFO, "DeployPortletBean.getIsLocal(), isLocal:"
0248:                        + isLocal());
0249:                return isLocal();
0250:            }
0251:
0252:            public void validateWarFileName(FacesContext ctx, UIComponent comp,
0253:                    Object value) {
0254:
0255:                log(Level.INFO, "validateWarFileName, selected:" + rb1Selected);
0256:
0257:                if (getRb1Selected() == true) {
0258:                    String warFileName = (String) value;
0259:                    String sm = (String) rbMap
0260:                            .get("error.deployPortlet.validation.summary");
0261:                    String dm = (String) rbMap
0262:                            .get("error.deployPortlet.war.file.extension");
0263:
0264:                    log(Level.INFO, "validateWarFileName, warfile path:"
0265:                            + warFileName);
0266:                    if ((rb1Selected == true && warFileName == null)
0267:                            || (rb1Selected == true && !warFileName
0268:                                    .endsWith(".war"))) {
0269:                        throw new ValidatorException(new FacesMessage(sm, dm));
0270:                    }
0271:
0272:                    if (warFileName != null) {
0273:                        File f = new File(warFileName);
0274:                        if (!f.isAbsolute()) {
0275:                            dm = (String) rbMap
0276:                                    .get("error.deployPortlet.full.path.required");
0277:                            throw new ValidatorException(new FacesMessage(sm,
0278:                                    dm));
0279:                        }
0280:                    }
0281:                }
0282:            }
0283:
0284:            private boolean validateUploadedWarFile() {
0285:                if (getRb0Selected() == true) {
0286:                    String warFileName = uploadedWarFile.getOriginalName();
0287:                    if (warFileName == null || warFileName.length() == 0
0288:                            || !warFileName.endsWith(".war")) {
0289:                        return false;
0290:                    }
0291:                } else {
0292:                    String warFileName = getWarFileName();
0293:                    if (warFileName == null || warFileName.length() == 0
0294:                            || !warFileName.endsWith(".war")) {
0295:                        return false;
0296:                    }
0297:                }
0298:
0299:                return true;
0300:            }
0301:
0302:            /**
0303:             * Roles file name methods
0304:             */
0305:
0306:            public UploadedFile getUploadedRolesFile() {
0307:                return this .uploadedRolesFile;
0308:            }
0309:
0310:            public void setUploadedRolesFile(UploadedFile file) {
0311:                this .uploadedRolesFile = file;
0312:            }
0313:
0314:            public String getRolesPath() {
0315:                if (rolesPath != null && rolesPath.length() > 0) {
0316:                    return rolesPath;
0317:                } else {
0318:                    return (String) rbMap.get("deployPortlet.noRolesFile");
0319:                }
0320:            }
0321:
0322:            public void setRolesPath(String path) {
0323:                rolesPath = path;
0324:            }
0325:
0326:            public String getRolesFileName() {
0327:                return rolesFileName;
0328:            }
0329:
0330:            public void setRolesFileName(String value) {
0331:                rolesFileName = value;
0332:            }
0333:
0334:            public void setRb3Selected(boolean o) {
0335:                rb3Selected = o;
0336:            }
0337:
0338:            public boolean getRb3Selected() {
0339:                return rb3Selected;
0340:            }
0341:
0342:            public void setRb4Selected(boolean o) {
0343:                rb4Selected = o;
0344:            }
0345:
0346:            public boolean getRb4Selected() {
0347:                return rb4Selected;
0348:            }
0349:
0350:            /**
0351:             * Users file name methods
0352:             */
0353:
0354:            public UploadedFile getUploadedUsersFile() {
0355:                return this .uploadedUsersFile;
0356:            }
0357:
0358:            public void setUploadedUsersFile(UploadedFile file) {
0359:                this .uploadedUsersFile = file;
0360:            }
0361:
0362:            public String getUsersPath() {
0363:                if (usersPath != null && usersPath.length() > 0) {
0364:                    return usersPath;
0365:                } else {
0366:                    return (String) rbMap.get("deployPortlet.noUsersFile");
0367:                }
0368:            }
0369:
0370:            public void setUsersPath(String path) {
0371:                usersPath = path;
0372:            }
0373:
0374:            public String getUsersFileName() {
0375:                return usersFileName;
0376:            }
0377:
0378:            public void setUsersFileName(String value) {
0379:                usersFileName = value;
0380:            }
0381:
0382:            public void setRb5Selected(boolean o) {
0383:                rb5Selected = o;
0384:            }
0385:
0386:            public boolean getRb5Selected() {
0387:                return rb5Selected;
0388:            }
0389:
0390:            public void setRb6Selected(boolean o) {
0391:                rb6Selected = o;
0392:            }
0393:
0394:            public boolean getRb6Selected() {
0395:                return rb6Selected;
0396:            }
0397:
0398:            private void validatePropertiesFileName(FacesContext ctx,
0399:                    UIComponent comp, Object value) {
0400:
0401:                log(Level.INFO, "valiatePropertiesFileName, value: "
0402:                        + (String) value);
0403:                String propFileName = (String) value;
0404:                String sm = (String) rbMap
0405:                        .get("error.deployPortlet.validation.summary");
0406:                String dm = (String) rbMap
0407:                        .get("error.deployPortlet.property.file.extension");
0408:                if (!propFileName.endsWith(".properties")) {
0409:                    throw new ValidatorException(new FacesMessage(sm, dm));
0410:                }
0411:
0412:                File f = new File(propFileName);
0413:
0414:                if (!f.isAbsolute()) {
0415:                    dm = (String) rbMap
0416:                            .get("error.deployPortlet.full.path.required");
0417:                    throw new ValidatorException(new FacesMessage(sm, dm));
0418:                }
0419:
0420:                if (!f.exists()) {
0421:                    String fullPath = f.getAbsolutePath();
0422:                    Object[] tokens = { fullPath };
0423:
0424:                    dm = (String) rbMap.get("error.file.or.dir.not.found");
0425:                    MessageFormat mf = new MessageFormat(dm);
0426:                    dm = mf.format(tokens);
0427:
0428:                    throw new ValidatorException(new FacesMessage(sm, dm));
0429:                }
0430:            }
0431:
0432:            public void validateRolesFileName(FacesContext ctx,
0433:                    UIComponent comp, Object value) {
0434:
0435:                if (getRb4Selected() == true) {
0436:                    validatePropertiesFileName(ctx, comp, value);
0437:                }
0438:            }
0439:
0440:            public void validateUsersFileName(FacesContext ctx,
0441:                    UIComponent comp, Object value) {
0442:
0443:                if (getRb6Selected() == true) {
0444:                    validatePropertiesFileName(ctx, comp, value);
0445:                }
0446:            }
0447:
0448:            private boolean validateUploadedRolesFile() {
0449:                if (getRb3Selected() == true) {
0450:                    String propFileName = uploadedRolesFile.getOriginalName();
0451:                    if (propFileName != null && propFileName.length() != 0
0452:                            && !propFileName.endsWith(".properties")) {
0453:                        return false;
0454:                    }
0455:                } else {
0456:                    String propFileName = getRolesFileName();
0457:                    if (propFileName != null && propFileName.length() != 0
0458:                            && !propFileName.endsWith(".properties")) {
0459:                        return false;
0460:                    }
0461:                }
0462:
0463:                return true;
0464:            }
0465:
0466:            private boolean validateUploadedUsersFile() {
0467:
0468:                if (getRb5Selected() == true) {
0469:                    String propFileName = uploadedUsersFile.getOriginalName();
0470:                    if (propFileName != null && propFileName.length() != 0
0471:                            && !propFileName.endsWith(".properties")) {
0472:                        return false;
0473:                    }
0474:                } else {
0475:                    String propFileName = getUsersFileName();
0476:                    if (propFileName != null && propFileName.length() != 0
0477:                            && !propFileName.endsWith(".properties")) {
0478:                        return false;
0479:                    }
0480:                }
0481:
0482:                return true;
0483:            }
0484:
0485:            //============================================================
0486:            // War name methods
0487:            //============================================================
0488:
0489:            public String getWarName() {
0490:                if (warName == null) {
0491:                    setCancelText((String) rbMap.get("cancel.button"));
0492:                    setDisableUndeploy(false);
0493:                    setDisplayError(new Boolean(false));
0494:                    if (isInProgress()) {
0495:                        setInProgress(false);
0496:                    }
0497:                }
0498:                return warName;
0499:            }
0500:
0501:            public void setWarName(String value) {
0502:                warName = value;
0503:            }
0504:
0505:            /**
0506:             * inProgress methods
0507:             */
0508:            public boolean isInProgress() {
0509:                return inProgress;
0510:            }
0511:
0512:            public void setInProgress(boolean val) {
0513:                inProgress = val;
0514:            }
0515:
0516:            /**
0517:             * disable deploy, undeploy methods
0518:             */
0519:            public boolean isDisableUndeploy() {
0520:                return disableUndeploy;
0521:            }
0522:
0523:            public void setDisableUndeploy(boolean val) {
0524:                disableUndeploy = val;
0525:            }
0526:
0527:            /**
0528:             * cancel methods
0529:             */
0530:
0531:            public String getCancelText() {
0532:                return cancelText;
0533:            }
0534:
0535:            public void setCancelText(String val) {
0536:                cancelText = val;
0537:            }
0538:
0539:            public String cancel() {
0540:                if (t != null) {
0541:                    t.interrupt();
0542:                }
0543:
0544:                setDisplayError(new Boolean(false));
0545:                return "cancel";
0546:            }
0547:
0548:            /**
0549:             * beginDeploy methods
0550:             */
0551:            public String beginDeploy() {
0552:
0553:                if (inProgress == true) {
0554:                    setupAlert(null, "error.deployPortlet.summary",
0555:                            "error.deployPortlet.alreadyRunning", "error");
0556:                    return null;
0557:                }
0558:
0559:                setInProgress(true);
0560:                dn = (String) getCurrentDN();
0561:                t = new CreateThread(this , dn, "deploy");
0562:                t.start();
0563:                return null;
0564:            }
0565:
0566:            /**
0567:             * beginUndeploy methods
0568:             */
0569:            public String beginUndeploy() {
0570:
0571:                if (inProgress == true) {
0572:                    setupAlert(null, "error.undeployPortlet.summary",
0573:                            "error.undeployPortlet.alreadyRunning", "error");
0574:                    return null;
0575:                }
0576:
0577:                setInProgress(true);
0578:                dn = (String) getCurrentDN();
0579:                t = new CreateThread(this , dn, "undeploy");
0580:                t.start();
0581:                return null;
0582:            }
0583:
0584:            /**
0585:             * Deploy operation
0586:             */
0587:
0588:            public void doUpload() {
0589:                try {
0590:                    //get war file from local machine
0591:                    if (getRb0Selected() == true) {
0592:                        log(Level.INFO, "uploaded war file:"
0593:                                + uploadedWarFile.getOriginalName());
0594:                        log(Level.INFO, "uploaded war path:" + getWarPath());
0595:                        warFile = writeFile(WAR);
0596:                    }
0597:
0598:                    //get war file from portal server machine
0599:                    if (getRb1Selected() == true) {
0600:                        warFile = warPath = getWarFileName();
0601:                    }
0602:
0603:                    if (getRb4Selected() == true) {
0604:                        file = rolesPath = getRolesFileName();
0605:                    }
0606:
0607:                    if (getRb3Selected() == true) {
0608:                        file = writeFile(ROLES);
0609:                    }
0610:
0611:                    if (getRb6Selected() == true) {
0612:                        ufile = usersPath = getUsersFileName();
0613:                    }
0614:
0615:                    if (getRb5Selected() == true) {
0616:                        ufile = writeFile(USERS);
0617:                    }
0618:                } catch (PSMBeanException pe) {
0619:                    setupAlert(pe.getTokens(), "error.deployPortlet.summary",
0620:                            pe.getErrorKey(), "error");
0621:                }
0622:
0623:            }
0624:
0625:            public String doDeploy(Thread t, String dn) {
0626:
0627:                Boolean global = Boolean.FALSE;
0628:                Properties rolesProperties;
0629:                Properties usersProperties;
0630:
0631:                log(Level.INFO, "DeployPortletBean.doDeploy(), dn:" + dn);
0632:
0633:                if (dn.equals(GLOBAL_LOCATION_DN)) {
0634:                    global = Boolean.TRUE;
0635:                }
0636:
0637:                try {
0638:                    rolesProperties = loadProperties(file);
0639:                    usersProperties = loadProperties(ufile);
0640:
0641:                    String[] signature = { "java.lang.String",
0642:                            "java.lang.Boolean", "java.lang.String",
0643:                            "java.util.Properties", "java.util.Properties",
0644:                            "java.lang.Boolean", "java.util.List",
0645:                            "java.lang.Boolean", "java.lang.Boolean" };
0646:                    Object[] params = { dn, global, warFile, rolesProperties,
0647:                            usersProperties, Boolean.FALSE, null, Boolean.TRUE,
0648:                            Boolean.FALSE };
0649:
0650:                    LinkedList path = new LinkedList();
0651:                    path.addFirst(getDomain());
0652:                    path.addFirst(portalId);
0653:                    path.addFirst(AdminClientUtil.PORTLET_ADMIN_MBEAN);
0654:                    ObjectName objName = AdminClientUtil
0655:                            .getResourceMBeanObjectName(
0656:                                    AdminClientUtil.PORTLET_ADMIN_MBEAN_TYPE,
0657:                                    path);
0658:
0659:                    //deployedAll is True if all instances are deployed successfully
0660:                    Boolean deployedAll = (Boolean) mbsc.invoke(objName,
0661:                            "deployAll", params, signature);
0662:
0663:                    String appName = warFile.substring(warFile
0664:                            .lastIndexOf(File.separator) + 1, warFile.length());
0665:                    appName = appName.substring(0, appName.indexOf(".war"));
0666:
0667:                    //check if any of the instances are on weblogic admin server
0668:                    //If they are, show an info message asking the user to deploy
0669:                    //the war file manually from the weblogic admin console
0670:                    //deploy doesn't deploy to container if it is a weblogic
0671:                    // adminserver
0672:
0673:                    Object[] tokens = { appName };
0674:                    if (hasWebLogicAdminServerInstance) {
0675:                        setupAlert(tokens, "deployPortlet.summary",
0676:                                "deployPortlet.manualdeploy", "information");
0677:                    } else if (!deployedAll.booleanValue()) {
0678:                        setupAlert(tokens, "deployPortlet.summary",
0679:                                "portlet.notDeployedAtAllInstances",
0680:                                "information");
0681:                    } else {
0682:                        setupAlert(tokens, "deployPortlet.summary",
0683:                                "deployPortlet.completed", "information");
0684:                    }
0685:                } catch (FileNotFoundException fe) {
0686:                    log(Level.SEVERE,
0687:                            "Exception in DeployPortletBean.doDeploy()", fe);
0688:
0689:                    if (inProgress == true) {
0690:                        t.interrupt();
0691:                        inProgress = false;
0692:                    }
0693:
0694:                    Object[] tokens = { file };
0695:                    setupAlert(tokens, "error.deployPortlet.summary",
0696:                            "error.file.or.dir.not.found", "error");
0697:                } catch (MBeanException me) {
0698:                    String errorKey = null;
0699:                    log(Level.SEVERE,
0700:                            "DeployPortletBean.doDeploy(), Exeption: ", me);
0701:
0702:                    if (inProgress == true) {
0703:                        t.interrupt();
0704:                        inProgress = false;
0705:                    }
0706:
0707:                    if (me.getCause() instanceof  PSMBeanException) {
0708:
0709:                        PSMBeanException pme = (PSMBeanException) me.getCause();
0710:
0711:                        errorKey = pme.getErrorKey();
0712:                        if (errorKey != null) {
0713:                            setupAlert(pme.getTokens(),
0714:                                    "error.deployPortlet.summary", errorKey,
0715:                                    "error");
0716:                        }
0717:                    }
0718:                    if (errorKey == null) {
0719:                        setupAlert(null, "error.deployPortlet.summary",
0720:                                "error.deployPortlet.failed.checkLogs", "error");
0721:                    }
0722:                } catch (Exception ex) {
0723:                    log(Level.SEVERE,
0724:                            "Exception in DeployPortletBean.doDeploy()", ex);
0725:
0726:                    if (inProgress == true) {
0727:                        t.interrupt();
0728:                        inProgress = false;
0729:                    }
0730:
0731:                    setupAlert(null, "error.deployPortlet.summary",
0732:                            "error.deployPortlet.failed.checkLogs", "error");
0733:                } finally {
0734:                    cleanUpTempFile();
0735:                }
0736:
0737:                return "done";
0738:            }
0739:
0740:            private String writeFile(int type) throws PSMBeanException {
0741:                String fileName = null;
0742:
0743:                try {
0744:
0745:                    String name = null;
0746:
0747:                    switch (type) {
0748:                    case WAR:
0749:                        name = uploadedWarFile.getOriginalName();
0750:                        break;
0751:                    case ROLES:
0752:                        name = uploadedRolesFile.getOriginalName();
0753:                        break;
0754:                    case USERS:
0755:                        name = uploadedUsersFile.getOriginalName();
0756:                        break;
0757:                    }
0758:
0759:                    //roles file and users file are optional
0760:                    if (type != WAR && (name == null || name.length() == 0)) {
0761:                        return null;
0762:                    }
0763:
0764:                    if (name.indexOf(File.separator) != -1) {
0765:                        int ind = name.lastIndexOf(File.separator);
0766:                        log(Level.INFO, "writeFile, ind:" + ind);
0767:                        name = name.substring(ind + 1, name.length());
0768:                    } else if (name.indexOf('\\') != -1) {
0769:                        int ind = name.lastIndexOf('\\');
0770:                        log(Level.INFO, "writeFile, ind:" + ind);
0771:                        name = name.substring(ind + 1, name.length());
0772:                    }
0773:
0774:                    String tmpDir = System.getProperty("java.io.tmpdir");
0775:
0776:                    //log(Level.INFO,"writeFile, tmpDir:" + tmpDir);
0777:
0778:                    if (!tmpDir.endsWith(File.separator)) {
0779:                        tmpDir = tmpDir + File.separator;
0780:                    }
0781:
0782:                    File tmpFile = new File(tmpDir + name);
0783:                    File tmpUsersFile = null;
0784:                    File tmpRolesFile = null;
0785:
0786:                    switch (type) {
0787:                    case WAR:
0788:                        uploadedWarFile.write(tmpFile);
0789:                        fileName = tmpFile.getAbsolutePath();
0790:
0791:                        log(Level.INFO, "absolute war file name:" + fileName);
0792:                        break;
0793:                    case ROLES:
0794:                        tmpRolesFile = new File(tmpDir + name);
0795:                        uploadedRolesFile.write(tmpRolesFile);
0796:                        fileName = tmpRolesFile.getAbsolutePath();
0797:                        break;
0798:                    case USERS:
0799:                        tmpUsersFile = new File(tmpDir + name);
0800:                        uploadedUsersFile.write(tmpUsersFile);
0801:                        fileName = tmpUsersFile.getAbsolutePath();
0802:                        break;
0803:                    }
0804:
0805:                } catch (IOException ie) {
0806:                    Object[] tokens = { fileName };
0807:                    log(Level.SEVERE, "DeployPortletBean.writeFile()", ie);
0808:                    throw new PSMBeanException("error.deployPortlet.writeFile",
0809:                            ie.getMessage(), tokens);
0810:                } catch (Exception e) {
0811:                    Object[] tokens = { fileName };
0812:                    log(Level.SEVERE, "DeployPortletBean.writeFile()", e);
0813:                    throw new PSMBeanException("error.deployPortlet.writeFile",
0814:                            e.getMessage(), tokens);
0815:
0816:                }
0817:                //if file is remote from portal server machine, upload the file 
0818:                String[] dest = null;
0819:                if (!getIsLocal()) {
0820:                    dest = uploadFile(fileName);
0821:                    fileName = dest[1];
0822:                    log(Level.INFO,
0823:                            "DeployPortletBean.writeFile(), upload file to portal server location: "
0824:                                    + fileName);
0825:                    tmpDest = dest[0];
0826:                }
0827:
0828:                clientTmpFile = true;
0829:                return fileName;
0830:
0831:            }
0832:
0833:            private void cleanUpTempFile() {
0834:                //clean up temp files
0835:                try {
0836:                    if (tmpDest != null) {
0837:                        AdminClientUtil.uploadDownloadCleanUp(mbsc,
0838:                                getDomain(), tmpDest);
0839:                    }
0840:                } catch (UploadDownloadException upe) {
0841:                    log(Level.SEVERE,
0842:                            "DeployPortletBean.cleanUpTemp(). Having problem clean up upload file:"
0843:                                    + tmpDest, upe);
0844:                } finally {
0845:                    tmpDest = null;
0846:                }
0847:                //delete client tmp files
0848:                if (clientTmpFile) {
0849:                    try {
0850:                        if (warFile != null) {
0851:                            File tmp = new File(warFile);
0852:                            if (tmp.exists()) {
0853:                                tmp.delete();
0854:                            }
0855:                        }
0856:                        if (file != null) {
0857:                            File tmp = new File(file);
0858:                            if (tmp.exists()) {
0859:                                tmp.delete();
0860:                            }
0861:                        }
0862:                        if (ufile != null) {
0863:                            File tmp = new File(ufile);
0864:                            if (tmp.exists()) {
0865:                                tmp.delete();
0866:                            }
0867:                        }
0868:                    } catch (Exception e) {
0869:                        //ignore
0870:                    }
0871:                    clientTmpFile = false;
0872:                }
0873:            }
0874:
0875:            private String[] uploadFile(String fileName)
0876:                    throws PSMBeanException {
0877:
0878:                String[] dest = new String[2];
0879:                try {
0880:                    dest = AdminClientUtil.uploadFile(mbsc, getDomain(),
0881:                            new File(fileName), 0);
0882:                } catch (UploadDownloadException upde) {
0883:                    Object[] tokens = { fileName };
0884:                    log(Level.SEVERE, "DeployPortletBean.uploadFile", upde);
0885:                    throw new PSMBeanException(
0886:                            "error.deployPortlet.uploadFailed", upde
0887:                                    .getMessage(), tokens);
0888:                }
0889:                return dest;
0890:            }
0891:
0892:            public String doUndeploy(Thread t, String dn) {
0893:
0894:                log(Level.INFO, "DeployPortletBean.doUndeploy(), dn:" + dn);
0895:                Boolean global = Boolean.FALSE;
0896:
0897:                if (dn.equals(GLOBAL_LOCATION_DN)) {
0898:                    global = Boolean.TRUE;
0899:                }
0900:
0901:                try {
0902:
0903:                    String[] signature = { "java.lang.String",
0904:                            "java.lang.Boolean", "java.lang.String",
0905:                            "java.lang.Boolean", "java.util.List",
0906:                            "java.lang.Boolean" };
0907:
0908:                    Object[] params = { dn, global, getWarName(),
0909:                            Boolean.FALSE, null, Boolean.TRUE };
0910:
0911:                    LinkedList path = new LinkedList();
0912:                    path.addFirst(getDomain());
0913:                    path.addFirst(portalId);
0914:                    path.addFirst(AdminClientUtil.PORTLET_ADMIN_MBEAN);
0915:                    ObjectName objName = AdminClientUtil
0916:                            .getResourceMBeanObjectName(
0917:                                    AdminClientUtil.PORTLET_ADMIN_MBEAN_TYPE,
0918:                                    path);
0919:                    //deployedAll is True if all instances are deployed successfully
0920:                    Boolean deployedAll = (Boolean) mbsc.invoke(objName,
0921:                            "undeployAll", params, signature);
0922:
0923:                    //check if any of the instances are on weblogic admin server
0924:                    //If they are, show an info message asking the user to undeploy
0925:                    //the war file manually from the weblogic admin console
0926:                    //undeploy doesn't undeploy from container if it is a weblogic adminserver
0927:                    log(Level.INFO, "Undeploy portlet, app name:"
0928:                            + getWarName());
0929:                    Object[] tokens = { getWarName() };
0930:                    if (hasWebLogicAdminServerInstance) {
0931:                        setupAlert(tokens, "undeployPortlet.summary",
0932:                                "undeployPortlet.manualundeploy", "information");
0933:                    } else if (!deployedAll.booleanValue()) {
0934:                        setupAlert(tokens, "undeployPortlet.summary",
0935:                                "portlet.notUnDeployedAtAllInstances",
0936:                                "information");
0937:                    } else {
0938:                        setupAlert(tokens, "undeployPortlet.summary",
0939:                                "undeployPortlet.completed", "information");
0940:                    }
0941:                    setCancelText((String) rbMap.get("close.button"));
0942:                    setDisableUndeploy(true);
0943:                } catch (InstanceNotFoundException ie) {
0944:                    log(Level.SEVERE,
0945:                            "Exception in DeployPortletBean.doUndeploy()", ie);
0946:                    if (inProgress == true) {
0947:                        t.interrupt();
0948:                        inProgress = false;
0949:                    }
0950:                    setupAlert(null, "error.undeployPortlet.summary",
0951:                            "error.undeployPortlet.failed", "error");
0952:                } catch (MBeanException me) {
0953:                    String errorKey = null;
0954:                    log(Level.SEVERE,
0955:                            "MBeanException DeployPortletBean.doUndeploy()", me);
0956:                    if (inProgress == true) {
0957:                        t.interrupt();
0958:                        inProgress = false;
0959:                    }
0960:                    if (me.getCause() instanceof  PSMBeanException) {
0961:
0962:                        PSMBeanException pme = (PSMBeanException) me.getCause();
0963:
0964:                        errorKey = pme.getErrorKey();
0965:                        if (errorKey != null) {
0966:                            if (errorKey.equals(ERROR_STREAMREAD)
0967:                                    || errorKey.equals(ERROR_INVALIDWEBAPPNAME)) {
0968:                                setupAlert(
0969:                                        null,
0970:                                        "error.undeployPortlet.summary",
0971:                                        "error.undeployPortlet.invalidWebAppName",
0972:                                        "error");
0973:                            } else {
0974:                                setupAlert(pme.getTokens(),
0975:                                        "error.undeployPortlet.summary",
0976:                                        errorKey, "error");
0977:                            }
0978:                        }
0979:                    }
0980:                    if (errorKey == null) {
0981:                        setupAlert(null, "error.undeployPortlet.summary",
0982:                                "error.undeployPortlet.failed.checkLogs",
0983:                                "error");
0984:                    }
0985:                } catch (Exception ex) {
0986:                    log(Level.SEVERE,
0987:                            "Exception in DeployPortletBean.doUndeploy()", ex);
0988:
0989:                    if (inProgress == true) {
0990:                        t.interrupt();
0991:                        inProgress = false;
0992:                    }
0993:                    setupAlert(null, "error.undeployPortlet.summary",
0994:                            "error.undeployPortlet.failed.checkLogs", "error");
0995:                } finally {
0996:                    setWarName(null);
0997:                }
0998:
0999:                return "";
1000:            }
1001:
1002:            /**
1003:             * Alert methods
1004:             */
1005:            public Boolean getDisplayError() {
1006:                return displayError;
1007:            }
1008:
1009:            public void setDisplayError(Boolean value) {
1010:                displayError = value;
1011:            }
1012:
1013:            public String getAlertSummary() {
1014:                return alertSummary;
1015:            }
1016:
1017:            public void setAlertSummary(String summary) {
1018:                alertSummary = summary;
1019:            }
1020:
1021:            public String getAlertDetail() {
1022:                return alertDetail;
1023:            }
1024:
1025:            public void setAlertDetail(String detail) {
1026:                alertDetail = detail;
1027:            }
1028:
1029:            public String getAlertType() {
1030:                return alertType;
1031:            }
1032:
1033:            public void setAlertType(String type) {
1034:                alertType = type;
1035:            }
1036:
1037:            /**
1038:             * Alert Utility methods
1039:             */
1040:
1041:            public void setupAlert(Object[] tokens, String summary,
1042:                    String detail, String type) {
1043:
1044:                String sm = (String) rbMap.get(summary);
1045:                String dm = (String) rbMap.get(detail);
1046:
1047:                if (dm != null && tokens != null) {
1048:                    MessageFormat mf = new MessageFormat(dm);
1049:                    dm = mf.format(tokens);
1050:                }
1051:                // if message can not be found in the resource bundle, use the 
1052:                // key
1053:                if (dm == null) {
1054:                    dm = detail;
1055:                }
1056:
1057:                setDisplayError(new Boolean(true));
1058:                setAlertSummary(sm);
1059:                setAlertDetail(dm);
1060:                setAlertType(type);
1061:            }
1062:
1063:            /**
1064:             * utility methods
1065:             */
1066:            public Properties loadProperties(String fileName)
1067:                    throws IOException {
1068:                Properties properties = new Properties();
1069:                if (fileName != null && fileName.length() != 0) {
1070:                    File f = new File(fileName);
1071:                    FileInputStream fis = new FileInputStream(f);
1072:                    properties.load(fis);
1073:                    fis.close();
1074:                }
1075:
1076:                return properties;
1077:            }
1078:
1079:            class CreateThread extends Thread {
1080:                DeployPortletBean bean = null;
1081:                String dn = null;
1082:                String type = null;
1083:
1084:                CreateThread(DeployPortletBean bean, String dn, String type) {
1085:                    this .bean = bean;
1086:                    this .dn = dn;
1087:                    this .type = type;
1088:                }
1089:
1090:                public void run() {
1091:                    if (type.equals("deploy")) {
1092:                        bean.doDeploy(this , dn);
1093:                    } else {
1094:                        bean.doUndeploy(this , dn);
1095:                    }
1096:                    setInProgress(false);
1097:                }
1098:            }
1099:
1100:            public void reset() {
1101:                setWarFileName(null);
1102:                setRolesFileName(null);
1103:                setUsersFileName(null);
1104:                setRb0Selected(true);
1105:                setRb3Selected(true);
1106:                setRb5Selected(true);
1107:                setRb1Selected(false);
1108:                setRb4Selected(false);
1109:                setRb6Selected(false);
1110:                setUploadedWarFile(null);
1111:                setUploadedRolesFile(null);
1112:                setUploadedUsersFile(null);
1113:                setWarPath(null);
1114:                setRolesPath(null);
1115:                setUsersPath(null);
1116:            }
1117:
1118:            public boolean handleEvent(WizardEvent event) {
1119:                String id = event.getWizard().getCurrentStep().getId();
1120:                switch (event.getNavigationEvent()) {
1121:                case WizardEvent.COMPLETE:
1122:                    //log(Level.SEVERE, "DeployPortletBean(), COMPLETE");
1123:                case WizardEvent.START:
1124:                    //log(Level.SEVERE, "DeployPortletBean(), START");
1125:                    reset();
1126:                    break;
1127:                case WizardEvent.GOTOSTEP:
1128:                    //log(Level.SEVERE, "DeployPortletBean(), GOTOStep, event id:"+id);
1129:                    if (id.equals("step3")) {
1130:                        reset();
1131:                    }
1132:
1133:                    break;
1134:                case WizardEvent.PREVIOUS:
1135:                    //log(Level.SEVERE, "DeployPortletBean(), event id:"+id);
1136:                    if (id.equals("step3")) {
1137:                        reset();
1138:                    }
1139:
1140:                    break;
1141:                case WizardEvent.NEXT:
1142:                    //log(Level.SEVERE, "DeployPortletBean(), event id:"+id);
1143:                    if (id.equals("step2")) {
1144:                        if (!validateUploadedWarFile()) {
1145:                            log(Level.SEVERE,
1146:                                    "DeployPortletBean(), uploaded war file validation failed");
1147:                            //reset();                      
1148:                            return false;
1149:                        }
1150:                        if (!validateUploadedRolesFile()) {
1151:                            log(Level.SEVERE,
1152:                                    "DeployPortletBean(), uploaded roles file validation failed");
1153:                            //reset();                       
1154:                            return false;
1155:                        }
1156:                        if (!validateUploadedUsersFile()) {
1157:                            log(Level.SEVERE,
1158:                                    "DeployPortletBean(), uploaded users file validation failed");
1159:                            //reset();                       
1160:                            return false;
1161:                        }
1162:                        doUpload();
1163:                    }
1164:                    break;
1165:                case WizardEvent.FINISH:
1166:                    setDisplayError(new Boolean(false));
1167:                    beginDeploy();
1168:                    break;
1169:                case WizardEvent.CLOSE:
1170:                case WizardEvent.CANCEL:
1171:                    //log(Level.SEVERE, "DeployPortletBean(), CANCEL");
1172:                    reset();
1173:                    if (t != null) {
1174:                        t.interrupt();
1175:                    }
1176:                    setDisplayError(new Boolean(false));
1177:                    break;
1178:                default:
1179:                    break;
1180:                }
1181:                return true;
1182:            }
1183:
1184:            public boolean isTransient() {
1185:                return false;
1186:            }
1187:
1188:            public void setTransient(boolean flag) {
1189:            }
1190:
1191:            public Object saveState(FacesContext context) {
1192:                return null;
1193:            }
1194:
1195:            public void restoreState(FacesContext context, Object state) {
1196:            }
1197:
1198:            private boolean hasWebLogicAdminServerInstance(String portalId) {
1199:                boolean hasWebLogicAdminServerInstance = false;
1200:                List instances = new ArrayList();
1201:                try {
1202:                    Set objNames = getInstanceObjectNames(portalId);
1203:                    Iterator iter = objNames.iterator();
1204:                    while (iter.hasNext()) {
1205:                        instances.add(getAttribute((ObjectName) iter.next(),
1206:                                "ID"));
1207:                    }
1208:                } catch (IOException ie) {
1209:                    log(
1210:                            Level.SEVERE,
1211:                            "DeployPortletBean.hasWebLogicAdminServerInstance(): Exception while trying to get the list of portal instances for portalId = "
1212:                                    + portalId, ie);
1213:                } catch (Exception ex) {
1214:                    log(
1215:                            Level.SEVERE,
1216:                            "DeployPortletBean.hasWebLogicAdminServerInstance(): Exception while trying to get the list of portal instances for portalId = "
1217:                                    + portalId, ex);
1218:                }
1219:                if (!instances.isEmpty()) {
1220:                    String instName = (String) instances.get(0);
1221:                    Set attrKeys = new HashSet();
1222:                    Map valuesMap = null;
1223:                    attrKeys.add(InstanceAttributes.WEB_CONTAINER_TYPE);
1224:                    Object[] params = {
1225:                            AdminClientUtil.PORTAL_SERVER_INSTANCE_MBEAN_TYPE,
1226:                            attrKeys };
1227:                    String[] signature = { "java.lang.String", "java.util.Set" };
1228:
1229:                    try {
1230:                        ObjectName objName = AdminClientUtil
1231:                                .getInstanceMBeanObjectName(
1232:                                        AdminClientUtil.DEFAULT_DOMAIN,
1233:                                        portalId, instName);
1234:
1235:                        log(Level.FINEST, "Invoking MBean method for: "
1236:                                + instName);
1237:                        valuesMap = (Map) getMBeanServerConnection().invoke(
1238:                                objName, "getMultipleAttributeValues", params,
1239:                                signature);
1240:                    } catch (Exception e) {
1241:                        log(
1242:                                Level.SEVERE,
1243:                                "DeployPortletBean.hasWebLogicAdminServerInstance(): Unable to fetch Instance Information",
1244:                                e);
1245:                    }
1246:                    if (valuesMap != null) {
1247:                        String wcType = getValueFromMap(
1248:                                InstanceAttributes.WEB_CONTAINER_TYPE,
1249:                                valuesMap);
1250:                        if (wcType != null && wcType.length() != 0
1251:                                && (wcType.indexOf("BEA") != -1)) {
1252:                            hasWebLogicAdminServerInstance = true;
1253:                        }
1254:                    }
1255:
1256:                }
1257:                return hasWebLogicAdminServerInstance;
1258:            }
1259:
1260:            private String getValueFromMap(String key, Map valuesMap) {
1261:                String value = "";
1262:                Set valueSet = (Set) valuesMap.get(key);
1263:                if (valueSet != null) {
1264:                    value = valueSet.toString();
1265:                    log(Level.FINEST, "webcontainer type: " + value);
1266:                }
1267:                return value;
1268:            }
1269:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.