< prev index next >

src/java.base/share/classes/java/net/HttpConnectSocketImpl.java

Print this page




  97     }
  98 
  99     @Override
 100     void setSocket(Socket socket) {
 101         delegate.socket = socket;
 102         super.setSocket(socket);
 103     }
 104 
 105     @Override
 106     void setServerSocket(ServerSocket socket) {
 107         throw new InternalError("should not get here");
 108     }
 109 
 110     @Override
 111     protected void connect(SocketAddress endpoint, int timeout)
 112         throws IOException
 113     {
 114         if (endpoint == null || !(endpoint instanceof InetSocketAddress))
 115             throw new IllegalArgumentException("Unsupported address type");
 116         final InetSocketAddress epoint = (InetSocketAddress)endpoint;
 117         final String destHost = epoint.isUnresolved() ? epoint.getHostName()
 118                                                       : epoint.getAddress().getHostAddress();
 119         final int destPort = epoint.getPort();
 120 
 121         SecurityManager security = System.getSecurityManager();
 122         if (security != null)
 123             security.checkConnect(destHost, destPort);
 124 



 125         // Connect to the HTTP proxy server
 126         String urlString = "http://" + destHost + ":" + destPort;
 127         Socket httpSocket = privilegedDoTunnel(urlString, timeout);
 128 
 129         // Success!
 130         external_address = epoint;
 131 
 132         // close the original socket impl and release its descriptor
 133         close();
 134 
 135         // update the Sockets impl to the impl from the http Socket
 136         SocketImpl si = httpSocket.impl;
 137         getSocket().setImpl(si);
 138 
 139         // best effort is made to try and reset options previously set
 140         Set<Map.Entry<Integer,Object>> options = optionsMap.entrySet();
 141         try {
 142             for(Map.Entry<Integer,Object> entry : options) {
 143                 si.setOption(entry.getKey(), entry.getValue());
 144             }




  97     }
  98 
  99     @Override
 100     void setSocket(Socket socket) {
 101         delegate.socket = socket;
 102         super.setSocket(socket);
 103     }
 104 
 105     @Override
 106     void setServerSocket(ServerSocket socket) {
 107         throw new InternalError("should not get here");
 108     }
 109 
 110     @Override
 111     protected void connect(SocketAddress endpoint, int timeout)
 112         throws IOException
 113     {
 114         if (endpoint == null || !(endpoint instanceof InetSocketAddress))
 115             throw new IllegalArgumentException("Unsupported address type");
 116         final InetSocketAddress epoint = (InetSocketAddress)endpoint;
 117         String destHost = epoint.isUnresolved() ? epoint.getHostName()
 118                                                 : epoint.getAddress().getHostAddress();
 119         final int destPort = epoint.getPort();
 120 
 121         SecurityManager security = System.getSecurityManager();
 122         if (security != null)
 123             security.checkConnect(destHost, destPort);
 124 
 125         if (destHost.contains(":"))
 126             destHost = "[" + destHost + "]";
 127 
 128         // Connect to the HTTP proxy server
 129         String urlString = "http://" + destHost + ":" + destPort;
 130         Socket httpSocket = privilegedDoTunnel(urlString, timeout);
 131 
 132         // Success!
 133         external_address = epoint;
 134 
 135         // close the original socket impl and release its descriptor
 136         close();
 137 
 138         // update the Sockets impl to the impl from the http Socket
 139         SocketImpl si = httpSocket.impl;
 140         getSocket().setImpl(si);
 141 
 142         // best effort is made to try and reset options previously set
 143         Set<Map.Entry<Integer,Object>> options = optionsMap.entrySet();
 144         try {
 145             for(Map.Entry<Integer,Object> entry : options) {
 146                 si.setOption(entry.getKey(), entry.getValue());
 147             }


< prev index next >