001: package com.sun.portal.fabric.config;
002:
003: import com.sun.portal.fabric.tasks.WebContainer;
004: import com.sun.portal.fabric.tasks.WebContainerFactory;
005: import com.sun.portal.fabric.tasks.ConfigurationException;
006:
007: import com.sun.portal.fabric.mbeans.Portal;
008: import com.sun.portal.fabric.util.ClasspathGenUtil;
009:
010: import com.sun.portal.admin.common.context.PSConfigContext;
011: import com.sun.portal.admin.common.context.PSConfigContextImpl;
012: import com.sun.portal.admin.common.InstanceAttributes;
013: import com.sun.portal.log.common.PortalLogger;
014:
015: import java.util.Map;
016: import java.util.HashMap;
017: import java.util.Properties;
018: import java.util.logging.Logger;
019: import java.util.logging.Level;
020: import java.io.FileInputStream;
021:
022: /**
023: * This is a Web Conatiner Implementaion test class. It can only be used
024: * for unit testing the various web conatiner tasks mentioned in WebContainer.java.
025: * Need to pass the WebContainer property file.
026: */
027: public class WebContainerImplTest {
028:
029: // Customise these values according to your configuration.
030: private static Logger logger = PortalLogger
031: .getLogger(WebContainerImplTest.class);
032: private static final String portalID = "myPortal";
033: private static final String domainID = "defaultDomain";
034:
035: public static void main(String[] args) {
036: process(args[0]);
037: }
038:
039: public static void process(String wcPropName) {
040: Properties wcProp = new Properties();
041: try {
042: wcProp.load(new FileInputStream(wcPropName));
043: } catch (Exception e) {
044: logger.log(Level.SEVERE, "PSFB_CSPFC0257", e);
045: }
046:
047: Map attributes = new HashMap(wcProp);
048: String host = (String) attributes.get(InstanceAttributes.HOST);
049: String port = (String) attributes.get(InstanceAttributes.PORT);
050:
051: // Prepare the instance name from the hostname and the port
052: String instanceID = null;
053: int idx = host.indexOf('.');
054: if (idx > 0) {
055: instanceID = host.substring(0, idx) + "_" + port;
056: } else {
057: instanceID = host + "_" + port;
058: }
059:
060: instanceID = instanceID.replace('-', '_');
061:
062: String sysClasspath = System.getProperty("java.class.path");
063:
064: System.setProperty("com.sun.portal.portal.id", portalID);
065: System.setProperty("com.sun.portal.instance.id", instanceID);
066: System.setProperty("java.class.path", sysClasspath + ":"
067: + "/etc/opt/SUNWportal" + ":" + "/opt/SUNWportal/lib");
068:
069: logger.log(Level.INFO, "PSFB_CSPFC0258", instanceID);
070: logger.log(Level.INFO, "PSFB_CSPFC0259", attributes);
071:
072: try {
073:
074: PSConfigContext cc = new PSConfigContextImpl(domainID);
075:
076: attributes.put(InstanceAttributes.NAME, instanceID);
077: attributes.put(InstanceAttributes.DESCRIPTION, instanceID);
078:
079: // Set the DomainID, portalID, instanceID into the attributes that passed
080: //to the webcontainer implementations
081: attributes.put(WebContainer.DOMAIN_ID, domainID);
082: attributes.put(WebContainer.PORTAL_ID, portalID);
083:
084: // Create instance of webcontainer
085: WebContainer wc = WebContainerFactory.getWebContainer(
086: attributes, true);
087:
088: // Invoke configure method to setup the classpath for Portal
089: // and Access Manager SDK
090: wc.configure(cc);
091:
092: // Switch to unconfigure
093: // wc.unconfigure(cc);
094:
095: } catch (ConfigurationException ce) {
096: logger.log(Level.SEVERE, "PSFB_CSPFC0260", ce);
097: } catch (Exception e) {
098: logger.log(Level.SEVERE, "PSFB_CSPFC0253", e);
099: }
100: }
101:
102: }
|