001: /*
002: * NetletRequestDispatcher.java
003: *
004: * Created on May 26, 2003, 5:33 PM
005: */
006:
007: package com.sun.portal.netlet.eproxy;
008:
009: /**
010: * Tunnels Netlet traffic from GW to NLP via a thirdparty proxy. Uses Proxies
011: * for domains and subdomain of GW profile to get the proxy information, also
012: * support proxy authentication
013: *
014: * TBD: 1. Need to send Dummy Netlet Messages on keep alive interval as the
015: * proxy may timeout netlet connections
016: *
017: * @author Rajesh T
018: */
019:
020: import java.net.Socket;
021:
022: import com.sun.portal.rproxy.configservlet.client.GatewayProfile;
023:
024: public class NetletRequestRouter {
025:
026: public static final boolean useProxyTunnel = GatewayProfile
027: .getBoolean("NetletProxyTunnel", false);
028:
029: public static final String NETLET_PROTOCOL_FOR_PROXY_TUNNEL = "https";
030:
031: private static final int HTTP_PROXY_PORT = 8080;
032:
033: private int clientPort = -1;
034:
035: /** Creates a new instance of NetletRequestDispatcher */
036: public NetletRequestRouter(int clientPort) {
037: this .clientPort = clientPort;
038: }
039:
040: /*
041: *
042: */
043:
044: public Socket getConnection(String host, int port) {
045: if (!useProxyTunnel) {
046: return directConnection(host, port);
047: } else {
048: return tunnelConnection(host, port);
049: }
050: }
051:
052: /*
053: *
054: */
055:
056: private Socket directConnection(String host, int port) {
057: return directSSLConnection(host, port);
058: }
059:
060: /*
061: *
062: */
063:
064: private Socket tunnelConnection(String host, int port) {
065: return tunnelSSLConnection(host, port);
066: }
067:
068: /*
069: *
070: */
071:
072: private Socket directSSLConnection(String host, int port) {
073: return SConn.sslconnect(port, host);
074: }
075:
076: /*
077: *
078: */
079: private Socket tunnelSSLConnection(String host, int port) {
080: String proxy = ProxyInfo.getWebProxy(
081: NETLET_PROTOCOL_FOR_PROXY_TUNNEL, host);
082: String proxyHost = null;
083: int proxyPort = -1;
084:
085: if (proxy == null) {
086: return directSSLConnection(host, port);
087: } else {
088: if (proxy.indexOf(":") != -1) {
089: proxyHost = proxy.substring(0, proxy.indexOf(':'));
090: proxyPort = Integer.parseInt(proxy.substring(proxy
091: .indexOf(':') + 1));
092: } else {
093: proxyHost = proxy;
094: proxyPort = HTTP_PROXY_PORT;
095: }
096: return SConn.sslProxyConnect(host, port, proxyHost,
097: proxyPort, clientPort);
098: }
099:
100: }
101:
102: }
|