Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
  * JBoss, Home of Professional Open Source
  * Copyright 2005, JBoss Inc., and individual contributors as indicated
  * by the @authors tag. See the copyright.txt in the distribution for a
  * full listing of individual contributors.
  *
  * This is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as
  * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
 package org.jboss.remoting.transport.http.ssl;
 
 
This is a wrapper for the real SSLSocketFactory passed to it so can have it create the real SSLSocket and then add HandshakeCompletedListener to it. This is needed because no direct API to the HttpsURLConnection class to do this, so am having to do it this way.

Author(s):
Tom Elrod
 
 public class HTTPSSocketFactory extends SSLSocketFactory
 {
    private SSLSocketFactory targetFactory = null;
    private HandshakeCompletedListener targetListener = null;
 
    public HTTPSSocketFactory(SSLSocketFactory socketFactoryHandshakeCompletedListener listener)
    {
       this. = socketFactory;
       this. = listener;
       if ( == null)
       {
          throw new RuntimeException("Can not create HTTPSSocketFactory with target SSLSocketFactory being null.");
       }
       if ( == null)
       {
          throw new RuntimeException("Can not create HTTPSSocketFactory with target HandshakeCompletedListener being null.");
       }
    }
 
    public String[] getDefaultCipherSuites()
    {
       return .getDefaultCipherSuites();
    }
 
    public String[] getSupportedCipherSuites()
    {
       return .getSupportedCipherSuites();
    }
 
    public Socket createSocket(Socket socketString stringint iboolean bthrows IOException
    {
       Socket retSocket = .createSocket(socketstringib);
 
       if (retSocket instanceof SSLSocket)
       {
          establishHandshake((SSLSocketretSocket);
       }
 
       return retSocket;
    }
 
    public Socket createSocket(String stringint ithrows IOExceptionUnknownHostException
    {
       Socket retSocket = .createSocket(stringi);
 
       if (retSocket instanceof SSLSocket)
       {
          establishHandshake((SSLSocketretSocket);
       }
 
       return retSocket;
    }
 
    public Socket createSocket(InetAddress inetAddressint ithrows IOException
    {
       Socket retSocket = .createSocket(inetAddressi);
 
       if (retSocket instanceof SSLSocket)
      {
         establishHandshake((SSLSocketretSocket);
      }
      return retSocket;
   }
   public Socket createSocket(String stringint iInetAddress inetAddressint i1throws IOExceptionUnknownHostException
   {
      Socket retSocket = .createSocket(stringiinetAddressi1);
      if (retSocket instanceof SSLSocket)
      {
         establishHandshake((SSLSocketretSocket);
      }
      return retSocket;
   }
   public Socket createSocket(InetAddress inetAddressint iInetAddress inetAddress1int i1throws IOException
   {
      Socket retSocket = .createSocket(inetAddressiinetAddress1i1);
      if (retSocket instanceof SSLSocket)
      {
         establishHandshake((SSLSocketretSocket);
      }
      return retSocket;
   }
   private void establishHandshake(SSLSocket sslSocketHandshakeCompletedListener listener)
         throws IOException
   {
      HandshakeRepeater repeater = new HandshakeRepeater(listener);
      sslSocket.addHandshakeCompletedListener(repeater);
      sslSocket.getSession();
      repeater.waitForHandshake();
   }
New to GrepCode? Check out our FAQ X