You are viewing a plain text version of this content. The canonical link for it is here.
Posted to soap-dev@ws.apache.org by sn...@apache.org on 2003/09/02 17:38:08 UTC

cvs commit: xml-soap/java/src/org/apache/soap/util/net SSLUtils.java

snichol     2003/09/02 08:38:08

  Modified:    java/src/org/apache/soap/util/net SSLUtils.java
  Log:
  Set read timeout before doing handshake, so that handshake cannot hang
  if the calling code specifies a non-zero timeout.
  
  Revision  Changes    Path
  1.13      +22 -18    xml-soap/java/src/org/apache/soap/util/net/SSLUtils.java
  
  Index: SSLUtils.java
  ===================================================================
  RCS file: /home/cvs/xml-soap/java/src/org/apache/soap/util/net/SSLUtils.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- SSLUtils.java	1 Apr 2003 14:07:20 -0000	1.12
  +++ SSLUtils.java	2 Sep 2003 15:38:08 -0000	1.13
  @@ -199,9 +199,6 @@
                       sslSocket = (SSLSocket) factory.createSocket(host, port);
                   }
               }
  -
  -            if (sslSocket != null && tcpNoDelay != null)
  -                sslSocket.setTcpNoDelay(tcpNoDelay.booleanValue());
           } else {
               /*                         
                * If a proxy has been set...
  @@ -214,22 +211,27 @@
   
               // Overlay tunnel socket with SSL
               sslSocket = (SSLSocket) factory.createSocket(tunnel, host, port, true);
  -            if (sslSocket != null && tcpNoDelay != null)
  -                sslSocket.setTcpNoDelay(tcpNoDelay.booleanValue());
           }
   
  -        /*
  -         * Handshaking is started manually in this example because
  -         * PrintWriter catches all IOExceptions (including
  -         * SSLExceptions), sets an internal error flag, and then
  -         * returns without rethrowing the exception.
  -         *
  -         * Unfortunately, this means any error messages are lost,
  -         * which caused lots of confusion for others using this
  -         * code.  The only way to tell there was an error is to call
  -         * PrintWriter.checkError().
  -         */
  -        sslSocket.startHandshake();   
  +        if (sslSocket != null) {
  +            if (tcpNoDelay != null)
  +                sslSocket.setTcpNoDelay(tcpNoDelay.booleanValue());
  +            if (timeout > 0)  // Should be redundant but not every JVM likes this
  +                sslSocket.setSoTimeout(timeout);
  +
  +            /*
  +             * Handshaking is started manually in this example because
  +             * PrintWriter catches all IOExceptions (including
  +             * SSLExceptions), sets an internal error flag, and then
  +             * returns without rethrowing the exception.
  +             *
  +             * Unfortunately, this means any error messages are lost,
  +             * which caused lots of confusion for others using this
  +             * code.  The only way to tell there was an error is to call
  +             * PrintWriter.checkError().
  +             */
  +            sslSocket.startHandshake();   
  +        }
   
           return (Socket) sslSocket;  
       }
  @@ -241,8 +243,10 @@
               throws IOException, InvocationTargetException {
   
           Socket tunnel = SocketUtils.createSocket(tunnelHost, tunnelPort, timeout);
  -        if (tunnel != null && tcpNoDelay != null)
  +        if (tcpNoDelay != null)
               tunnel.setTcpNoDelay(tcpNoDelay.booleanValue());
  +        if (timeout > 0)  // Should be redundant but not every JVM likes this
  +            tunnel.setSoTimeout(timeout);
   
           String msg;
           OutputStream out = tunnel.getOutputStream();