001: /*
002: * SRAPSocket.java
003: *
004: * Created on November 12, 2002, 5:12 PM
005: */
006:
007: package com.sun.portal.util;
008:
009: import java.io.BufferedInputStream;
010: import java.io.BufferedOutputStream;
011: import java.io.IOException;
012: import java.io.InputStream;
013: import java.io.OutputStream;
014: import java.net.InetAddress;
015: import java.net.Socket;
016: import java.net.SocketAddress;
017: import java.net.SocketException;
018: import java.net.SocketImplFactory;
019: import java.util.logging.Logger;
020:
021: import com.sun.portal.log.common.PortalLogger;
022: import com.sun.portal.rproxy.monitoring.MonitoringSubsystem;
023:
024: /**
025: *
026: * @author Mridul
027: */
028: public class SRAPSocket extends Socket {
029:
030: private Socket sock = null;
031:
032: private BufferedInputStream in = null;
033:
034: private BufferedOutputStream out = null;
035:
036: private boolean isHTTPS;
037:
038: // static Logger logger = Logger.getLogger("com.sun.portal.sra.rproxy");
039: private static Logger logger = PortalLogger
040: .getLogger(SRAPSocket.class);
041:
042: public SRAPSocket(Socket sock) throws IOException {
043: this .sock = sock;
044: isHTTPS = (sock instanceof org.mozilla.jss.ssl.SSLSocket);
045:
046: if (isHTTPS) {
047: MonitoringSubsystem
048: .handleEvent(SRAEvent.SSL_SOCKET_CREATED);
049: } else {
050: MonitoringSubsystem
051: .handleEvent(SRAEvent.PLAIN_SOCKET_CREATED);
052: }
053: }
054:
055: public InputStream getInputStream() throws IOException {
056: if (in == null) {
057: in = new BufferedInputStream(sock.getInputStream());
058: }
059: return in;
060: }
061:
062: public void close() throws IOException {
063: if (_open) {// sock.isClosed() does not give the actual state. probably a bug with JSS. So this new flag is added
064: if (isHTTPS) {
065: MonitoringSubsystem
066: .handleEvent(SRAEvent.SSL_SOCKET_DESTROYED);
067: } else {
068: MonitoringSubsystem
069: .handleEvent(SRAEvent.PLAIN_SOCKET_DESTROYED);
070: }
071: }
072: /*
073: * // This should not cause gateway to throw up - but is the proper way
074: * to // exit - but JSS/NSS throws up with a JVM crash if we do this !! //
075: * That product sure is buggy !! if (out != null){ try{ out.flush();
076: * }catch(IOException ex){} }
077: */
078: sock.close();
079: }
080:
081: public InetAddress getInetAddress() {
082: return sock.getInetAddress();
083: }
084:
085: public boolean getKeepAlive() throws SocketException {
086: return sock.getKeepAlive();
087: }
088:
089: public InetAddress getLocalAddress() {
090: return sock.getLocalAddress();
091: }
092:
093: public int getLocalPort() {
094: return sock.getLocalPort();
095: }
096:
097: public OutputStream getOutputStream() throws IOException {
098: if (out == null) {
099: out = new BufferedOutputStream(sock.getOutputStream());
100: }
101: return out;
102: }
103:
104: public int getPort() {
105: return sock.getPort();
106: }
107:
108: public int getReceiveBufferSize() throws SocketException {
109: return sock.getReceiveBufferSize();
110: }
111:
112: public int getSendBufferSize() throws SocketException {
113: return sock.getSendBufferSize();
114: }
115:
116: public int getSoLinger() throws SocketException {
117: return sock.getSoLinger();
118: }
119:
120: public int getSoTimeout() throws SocketException {
121: return sock.getSoTimeout();
122: }
123:
124: public boolean getTcpNoDelay() throws SocketException {
125: return sock.getTcpNoDelay();
126: }
127:
128: public void setKeepAlive(boolean on) throws SocketException {
129: sock.setKeepAlive(on);
130: }
131:
132: public void setReceiveBufferSize(int size) throws SocketException {
133: sock.setReceiveBufferSize(size);
134: }
135:
136: public void setSendBufferSize(int size) throws SocketException {
137: sock.setSendBufferSize(size);
138: }
139:
140: public static void setSocketImplFactory(SocketImplFactory fac)
141: throws UnsupportedOperationException {
142: // logger.info("setSocketImplFactory(SocketImplFactory fac) called in
143: // SRAPSocket");
144: logger.info("PSSR_CSPU091");
145: throw new UnsupportedOperationException("Not supported");
146: }
147:
148: public void setSoLinger(boolean on, int linger)
149: throws SocketException {
150: sock.setSoLinger(on, linger);
151: }
152:
153: public void setSoTimeout(int timeout) throws SocketException {
154:
155: sock.setSoTimeout(timeout);
156: }
157:
158: public void setTcpNoDelay(boolean on) throws SocketException {
159: sock.setTcpNoDelay(on);
160: }
161:
162: public void shutdownInput() throws IOException {
163: // Is this required ??
164: // Mridul
165: in.skip(in.available());
166: sock.shutdownInput();
167: }
168:
169: public void shutdownOutput() throws IOException {
170: out.flush();
171: sock.shutdownOutput();
172: }
173:
174: public String toString() {
175: try {
176: return sock.toString();
177: } catch (Exception ex) {
178: return null;
179: }
180: }
181:
182: public boolean isSSLSocket() {
183: return isHTTPS;
184: }
185:
186: public Socket getActualSocket() {
187: return sock;
188: }
189:
190: private boolean _open = true;
191:
192: public SocketAddress getRemoteSocketAddress() {
193: return sock.getRemoteSocketAddress();
194: }
195: }
|