/[classpath]/classpath/gnu/java/net/protocol/http/HTTPConnection.java
ViewVC logotype

Diff of /classpath/gnu/java/net/protocol/http/HTTPConnection.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by mkoch, Tue Nov 30 22:15:03 2004 UTC revision 1.2 by dog, Mon Dec 6 09:55:23 2004 UTC
# Line 38  exception statement from your version. * Line 38  exception statement from your version. *
38    
39  package gnu.java.net.protocol.http;  package gnu.java.net.protocol.http;
40    
41    import gnu.classpath.Configuration;
42  import gnu.java.net.protocol.http.event.ConnectionEvent;  import gnu.java.net.protocol.http.event.ConnectionEvent;
43  import gnu.java.net.protocol.http.event.ConnectionListener;  import gnu.java.net.protocol.http.event.ConnectionListener;
44  import gnu.java.net.protocol.http.event.RequestEvent;  import gnu.java.net.protocol.http.event.RequestEvent;
# Line 55  import java.security.GeneralSecurityExce Line 56  import java.security.GeneralSecurityExce
56  import java.util.ArrayList;  import java.util.ArrayList;
57  import java.util.Collections;  import java.util.Collections;
58  import java.util.HashMap;  import java.util.HashMap;
59    import java.util.Iterator;
60  import java.util.List;  import java.util.List;
61  import java.util.Map;  import java.util.Map;
62  import javax.net.SocketFactory;  import javax.net.SocketFactory;
63    import javax.net.ssl.HandshakeCompletedListener;
64  import javax.net.ssl.SSLContext;  import javax.net.ssl.SSLContext;
65  import javax.net.ssl.SSLSocket;  import javax.net.ssl.SSLSocket;
66  import javax.net.ssl.SSLSocketFactory;  import javax.net.ssl.SSLSocketFactory;
# Line 87  public class HTTPConnection Line 90  public class HTTPConnection
90    {    {
91      try      try
92        {        {
93          StringBuffer buf = new StringBuffer("inetlib/1.1 (");          StringBuffer buf = new StringBuffer("classpath/");
94            buf.append(Configuration.CLASSPATH_VERSION);
95            buf.append(" (");
96          buf.append(System.getProperty("os.name"));          buf.append(System.getProperty("os.name"));
97          buf.append("; ");          buf.append("; ");
98          buf.append(System.getProperty("os.arch"));          buf.append(System.getProperty("os.arch"));
# Line 149  public class HTTPConnection Line 154  public class HTTPConnection
154    
155    private final List connectionListeners;    private final List connectionListeners;
156    private final List requestListeners;    private final List requestListeners;
157      private final List handshakeCompletedListeners;
158    
159    /**    /**
160     * The socket this connection communicates on.     * The socket this connection communicates on.
# Line 156  public class HTTPConnection Line 162  public class HTTPConnection
162    protected Socket socket;    protected Socket socket;
163    
164    /**    /**
165       * The SSL socket factory to use.
166       */
167      private SSLSocketFactory sslSocketFactory;
168    
169      /**
170     * The socket input stream.     * The socket input stream.
171     */     */
172    protected InputStream in;    protected InputStream in;
# Line 246  public class HTTPConnection Line 257  public class HTTPConnection
257      this.connectionTimeout = connectionTimeout;      this.connectionTimeout = connectionTimeout;
258      this.timeout = timeout;      this.timeout = timeout;
259      majorVersion = minorVersion = 1;      majorVersion = minorVersion = 1;
260      connectionListeners = Collections.synchronizedList(new ArrayList(4));      connectionListeners = new ArrayList(4);
261      requestListeners = Collections.synchronizedList(new ArrayList(4));      requestListeners = new ArrayList(4);
262        handshakeCompletedListeners = new ArrayList(2);
263    }    }
264    
265    /**    /**
# Line 434  public class HTTPConnection Line 446  public class HTTPConnection
446            {            {
447              try              try
448                {                {
449                  TrustManager tm = new EmptyX509TrustManager();                  SSLSocketFactory factory = getSSLSocketFactory();
                 SSLContext context = SSLContext.getInstance("SSL");  
                 TrustManager[] trust = new TrustManager[] { tm };  
                 context.init(null, trust, null);  
                 SSLSocketFactory factory =  context.getSocketFactory();  
450                  SSLSocket ss =                  SSLSocket ss =
451                    (SSLSocket) factory.createSocket(socket, connectHostname,                    (SSLSocket) factory.createSocket(socket, connectHostname,
452                                                     connectPort, true);                                                     connectPort, true);
453                  String[] protocols = { "TLSv1", "SSLv3" };                  String[] protocols = { "TLSv1", "SSLv3" };
454                  ss.setEnabledProtocols(protocols);                  ss.setEnabledProtocols(protocols);
455                  ss.setUseClientMode(true);                  ss.setUseClientMode(true);
456                    synchronized (handshakeCompletedListeners)
457                      {
458                        if (!handshakeCompletedListeners.isEmpty())
459                          {
460                            for (Iterator i =
461                                 handshakeCompletedListeners.iterator();
462                                 i.hasNext(); )
463                              {
464                                HandshakeCompletedListener l =
465                                  (HandshakeCompletedListener) i.next();
466                                ss.addHandshakeCompletedListener(l);
467                              }
468                          }
469                      }
470                  ss.startHandshake();                  ss.startHandshake();
471                  socket = ss;                  socket = ss;
472                }                }
# Line 461  public class HTTPConnection Line 483  public class HTTPConnection
483      return socket;      return socket;
484    }    }
485    
486      SSLSocketFactory getSSLSocketFactory()
487        throws GeneralSecurityException
488      {
489        if (sslSocketFactory == null)
490          {
491            TrustManager tm = new EmptyX509TrustManager();
492            SSLContext context = SSLContext.getInstance("SSL");
493            TrustManager[] trust = new TrustManager[] { tm };
494            context.init(null, trust, null);
495            sslSocketFactory = context.getSocketFactory();
496          }
497        return sslSocketFactory;
498      }
499    
500      void setSSLSocketFactory(SSLSocketFactory factory)
501      {
502        sslSocketFactory = factory;
503      }
504    
505    protected InputStream getInputStream()    protected InputStream getInputStream()
506      throws IOException      throws IOException
507    {    {
# Line 634  public class HTTPConnection Line 675  public class HTTPConnection
675        }        }
676    }    }
677    
678      void addHandshakeCompletedListener(HandshakeCompletedListener l)
679      {
680        synchronized (handshakeCompletedListeners)
681          {
682            handshakeCompletedListeners.add(l);
683          }
684      }
685      void removeHandshakeCompletedListener(HandshakeCompletedListener l)
686      {
687        synchronized (handshakeCompletedListeners)
688          {
689            handshakeCompletedListeners.remove(l);
690          }
691      }
692    
693  }  }
694    

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26