All pastes #1806548 Raw Edit

WireLogSSLSocketFactory

public java v1 · immutable
#1806548 ·published 2010-02-23 09:02 UTC
rendered paste body
public class WireLogSSLSocketFactory extends SSLSocketFactory {	private SSLSocketFactory delegate;	public WireLogSSLSocketFactory(SSLSocketFactory sf0) {		this.delegate = sf0;	}	public Socket createSocket(Socket s, String host, int port,			boolean autoClose) throws IOException {		return new WireLogSocket((SSLSocket) delegate.createSocket(s, host, port, autoClose));	}	/*	...	*/	private static class WireLogSocket extends SSLSocket {		private SSLSocket delegate;		public WireLogSocket(SSLSocket s) {			this.delegate = s;		}		public OutputStream getOutputStream() throws IOException {			return new LoggingOutputStream(delegate.getOutputStream());		}		/*		...		*/		private static class LoggingOutputStream extends FilterOutputStream {			private static final Logger logger = Logger.getLogger(WireLogSocket.LoggingOutputStream.class);			private static final String CHARSET = "ISO-8859-1";			private StringBuffer sb = new StringBuffer();			public LoggingOutputStream(OutputStream out) {				super(out);			}			@Override			public void write(byte[] b, int off, int len)					throws IOException {				sb.append(new String(b, off, len, CHARSET));				logger.info("\n" + sb.toString());				out.write(b, off, len);			}						@Override			public void write(int b) throws IOException {				sb.append(b);				logger.info("\n" + sb.toString());				out.write(b);			}						@Override			public void close() throws IOException {				logger.info("\n" + sb.toString());				super.close();			}		}	}}