001: // @(#)NetletProxy.java 1.14 "@(#)NetletProxy.java 1.14 00/12/21 Sun Microsystems"
002:
003: package com.sun.portal.netlet.proxy;
004:
005: // JDK classes
006:
007: import java.io.BufferedInputStream;
008: import java.io.BufferedReader;
009: import java.io.DataOutputStream;
010: import java.io.FileOutputStream;
011: import java.io.IOException;
012: import java.io.InputStreamReader;
013: import java.net.Socket;
014: import java.net.SocketException;
015: import java.util.ResourceBundle;
016: import java.util.StringTokenizer;
017: import java.util.logging.Level;
018: import java.util.logging.Logger;
019:
020: import javax.servlet.http.HttpServletRequest;
021: import javax.servlet.http.HttpServletResponse;
022:
023: import com.iplanet.services.comm.client.PLLNotificationServlet;
024: import com.sun.portal.log.common.PortalLogger;
025: import com.sun.portal.netlet.eproxy.GW;
026: import com.sun.portal.netlet.eproxy.RProxyConnection;
027: import com.sun.portal.rproxy.configservlet.client.GatewayProfile;
028: import com.sun.portal.rproxy.configservlet.client.PlatformProfile;
029: import com.sun.portal.rproxy.connectionhandler.GatewayServletResponse;
030: import com.sun.portal.rproxy.connectionhandler.HTTPRequest;
031: import com.sun.portal.rproxy.connectionhandler.HTTPSession;
032: import com.sun.portal.rproxy.connectionhandler.Request;
033: import com.sun.portal.rproxy.connectionhandler.Response;
034: import com.sun.portal.rproxy.connectionhandler.Session;
035: import com.sun.portal.rproxy.monitoring.MonitoringSubsystem;
036: import com.sun.portal.rproxy.server.GatewayContextFactory;
037: import com.sun.portal.rproxy.server.RequestProcessor;
038: import com.sun.portal.util.GWDebug;
039: import com.sun.portal.util.GWLocale;
040: import com.sun.portal.util.GWNSSInit;
041: import com.sun.portal.util.GWThreadPool;
042: import com.sun.portal.util.NetletLogMgr;
043: import com.sun.portal.util.ServiceIdentifier;
044: import com.sun.portal.util.SystemProperties;
045:
046: public class NetletProxy {
047:
048: public static ResourceBundle eResources;
049:
050: /*
051: * private static String _server_host; private static String _server_port;
052: * private static String _server_protocol;
053: *
054: * public static final int DEFAULT_MAXECONN = 1000;
055: */
056: public static final String DEFAULT_PORT = "10555";
057:
058: private static Logger logger = null;
059:
060: static {
061: System.setProperty("com.sun.portal.sra.component.type",
062: "nlproxy");
063: if (logger == null) {
064: // The following will replace the %sraComponentType key in the log
065: // file with the key
066: // NetletProxy and generate the log file name . See the
067: // platform.conf file for the entire
068: // key
069:
070: logger = PortalLogger.getLogger(NetletProxy.class);
071: }
072:
073: try {
074: GWNSSInit.initialize();
075: } catch (SocketException e1) {
076: if (GWDebug.debug.errorEnabled())
077: GWDebug.debug
078: .error("NetletProxy: Unable to initialize NSS -> "
079: + e1);
080: }
081:
082: /*
083: * _server_host = SystemProperties.get("portal.server.host");
084: * _server_port = SystemProperties.get("portal.server.port");
085: * _server_protocol = SystemProperties.get("portal.server.protocol");
086: */
087: try {
088: String profileName = System.getProperty(
089: "gateway.profilename", "default");
090: GatewayProfile.init("this-should-be-sid", profileName);
091: PlatformProfile.init("this-should-be-sid");
092: } catch (Exception e) {
093: // logger.severe("NetletProxy: Unable to initialize
094: // GatewayProfile/PlatformProfile -> " + e);
095: logger.log(Level.SEVERE, "PSSRNTLT_CSPNPROXY000", e);
096: System.exit(1);
097: }
098: GWDebug.createDefault("srapNetletProxy");
099:
100: ServiceIdentifier.createDefault("srapNetletProxy");
101:
102: if (NetletLogMgr.loggingEnabled) {
103: StringBuffer logsb = new StringBuffer();
104: logsb.append("srapNetlet_").append(
105: SystemProperties.get("gateway.host").replace('-',
106: '_')).append('_').append(
107: System
108: .getProperty("gateway.profilename",
109: "default").replace('-', '_'));
110: NetletLogMgr.createDefault(logsb.toString());
111: // logger.info("NetletProxy: Log file -> " + logsb.toString());
112: Object[] params1 = { logsb.toString() };
113: logger.log(Level.INFO, "PSSRNTLT_CSPNPROXY001", params1);
114: }
115:
116: GWLocale.createDefault();
117: GWThreadPool.init();
118:
119: GatewayContextFactory
120: .init(GatewayContextFactory.DSAME_INSTANCE);
121: }
122:
123: public static void main(String argv[]) {
124:
125: // Switch uid to desired user.
126: // NetletProxyUID SetUID = new NetletProxyUID();
127: // SetUID.SwitchToUser();
128: GW.setNumberOfInstances(1);
129:
130: /*
131: * Added for RFE#4646305
132: */
133: int portnum = 10555;
134: try {
135: portnum = Integer.valueOf(
136: SystemProperties.get("netletproxy.port",
137: DEFAULT_PORT)).intValue();
138: String portInfoFile = argv[0];
139: FileOutputStream fos = new FileOutputStream(portInfoFile,
140: true);
141: String str = "port=" + portnum + "\n";
142: byte b[] = str.getBytes();
143: fos.write(b);
144: fos.flush();
145: fos.close();
146: } catch (Exception e) {
147: // logger.severe("Cannot write netlet proxy port to the output
148: // file");
149: logger.severe("PSSRNTLT_CSPNPROXY002");
150: }
151: // logger.info("Starting proxy at port -> " + portnum);
152: Object[] params3 = { portnum + "" };
153: logger.log(Level.INFO, "PSSRNTLT_CSPNPROXY003", params3);
154: RProxyConnection.startHttps(portnum);
155: MonitoringSubsystem.getInstance();
156: /*
157: * EProxyConnection sc = new EProxyConnection(portnum); sc.start();
158: */
159: }
160:
161: public static void exit(int status) {
162: System.exit(status);
163: }
164:
165: public static void processAmNotification(final Socket sock) {
166: // Process Notification in a separate thread.
167: Runnable r = new Runnable() {
168: public void run() {
169: try {
170: logger.info("PSSRNTLT_CSPNPROXY004");
171: sock.setSoTimeout(5000);
172:
173: BufferedReader reader = new BufferedReader(
174: new InputStreamReader(sock.getInputStream()));
175:
176: String line = "";
177: HTTPRequest req = new HTTPRequest();
178: HTTPSession session = new HTTPSession(sock);
179:
180: while ((line = reader.readLine()).length() > 0)
181: req.addHeaderLine(line);
182:
183: if (req != null) {
184: if (req.getGatewayScheme().equals(
185: Session.notificationURL)) {
186: logger.info("PSSRNTLT_CSPNPROXY005");
187: session.processNotificationRequest(req);
188: } else
189: sock.close();
190: }
191:
192: } catch (Exception e) {
193: // TODO Auto-generated catch block
194: logger
195: .severe("Error processing Notification Request from Access Manager");
196: }
197: }
198: };
199: new Thread(r).start();
200: }
201:
202: }
|