001: package com.sun.portal.netlet.eproxy;
002:
003: import java.io.File;
004: import java.io.FileWriter;
005: import java.io.IOException;
006: import java.net.ServerSocket;
007: import java.net.SocketException;
008: import java.util.logging.Level;
009: import java.util.logging.Logger;
010: import java.util.List;
011: import java.util.Iterator;
012:
013: import com.sun.portal.log.common.PortalLogger;
014: import com.sun.portal.rproxy.configservlet.client.GatewayProfile;
015: import com.sun.portal.rproxy.configservlet.client.PlatformProfile;
016: import com.sun.portal.rproxy.monitoring.MonitoringSubsystem;
017: import com.sun.portal.rproxy.rewriter.SRAPRewriterModule;
018: import com.sun.portal.rproxy.server.GatewayContext;
019: import com.sun.portal.rproxy.server.GatewayContextFactory;
020: import com.sun.portal.util.GWDebug;
021: import com.sun.portal.util.GWLocale;
022: import com.sun.portal.util.GWLogManager;
023: import com.sun.portal.util.GWNSSInit;
024: import com.sun.portal.util.GWThreadPool;
025: import com.sun.portal.util.NetletLogMgr;
026: import com.sun.portal.util.ServiceIdentifier;
027: import com.sun.portal.util.SystemProperties;
028:
029: public class EProxy {
030:
031: public static boolean isNetletEnabled = true;
032:
033: public static boolean isProxyletEnabled = false;
034:
035: public static Logger logger = null;
036:
037: private static void init() throws SocketException {
038: System.setProperty("com.sun.portal.sra.component.type",
039: "gateway");
040: if (logger == null) {
041: // The following will replace the %sraComponentType key in the log file with the key
042: // Gateway and generate the log file name . See the platform.conf file for the entire
043: // key
044: logger = PortalLogger.getLogger(EProxy.class);
045: }
046: GWDebug.createDefault("srapGateway");
047: if (!GWNSSInit.initialize()) {
048: System.exit(1);
049: }
050: ServiceIdentifier.createDefault("srapGateway");
051: try {
052: String profileName = System.getProperty(
053: "gateway.profilename", "default");
054: GatewayProfile.init("this-should-be-sid", profileName);
055: PlatformProfile.init("this-should-be-sid");
056: SRAPRewriterModule.initIDSAME();
057: } catch (Exception e) {
058:
059: // logger.log(Level.SEVERE, "Unable to initialize
060: // GatewayProfile/PlatformProfile", e);
061: logger.log(Level.SEVERE, "PSSRNTLT_CSPNEPROX010");
062: System.exit(1);
063: }
064: // GatewayContextFactory.init(GatewayContextFactory.FILE_INSTANCE);
065: GatewayContextFactory
066: .init(GatewayContextFactory.DSAME_INSTANCE);
067:
068: GWLogManager.initialise();
069: if (GWLogManager.loggingEnabled) {
070: // Guess this is ok since this is in static block
071: // Log file name should not contain '-' as per iDSAME Log api
072: StringBuffer logsb = new StringBuffer();
073: logsb.append("srapGateway_").append(
074: SystemProperties.get("gateway.host").replace('-',
075: '_')).append('_').append(
076: System
077: .getProperty("gateway.profilename",
078: "default").replace('-', '_'));
079: GWLogManager.createDefault(logsb.toString());
080: }
081:
082: if (NetletLogMgr.loggingEnabled) {
083: StringBuffer logsb = new StringBuffer();
084: logsb.append("srapNetlet_").append(
085: SystemProperties.get("gateway.host").replace('-',
086: '_')).append('_').append(
087: System
088: .getProperty("gateway.profilename",
089: "default").replace('-', '_'));
090: NetletLogMgr.createDefault(logsb.toString());
091: }
092:
093: GWLocale.createDefault();
094:
095: GWThreadPool.init();
096: }
097:
098: // Lihue PRD : 4.5
099: static final String watchdogInfoFileBase = "/var/opt/SUNWportal/.gw.";
100:
101: // EOC :: Lihue PRD : 4.5
102:
103: public static void main(String argv[]) {
104:
105: try {
106: init();
107: if (GWLogManager.loggingEnabled) {
108: GWLogManager.write("EProxy", GWLocale
109: .getPFString("StartEProxy"));
110: }
111: } catch (SocketException e) {
112: e.printStackTrace();
113: }
114:
115: if (GWLogManager.loggingEnabled) {
116: GWLogManager.write("EProxy", GWLocale
117: .getPFString("StartEProxy"));
118: }
119:
120: GatewayContext gatewayContext = GatewayContextFactory
121: .getGatewayContext();
122: boolean httpEnabled = gatewayContext.isHttpEnabled();
123: boolean httpsEnabled = gatewayContext.isHttpsEnabled();
124:
125: if (!(httpEnabled || httpsEnabled)) {
126: // Neither of them is enabled...
127: return;
128: }
129:
130: int httpPort = gatewayContext.getHttpPort();
131: int httpsPort = gatewayContext.getHttpsPort();
132:
133: writePortInfoForWatchdog(httpEnabled, httpPort, httpsEnabled,
134: httpsPort);
135:
136: isNetletEnabled = gatewayContext.isEProxyEnabled();
137:
138: isProxyletEnabled = gatewayContext.isPProxyEnabled();
139:
140: //
141: // Start gateway in two modes ( non-ssl as well as SSL mode ) if
142: // proxylet is enabled.
143: //
144: if (isProxyletEnabled) {
145: // logger.info("Proxylet Enabled");
146: logger.info("PSSRNTLT_CSPNEPROX011");
147: //
148: // Find out an unused port on the local machine.
149: //
150: int internalPort = 0;
151: try {
152: ServerSocket s = new ServerSocket(0);
153: internalPort = s.getLocalPort();
154: s.close();
155: s = null;
156:
157: } catch (Exception ignore) {
158: }
159:
160: // logger.info("Free port on localhost " + internalPort);
161: Object[] params2 = { "" + internalPort };
162: logger.log(Level.INFO, "PSSRNTLT_CSPNEPROX012", params2);
163:
164: // Start SSL server on any free port . This port information is
165: // local to the server
166: // and is not published
167: startRProxy(httpEnabled, httpPort, httpsEnabled,
168: internalPort);
169:
170: // Start non-ssl server on the acutal SSL port. Request that arrive
171: // on this port will
172: // be forwarded to the SSL server running on the internal port
173: startPProxy(httpsEnabled, httpsPort, internalPort);
174: } else
175: startRProxy(httpEnabled, httpPort, httpsEnabled, httpsPort);
176:
177: MonitoringSubsystem.getInstance();
178: }
179:
180: private static void startPProxy_HTTP(boolean httpEnabled,
181: int httpPort, int internalPort) {
182:
183: if (httpEnabled) {
184: PProxyConnection.startHttps(httpPort, internalPort);
185: // logger.info("PProxy HTTP is being initialised at port:" +
186: // httpPort); }
187: Object[] params3 = { httpPort + "" };
188: logger.log(Level.INFO, "PSSRNTLT_CSPNEPROX013", params3);
189:
190: }
191: }
192:
193: private static void startPProxy(boolean httpsEnabled,
194: int httpsPort, int internalPort) {
195:
196: if (httpsEnabled) {
197: PProxyConnection.startHttps(httpsPort, internalPort);
198: // logger.info("PProxy Https is being initialised at port:" +
199: // httpsPort);
200: Object[] params4 = { "" + httpsPort };
201: logger.log(Level.INFO, "PSSRNTLT_CSPNEPROX014", params4);
202: }
203:
204: }
205:
206: private static void startRProxy(boolean httpEnabled, int httpPort,
207: boolean httpsEnabled, int httpsPort) {
208:
209: int numberOfGatewayInstances = (httpEnabled && httpsEnabled) ? 2
210: : 1;
211: GW.setNumberOfInstances(numberOfGatewayInstances);
212:
213: if (httpEnabled) {
214: RProxyConnection.startHttp(httpPort);
215: // logger.info("Http is being initialised at port:" + httpPort);
216: Object[] params5 = { httpPort + "" };
217: logger.log(Level.INFO, "PSSRNTLT_CSPNEPROX015", params5);
218: }
219:
220: if (httpsEnabled) {
221: RProxyConnection.startHttps(httpsPort);
222: // logger.info("Https is being initialised at port:" + httpsPort);
223: Object[] params6 = { httpsPort + "" };
224: logger.log(Level.INFO, "PSSRNTLT_CSPNEPROX016", params6);
225: }
226:
227: }
228:
229: private static void writePortInfoForWatchdog(boolean httpEnabled,
230: int httpPort, boolean httpsEnabled, int httpsPort) {
231: File watchdogInfoFile = new File(watchdogInfoFileBase
232: + System.getProperty("conf.suffix"));
233: if (watchdogInfoFile.exists()) {
234: watchdogInfoFile.delete();
235: }
236:
237: // Write port Information for watchdog process.
238: try {
239: FileWriter fw = new FileWriter(watchdogInfoFile);
240:
241: if (httpEnabled) {
242: fw.write(httpPort + "\n");
243: }
244:
245: if (httpsEnabled) {
246: fw.write(httpsPort + "\n");
247: }
248:
249: fw.flush();
250: fw.close();
251: } catch (IOException ex) {
252: // logger.severe("Unable to enter information for watchdog
253: // information");
254: logger.severe("PSSRNTLT_CSPNEPROX017");
255: }
256: }
257:
258: }
|