001: package org.objectweb.celtix.bus.transports.https;
002:
003: import java.io.IOException;
004: import java.net.InetAddress;
005: import java.net.Socket;
006: import java.net.UnknownHostException;
007: import java.util.logging.Handler;
008: import java.util.logging.Level;
009: import java.util.logging.Logger;
010:
011: import javax.net.ssl.SSLSocket;
012: import javax.net.ssl.SSLSocketFactory;
013:
014: import org.objectweb.celtix.common.logging.LogUtils;
015:
016: class SSLSocketFactoryWrapper extends SSLSocketFactory {
017:
018: private static final Logger LOG = LogUtils
019: .getL7dLogger(SSLSocketFactoryWrapper.class);
020:
021: private SSLSocketFactory sslSocketFactory;
022: private String[] ciphers;
023:
024: public SSLSocketFactoryWrapper(
025: SSLSocketFactory sslSocketFactoryParam,
026: String[] ciphersParam) {
027: sslSocketFactory = sslSocketFactoryParam;
028: ciphers = ciphersParam;
029: }
030:
031: public String[] getDefaultCipherSuites() {
032: return sslSocketFactory.getDefaultCipherSuites();
033: }
034:
035: public String[] getSupportedCipherSuites() {
036: return sslSocketFactory.getSupportedCipherSuites();
037: }
038:
039: public Socket createSocket(Socket s, String host, int port,
040: boolean autoClose) throws IOException, UnknownHostException {
041:
042: SSLSocket socket = null;
043: socket = (SSLSocket) sslSocketFactory.createSocket(s, host,
044: port, autoClose);
045: if ((socket != null) && (ciphers != null)) {
046: socket.setEnabledCipherSuites(ciphers);
047: }
048:
049: return socket;
050: }
051:
052: public Socket createSocket(String host, int port)
053: throws IOException, UnknownHostException {
054: SSLSocket socket = null;
055: socket = (SSLSocket) sslSocketFactory.createSocket(host, port);
056: if ((socket != null) && (ciphers != null)) {
057: socket.setEnabledCipherSuites(ciphers);
058: }
059: if (socket == null) {
060: LogUtils.log(LOG, Level.SEVERE,
061: "PROBLEM_CREATING_OUTBOUND_REQUEST_SOCKET",
062: new Object[] { host, port });
063: }
064: return socket;
065: }
066:
067: public Socket createSocket(String host, int port,
068: InetAddress localHost, int localPort) throws IOException,
069: UnknownHostException {
070: SSLSocket socket = null;
071: socket = (SSLSocket) sslSocketFactory.createSocket(host, port,
072: localHost, localPort);
073: if ((socket != null) && (ciphers != null)) {
074: socket.setEnabledCipherSuites(ciphers);
075: }
076:
077: if (socket == null) {
078: LogUtils.log(LOG, Level.SEVERE,
079: "PROBLEM_CREATING_OUTBOUND_REQUEST_SOCKET",
080: new Object[] { host, port });
081: }
082: return socket;
083: }
084:
085: public Socket createSocket(InetAddress host, int port)
086: throws IOException {
087: SSLSocket socket = null;
088: socket = (SSLSocket) sslSocketFactory.createSocket(host, port);
089: if ((socket != null) && (ciphers != null)) {
090: socket.setEnabledCipherSuites(ciphers);
091: }
092:
093: if (socket == null) {
094: LogUtils.log(LOG, Level.SEVERE,
095: "PROBLEM_CREATING_OUTBOUND_REQUEST_SOCKET",
096: new Object[] { host, port });
097: }
098: return socket;
099: }
100:
101: public Socket createSocket(InetAddress address, int port,
102: InetAddress localAddress, int localPort) throws IOException {
103: SSLSocket socket = null;
104: socket = (SSLSocket) sslSocketFactory.createSocket(address,
105: port, localAddress, localPort);
106: if ((socket != null) && (ciphers != null)) {
107: socket.setEnabledCipherSuites(ciphers);
108: }
109:
110: if (socket == null) {
111: LogUtils.log(LOG, Level.SEVERE,
112: "PROBLEM_CREATING_OUTBOUND_REQUEST_SOCKET",
113: new Object[] { address, port });
114: }
115: return socket;
116: }
117:
118: /*
119: * For testing only
120: */
121: protected void addLogHandler(Handler handler) {
122: LOG.addHandler(handler);
123: }
124: }
|